Add support for rename with language servers that lack prepareRename (#23000)

This adds support for LSPs that use the old rename flow which does not
first ask the LSP for the rename range and check that it is a valid
range to rename.

Closes #16663

Release Notes:

* Fixed rename symbols action when the language server does not have the
capability to prepare renames - such as `luau-lsp`.
This commit is contained in:
Michael Sloan 2025-01-11 14:22:17 -07:00 committed by GitHub
parent b65dc8c566
commit bda0c67ece
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 268 additions and 66 deletions

View file

@ -132,7 +132,7 @@ use project::{
lsp_store::{FormatTrigger, LspFormatTarget, OpenLspBufferHandle},
project_settings::{GitGutterSetting, ProjectSettings},
CodeAction, Completion, CompletionIntent, DocumentHighlight, InlayHint, Location, LocationLink,
LspStore, Project, ProjectItem, ProjectTransaction, TaskSourceKind,
LspStore, PrepareRenameResponse, Project, ProjectItem, ProjectTransaction, TaskSourceKind,
};
use rand::prelude::*;
use rpc::{proto::*, ErrorExt};
@ -13941,7 +13941,28 @@ impl SemanticsProvider for Model<Project> {
cx: &mut AppContext,
) -> Option<Task<Result<Option<Range<text::Anchor>>>>> {
Some(self.update(cx, |project, cx| {
project.prepare_rename(buffer.clone(), position, cx)
let buffer = buffer.clone();
let task = project.prepare_rename(buffer.clone(), position, cx);
cx.spawn(|_, mut cx| async move {
Ok(match task.await? {
PrepareRenameResponse::Success(range) => Some(range),
PrepareRenameResponse::InvalidPosition => None,
PrepareRenameResponse::OnlyUnpreparedRenameSupported => {
// Fallback on using TreeSitter info to determine identifier range
buffer.update(&mut cx, |buffer, _| {
let snapshot = buffer.snapshot();
let (range, kind) = snapshot.surrounding_word(position);
if kind != Some(CharKind::Word) {
return None;
}
Some(
snapshot.anchor_before(range.start)
..snapshot.anchor_after(range.end),
)
})?
}
})
})
}))
}