mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-25 19:03:30 +04:00
Check language server symbol renaming support before prompting (#6257)
Co-authored-by: Poliorcetics <poliorcetics@users.noreply.github.com>
This commit is contained in:
parent
dc418bb507
commit
db8e9f5bb2
@ -1136,20 +1136,23 @@ pub fn code_actions(
|
||||
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 {
|
||||
|
@ -1316,6 +1316,12 @@ fn create_rename_prompt(editor: &Editor, prefill: String) -> Box<ui::Prompt> {
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user