mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-19 18:41:56 +03:00
lsp: Add partial support for insert/replace completions (#9634)
Most notably, this should do away with completions overriding the whole word around completion trigger text. Fixes: #4816 Release Notes: - Fixed code completions overriding text around the cursor.
This commit is contained in:
parent
6184278faf
commit
e20508f66c
@ -590,6 +590,7 @@ impl LanguageServer {
|
|||||||
"additionalTextEdits".to_string(),
|
"additionalTextEdits".to_string(),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
insert_replace_support: Some(true),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
completion_list: Some(CompletionListCapability {
|
completion_list: Some(CompletionListCapability {
|
||||||
|
@ -1557,10 +1557,20 @@ impl LspCommand for GetCompletions {
|
|||||||
(range, text)
|
(range, text)
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(lsp::CompletionTextEdit::InsertAndReplace(_)) => {
|
Some(lsp::CompletionTextEdit::InsertAndReplace(edit)) => {
|
||||||
log::info!("unsupported insert/replace completion");
|
let range = range_from_lsp(edit.insert);
|
||||||
|
|
||||||
|
let start = snapshot.clip_point_utf16(range.start, Bias::Left);
|
||||||
|
let end = snapshot.clip_point_utf16(range.end, Bias::Left);
|
||||||
|
if start != range.start.0 || end != range.end.0 {
|
||||||
|
log::info!("completion out of expected range");
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
(
|
||||||
|
snapshot.anchor_before(start)..snapshot.anchor_after(end),
|
||||||
|
edit.new_text.clone(),
|
||||||
|
)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let language_registry = language_registry.clone();
|
let language_registry = language_registry.clone();
|
||||||
|
Loading…
Reference in New Issue
Block a user