-
Notifications
You must be signed in to change notification settings - Fork 121
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
Use Merlin Enclosing command instead of Shape to answer SelectionRange queries #860
base: master
Are you sure you want to change the base?
Conversation
Does this still work when the module fails to type check? Out of curiosity, what are "Shapes" useful for if not for this? Please update CHANGES. |
The "shape" command of Merlin has nothing to do with the "shapes" that we use to jump to definitions. I just tried and it appears to work when the buffer does not type but I did not test it extensively. |
I'm still curious why do we have Shape in merlin at all then? By the way, I would expect expanding selection wouldn't always select an expression or a type. For example, given (bar signifies the cursor,
would expand to
and then to
I'm not sure the current shapes command respects that either, but it would be good if a proper solution for expand selection did. |
Finally, does expand selection work inside comments? |
Fiber.sequential_map positions ~f:(fun x -> | ||
let+ shapes = | ||
let command = Query_protocol.Shape (Position.logical x) in | ||
let+ enclosings = | ||
let command = Query_protocol.Enclosing (Position.logical x) in | ||
Document.dispatch_exn doc command | ||
in | ||
selection_range_of_shapes x shapes) | ||
selection_range_of_enclosings enclosings) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO(ulugbekna): we should batch these merlin queries into one
No, the only range returned is the whole document range, but, for example, vscode is smart about it and expands selection gradually: word, parenthesized expression, line, then the whole document.
What would you expect from expanding selection in a comment? Do you mean the selections could work in pre-formatted code block within a comment |
Yes, both the It looks like the kind of selection you describe would be more "parsetree" based.
It looks like a refinement over the
In Merlin's doc:
|
That's exactly what I would expect for this command.
At least from this description, it seems like Shape fits better fitted to play the role of "expand selection" than the enclosing type. |
13d50eb
to
d58977b
Compare
Do we plan to merge this? @rgrinberg Would be great to merge before there're more conflicts. I can fix the conflict if @voodoos is busy |
The enclosing command is the dedicated Merlin command to provide meaningfull growing and shrinking selection.
d58977b
to
ebb41cd
Compare
Rebased.
Right, and it does look like the code on Merlin's side is doing some interesting selection to reduce noise, however the result are still bad. Maybe it is worth to have a look and fix it. But it is quite low on my priority list. This PR would make the behavior consistent with how Merlin behave in Emacs in Vim, but this might not be "better". I will try to find the type to write some test that highlight differences between the two commands. |
I'd like to see some tests before we evaluate the PR. As I've mentioned earlier, I don't think growing the type enclosing is the correct interpretation for growing the selection. Shapes might not be any better, but we need to agree how it should work first. |
The enclosing command is the dedicated Merlin command to provide meaningful growing and shrinking of the selection.