diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index 9fa118fbda22..5aee514e8a7f 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -1104,20 +1104,23 @@ impl Client { Some(self.call::(params)) } + pub fn supports_rename(&self) -> bool { + let capabilities = self.capabilities.get().unwrap(); + matches!( + capabilities.rename_provider, + Some(lsp::OneOf::Left(true) | lsp::OneOf::Right(_)) + ) + } + pub fn rename_symbol( &self, text_document: lsp::TextDocumentIdentifier, position: lsp::Position, new_name: String, ) -> Option>> { - let capabilities = self.capabilities.get().unwrap(); - - // Return early if the language server does not support renaming. - match capabilities.rename_provider { - Some(lsp::OneOf::Left(true)) | Some(lsp::OneOf::Right(_)) => (), - // None | Some(false) - _ => return None, - }; + if !self.supports_rename() { + return None; + } let params = lsp::RenameParams { text_document_position: lsp::TextDocumentPositionParams { diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index 08519366b257..094ced2853ef 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -1310,6 +1310,12 @@ pub fn rename_symbol(cx: &mut Context) { let language_server = language_server!(cx.editor, doc); let offset_encoding = language_server.offset_encoding(); + if !language_server.supports_rename() { + cx.editor + .set_error("Language server does not support symbol renaming"); + return; + } + let pos = doc.position(view.id, offset_encoding); match language_server.prepare_rename(doc.identifier(), pos) {