Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check language server symbol renaming support before prompting #6257

Merged
merged 3 commits into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions helix-lsp/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1104,21 +1104,21 @@ impl Client {
Some(self.call::<lsp::request::CodeActionRequest>(params))
}

pub fn supports_rename(&self) -> bool {
let capabilities = self.capabilities.get().unwrap();
match capabilities.rename_provider {
Some(lsp::OneOf::Left(true)) | Some(lsp::OneOf::Right(_)) => true,
// None | Some(false)
_ => false,
}
misiasty3 marked this conversation as resolved.
Show resolved Hide resolved
}

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,
};
misiasty3 marked this conversation as resolved.
Show resolved Hide resolved

let params = lsp::RenameParams {
text_document_position: lsp::TextDocumentPositionParams {
text_document,
Expand Down
9 changes: 7 additions & 2 deletions helix-term/src/commands/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1290,8 +1290,7 @@ pub fn rename_symbol(cx: &mut Context) {
match language_server.rename_symbol(doc.identifier(), pos, input.to_string()) {
Some(future) => future,
None => {
cx.editor
.set_error("Language server does not support symbol renaming");
cx.editor.set_error("Failed to rename symbol");
misiasty3 marked this conversation as resolved.
Show resolved Hide resolved
return;
}
};
Expand All @@ -1310,6 +1309,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