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
Expand Selection selects too wide scope #3615
Comments
Thanks for reporting! This is related to the fact that the Scala parser omits comments, we should probably do a similar thing to what we do for keywords in https://github.com/scalameta/metals/blob/main/mtags/src/main/scala-2/scala/meta/internal/pc/Keywords.scala#L66 Check if we are in the comment and expand the selection for it otherwise do it normally. |
@tgodzik Could you give me some advice on how to achieve this in more details ? and do we need to change Scala parsers in scalameta library? |
A very similar issue was in https://github.com/scalameta/metals/pull/2822/files where we wanted to not show completions inside comments. We could use the same mechanism to check if we are in a comment and if we are we would probably need to use the Scalameta tokenizer to find the enclosing scope. It would need to be implemented in: Of course we don't need to do both at the same time, but the solution would be similar. |
thanks! I will have a look |
I see the problem is in https://github.com/scalameta/metals/blob/main/mtags/src/main/scala-3/scala/meta/internal/pc/SelectionRangeProvider.scala#L43 that val path =
Interactive.pathTo(driver.openedTrees(uri), pos)(using ctx) where the trees returned by openedTrees In addition,seems that Keywords.scala#L66 doesn't exist for scala 3 yet . We can have a meeting about this if you would like to. |
For Scala 3 we have https://github.com/scalameta/metals/blob/main/mtags/src/main/scala-3/scala/meta/internal/pc/completions/KeywordsCompletions.scala#L75 <- comments are handled there. We would probably need to also check if we are in a comment and if so the next range should be the range of that comment.
That's why we use the scalameta tokenizer for the task, which also handles tokens. |
We merged the support for Scala 2, Scala 3 support should look very similar. |
@tgodzik we actually merged support for Scala 3, now I'm looking at Scala 2. The scala meta code part seems similar, but I'm unable to find out how to get the cursor location as in https://github.com/scalameta/metals/blob/main/mtags/src/main/scala-3/scala/meta/internal/pc/SelectionRangeProvider.scala#L47 |
Ach, you're right! |
thanks @tgodzik , what is the Scala 2 correspondence of metals/mtags/src/main/scala-3/scala/meta/internal/pc/SelectionRangeProvider.scala Line 49 in 2014643
|
That should be |
Describe the bug
When use selection->Expand Selection,it sometimes selects the wrong range
Reproduction:
1.type single line some comment
2.put cursor before
//
or after//
3.expand selection will select wrong block
In addition,it's also problematic with expand selection on block comment
/* */
Expected behavior
expand selection should only select the comment block when cursor is before before
//
or after//
Operating system
Linux
Editor/Extension
VS Code
Version of Metals
v0.11.1
Extra context or search terms
Expand ,Selection
probably relates to scala/vscode-scala-syntax#49
The text was updated successfully, but these errors were encountered: