fix(lsp): apply specifier rewrite to CompletionItem::text_edit (#21564)

This commit is contained in:
Nayeem Rahman 2023-12-15 15:24:38 +00:00 committed by GitHub
parent fd6044dfec
commit cd480b481e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3112,6 +3112,23 @@ impl CompletionEntryDetails {
} else {
None
};
let mut text_edit = original_item.text_edit.clone();
if let Some(specifier_rewrite) = &data.specifier_rewrite {
if let Some(text_edit) = &mut text_edit {
match text_edit {
lsp::CompletionTextEdit::Edit(text_edit) => {
text_edit.new_text = text_edit
.new_text
.replace(&specifier_rewrite.0, &specifier_rewrite.1);
}
lsp::CompletionTextEdit::InsertAndReplace(insert_replace_edit) => {
insert_replace_edit.new_text = insert_replace_edit
.new_text
.replace(&specifier_rewrite.0, &specifier_rewrite.1);
}
}
}
}
let (command, additional_text_edits) = parse_code_actions(
self.code_actions.as_ref(),
data,
@ -3136,6 +3153,7 @@ impl CompletionEntryDetails {
detail,
documentation,
command,
text_edit,
additional_text_edits,
insert_text,
// NOTE(bartlomieju): it's not entirely clear to me why we need to do that,