mirror of
https://github.com/ilyakooo0/helix.git
synced 2024-11-28 12:42:09 +03:00
chore(lsp): check rename capabilities before send rename action (#2203)
This commit is contained in:
parent
c1d3d49f3f
commit
19d042dde6
@ -3,6 +3,7 @@ use crate::{
|
|||||||
Call, Error, OffsetEncoding, Result,
|
Call, Error, OffsetEncoding, Result,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use anyhow::anyhow;
|
||||||
use helix_core::{find_root, ChangeSet, Rope};
|
use helix_core::{find_root, ChangeSet, Rope};
|
||||||
use jsonrpc_core as jsonrpc;
|
use jsonrpc_core as jsonrpc;
|
||||||
use lsp_types as lsp;
|
use lsp_types as lsp;
|
||||||
@ -861,6 +862,19 @@ impl Client {
|
|||||||
position: lsp::Position,
|
position: lsp::Position,
|
||||||
new_name: String,
|
new_name: String,
|
||||||
) -> anyhow::Result<lsp::WorkspaceEdit> {
|
) -> anyhow::Result<lsp::WorkspaceEdit> {
|
||||||
|
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 {
|
let params = lsp::RenameParams {
|
||||||
text_document_position: lsp::TextDocumentPositionParams {
|
text_document_position: lsp::TextDocumentPositionParams {
|
||||||
text_document,
|
text_document,
|
||||||
|
@ -674,8 +674,10 @@ pub fn rename_symbol(cx: &mut Context) {
|
|||||||
let pos = doc.position(view.id, offset_encoding);
|
let pos = doc.position(view.id, offset_encoding);
|
||||||
|
|
||||||
let task = language_server.rename_symbol(doc.identifier(), pos, input.to_string());
|
let task = language_server.rename_symbol(doc.identifier(), pos, input.to_string());
|
||||||
let edits = block_on(task).unwrap_or_default();
|
match block_on(task) {
|
||||||
apply_workspace_edit(cx.editor, offset_encoding, &edits);
|
Ok(edits) => apply_workspace_edit(cx.editor, offset_encoding, &edits),
|
||||||
|
Err(err) => cx.editor.set_error(err.to_string()),
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user