From 19d042dde6ac7aad5b597c791c1f142f5c7f7198 Mon Sep 17 00:00:00 2001 From: ttys3 <41882455+ttys3@users.noreply.github.com> Date: Sat, 23 Apr 2022 16:09:16 +0800 Subject: [PATCH] chore(lsp): check rename capabilities before send rename action (#2203) --- helix-lsp/src/client.rs | 14 ++++++++++++++ helix-term/src/commands/lsp.rs | 6 ++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index dba134fc..2459554c 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -3,6 +3,7 @@ use crate::{ Call, Error, OffsetEncoding, Result, }; +use anyhow::anyhow; use helix_core::{find_root, ChangeSet, Rope}; use jsonrpc_core as jsonrpc; use lsp_types as lsp; @@ -861,6 +862,19 @@ impl Client { position: lsp::Position, new_name: String, ) -> anyhow::Result { + let capabilities = self.capabilities.get().unwrap(); + + // check if we're able to rename + match capabilities.rename_provider { + Some(lsp::OneOf::Left(true)) | Some(lsp::OneOf::Right(_)) => (), + // None | Some(false) + _ => { + let err = "The server does not support rename"; + log::warn!("rename_symbol failed: {}", err); + return Err(anyhow!(err)); + } + }; + let params = lsp::RenameParams { text_document_position: lsp::TextDocumentPositionParams { text_document, diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index 0a12ae39..90a1ad7f 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -674,8 +674,10 @@ pub fn rename_symbol(cx: &mut Context) { let pos = doc.position(view.id, offset_encoding); let task = language_server.rename_symbol(doc.identifier(), pos, input.to_string()); - let edits = block_on(task).unwrap_or_default(); - apply_workspace_edit(cx.editor, offset_encoding, &edits); + match block_on(task) { + Ok(edits) => apply_workspace_edit(cx.editor, offset_encoding, &edits), + Err(err) => cx.editor.set_error(err.to_string()), + } }, ); }