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

feat: highlight / select symbol under cursor using LSP textDocument/documentHighlight #2738

Merged
merged 3 commits into from Jun 27, 2022

Conversation

lazytanuki
Copy link
Contributor

Hi !

This PR implements the LSP textDocument/documentHighlight request. The command asks the LSP server for the ranges of references to current symbol, and select them (using multiple cursors).

I initially just wanted to have these symbols highlighted (like in nvim or vscode), but using multi-cursors is more convenient because the user can navigate between the references using ( and ), and also because it reuses already existing components :

Peek 2022-06-10 14-15

I have set the Space + h (for highlight) mapping to use this.

Have a good day !

helix-term/src/commands.rs Outdated Show resolved Hide resolved
helix-term/src/commands/lsp.rs Outdated Show resolved Hide resolved
helix-term/src/commands/lsp.rs Outdated Show resolved Hide resolved
@lazytanuki
Copy link
Contributor Author

Changes made, thanks for the review !

Copy link
Member

@sudormrfbin sudormrfbin left a comment

Choose a reason for hiding this comment

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

LGTM!

@n0s4
Copy link
Contributor

n0s4 commented Jun 12, 2022

As for the keybind, wouldn't m-h be better than space-h? This feels like a "match" command.

@lazytanuki
Copy link
Contributor Author

Now that you mention it, indeed it does look like a match command. I chose 'h' for highlight because the call to LSP is textDocument/documentHighlight, although maybe something else than 'h' would make more sense as well ?
What do others think ?

@n0s4
Copy link
Contributor

n0s4 commented Jun 12, 2022

Maybe m-S for 'Symbol' ? Lowercase s is already used (although we could change that to w for 'wrap'..?).

@lazytanuki
Copy link
Contributor Author

I don't think changing m-s would be such a good idea, it might already be muscle memory for current users. m-S could do it.

@archseer
Copy link
Member

@the-mikedavis any opinions on keymaps here?

I initially just wanted to have these symbols highlighted (like in nvim or vscode), but using multi-cursors is more convenient because the user can navigate between the references using ( and )

I think this is a smart way of doing it, especially since it makes it easy to rename all occurrences (if the lsp doesn't support the rename code action)

@the-mikedavis
Copy link
Member

I didn't mind space-h but I don't have any problems with mS either. My only hold-up with m is that it's usually used for matches and textobjects and I don't think this fits in perfectly with that. Given that hover and rename are already in space I think adding more is ok

@lazytanuki
Copy link
Contributor Author

Okay, should we go back to space-h then ?

@the-mikedavis
Copy link
Member

Yeah let's go for space-h for now, we can always revisit the binding later

@lazytanuki
Copy link
Contributor Author

Alright, done !

Copy link
Member

@the-mikedavis the-mikedavis left a comment

Choose a reason for hiding this comment

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

This is awesome, thanks for working on it!

Copy link
Member

@archseer archseer left a comment

Choose a reason for hiding this comment

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

Great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants