Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate java scopes #2038

Merged
merged 22 commits into from
Nov 25, 2023
Merged

Migrate java scopes #2038

merged 22 commits into from
Nov 25, 2023

Conversation

AndreasArvidsson
Copy link
Member

@AndreasArvidsson AndreasArvidsson commented Nov 18, 2023

#Fixes #1926

Checklist

  • I have added tests
  • [-] I have updated the docs and cheatsheet
  • [-] I have not broken the cheatsheet

queries/java.scm Outdated Show resolved Hide resolved
Copy link
Member

@pokey pokey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Left a few minor comments

queries/java.scm Show resolved Hide resolved
consequence: (block) @branch.end @condition.domain.end
) @dummy
(#not-parent-type? @dummy "if_statement")
(#child-range! @condition 0 -1 true true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This includes any whitespace surrounding the condition inside the parens. Probably fine. Def makes sense for removal range. Prob good enough for content range

Copy link
Member Author

@AndreasArvidsson AndreasArvidsson Nov 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so. Otherwise I definitely think that we need a trim predicate here.

queries/java.scm Outdated Show resolved Hide resolved
consequence: (_) @branch
) @condition.domain
(ternary_expression
alternative: (_) @branch
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a way to define a scope multiple places in the same pattern?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately not. The problem is that then things like .leading, .start, etc become ambiguous. I guess we could allow it if we don't see any of those things in the pattern? 🤔 cc/ @josharian

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have now forgotten all of the details but last time I tried playing games like that I ended up in a tangled mess of code. I will generally choose clear over clever/concise, personally.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we number the scopes?

(ternary_expression
    consequence: (_) @branch1
    alternative: (_) @branch2
)

If we can't use actual numbers we could use letters or roman numerals? :D

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an interesting idea. Or @branch.1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah probably even better

@auscompgeek auscompgeek added the scope-migration Migrating scopes to next-gen scope implementation label Nov 18, 2023
Copy link
Member

@pokey pokey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I didn't look super closely, as it's been awhile since my java days, we have lots of tests, and you're using it day-to-day so will notice oddnesses. I left a few comments. In addition, the following looked weird to me for "value"

image

domain should include ; above; might be same issue I point out in inline comment

image

these should be values

consequence: (_) @branch
) @condition.domain
(ternary_expression
alternative: (_) @branch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately not. The problem is that then things like .leading, .start, etc become ambiguous. I guess we could allow it if we don't see any of those things in the pattern? 🤔 cc/ @josharian

queries/java.scm Outdated Show resolved Hide resolved
queries/java.scm Outdated Show resolved Hide resolved
@AndreasArvidsson
Copy link
Member Author

@pokey Updated.

Copy link
Member

@pokey pokey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better; left one more minor comment and I think we're good to go

queries/java.scm Outdated
Comment on lines 299 to 322
(local_variable_declaration
(variable_declarator
name: (_) @name @value.removal.start.endOf
value: (_)? @value @value.removal.end
)
) @_.domain
(field_declaration
(variable_declarator
name: (_) @name @value.removal.start.endOf
value: (_)? @value @value.removal.end
)
) @_.domain

;;!! value = 1;
;;! ^
;;! xxxx
;;! ----------
(_
(assignment_expression
left: (_) @value.removal.start.endOf
right: (_) @value @value.removal.end
) @_.domain.start
";"? @_.domain.end
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd argue for using leading / trailing instead of removal for all of these

Copy link
Member Author

@AndreasArvidsson AndreasArvidsson Nov 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you prefer I could do that. Personally I don't think I have every used leading and trailing for anything else than whitespaces, but I'm not against it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Member

@pokey pokey Nov 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha yeah was kind of thinking the same thing in the back of my mind 😅. Better to be consistent tho I guess 🤷‍♂️

Copy link
Member

@pokey pokey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍👍

@pokey pokey enabled auto-merge November 25, 2023 10:01
@pokey pokey added this pull request to the merge queue Nov 25, 2023
Merged via the queue into main with commit 5b22a22 Nov 25, 2023
@pokey pokey deleted the java_scopes branch November 25, 2023 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang-java scope-migration Migrating scopes to next-gen scope implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Java: Support name and value in for each statements
4 participants