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

LSP: Support textDocument/prepareRename #6103

Merged
merged 8 commits into from
Mar 8, 2023

Conversation

askreet
Copy link
Contributor

@askreet askreet commented Feb 25, 2023

@the-mikedavis here's the updated branch with fallback behavior in all the right places, I think. I used inner functions to factor our duplicate logic and actually think it came out quite nice. Seen it elsewhere in the codebase but curious if it's considered a "good" pattern we want to embrace.

'textDocument/prepareRename' can be used by the client to ask the server the range of the symbol under the cursor which would be changed by a subsequent call to 'textDocument/rename' with that position.

We can use this information to fill the prompt with an accurate prefill which can improve the UX for renaming symbols when the symbol doesn't align with the "word" textobject. (We currently use the "word" textobject as a default value for the prompt.)

'textDocument/prepareRename' can be used by the client to ask the
server the range of the symbol under the cursor which would be changed
by a subsequent call to 'textDocument/rename' with that position.

We can use this information to fill the prompt with an accurate prefill
which can improve the UX for renaming symbols when the symbol doesn't
align with the "word" textobject. (We currently use the "word"
textobject as a default value for the prompt.)

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
@the-mikedavis the-mikedavis added C-enhancement Category: Improvements A-language-server Area: Language server client S-waiting-on-review Status: Awaiting review from a maintainer. labels Feb 26, 2023
@the-mikedavis the-mikedavis self-requested a review February 26, 2023 01:22
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 looking good 👍

Splitting up the code by using functions within rename_symbol makes sense to me.

helix-term/src/commands/lsp.rs Outdated Show resolved Hide resolved
helix-term/src/commands/lsp.rs Outdated Show resolved Hide resolved
Comment on lines +1323 to +1324
Err(e) => {
editor.set_error(e);
Copy link
Member

Choose a reason for hiding this comment

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

If we return early here we won't be able to try the rename. That might be ok: if get_prefill_from_lsp_response returns an Err, the language server either doesn't support renaming at the current position or it sent an invalid range which is a problem too.

Alternatively though we could fall back to the word textobject prefill value here. I'm not sure which is better behavior. Let's leave it as-is for now?

Copy link
Member

Choose a reason for hiding this comment

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

I don't have the time to investigate myself right now but it might be worth looking at what vscode does here

Copy link
Member

Choose a reason for hiding this comment

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

I couldn't find exactly where this is handled in vscode but it looks like the current behavior here matches nvim's https://github.com/neovim/neovim/blob/ca3bc56a3b1b3454498a4a23c0d700486d554077/runtime/lua/vim/lsp/buf.lua#L319-L379

askreet and others added 3 commits February 27, 2023 07:37
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
askreet and others added 2 commits March 5, 2023 17:35
@the-mikedavis the-mikedavis requested a review from archseer March 6, 2023 15:15
@archseer archseer merged commit 44ff8a1 into helix-editor:master Mar 8, 2023
sagnibak pushed a commit to sagnibak/helix that referenced this pull request Mar 21, 2023
* LSP: Support textDocument/prepareRename

'textDocument/prepareRename' can be used by the client to ask the
server the range of the symbol under the cursor which would be changed
by a subsequent call to 'textDocument/rename' with that position.

We can use this information to fill the prompt with an accurate prefill
which can improve the UX for renaming symbols when the symbol doesn't
align with the "word" textobject. (We currently use the "word"
textobject as a default value for the prompt.)

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>

* clippy fixes

* rustfmt

* Update helix-term/src/commands/lsp.rs

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>

* Update helix-term/src/commands/lsp.rs

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>

* fix clippy from suggestions

* Update helix-term/src/commands/lsp.rs

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>

---------

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
wes-adams pushed a commit to wes-adams/helix that referenced this pull request Jul 4, 2023
* LSP: Support textDocument/prepareRename

'textDocument/prepareRename' can be used by the client to ask the
server the range of the symbol under the cursor which would be changed
by a subsequent call to 'textDocument/rename' with that position.

We can use this information to fill the prompt with an accurate prefill
which can improve the UX for renaming symbols when the symbol doesn't
align with the "word" textobject. (We currently use the "word"
textobject as a default value for the prompt.)

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>

* clippy fixes

* rustfmt

* Update helix-term/src/commands/lsp.rs

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>

* Update helix-term/src/commands/lsp.rs

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>

* fix clippy from suggestions

* Update helix-term/src/commands/lsp.rs

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>

---------

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-language-server Area: Language server client C-enhancement Category: Improvements S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
4 participants