Skip to content

Commit

Permalink
Check language server symbol renaming support before prompting (helix…
Browse files Browse the repository at this point in the history
…-editor#6257)

Co-authored-by: Poliorcetics <poliorcetics@users.noreply.github.com>
  • Loading branch information
2 people authored and Sagnik Bhattacharya committed Mar 21, 2023
1 parent 1ff93f4 commit 95eeb94
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
19 changes: 11 additions & 8 deletions helix-lsp/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1136,20 +1136,23 @@ impl Client {
Some(self.call::<lsp::request::CodeActionRequest>(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<impl Future<Output = Result<lsp::WorkspaceEdit>>> {
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 {
Expand Down
6 changes: 6 additions & 0 deletions helix-term/src/commands/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,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) {
Expand Down

0 comments on commit 95eeb94

Please sign in to comment.