From 44ff8a1df1f69733bc40ea866674fcfd7e0cdded Mon Sep 17 00:00:00 2001 From: Kyle Smith Date: Tue, 7 Mar 2023 21:11:43 -0500 Subject: LSP: Support textDocument/prepareRename (#6103) * 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 * clippy fixes * rustfmt * Update helix-term/src/commands/lsp.rs Co-authored-by: Michael Davis * Update helix-term/src/commands/lsp.rs Co-authored-by: Michael Davis * fix clippy from suggestions * Update helix-term/src/commands/lsp.rs Co-authored-by: Michael Davis --------- Co-authored-by: Michael Davis --- helix-lsp/src/client.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'helix-lsp/src') diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index 95f3ea34..9fa118fb 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -359,7 +359,7 @@ impl Client { }), rename: Some(lsp::RenameClientCapabilities { dynamic_registration: Some(false), - prepare_support: Some(false), + prepare_support: Some(true), prepare_support_default_behavior: None, honors_change_annotations: Some(false), }), @@ -1034,6 +1034,29 @@ impl Client { Some(self.call::(params)) } + pub fn prepare_rename( + &self, + text_document: lsp::TextDocumentIdentifier, + position: lsp::Position, + ) -> Option>> { + let capabilities = self.capabilities.get().unwrap(); + + match capabilities.rename_provider { + Some(lsp::OneOf::Right(lsp::RenameOptions { + prepare_provider: Some(true), + .. + })) => (), + _ => return None, + } + + let params = lsp::TextDocumentPositionParams { + text_document, + position, + }; + + Some(self.call::(params)) + } + // empty string to get all symbols pub fn workspace_symbols(&self, query: String) -> Option>> { let capabilities = self.capabilities.get().unwrap(); -- cgit v1.2.3-70-g09d2