Test for filtering out of faulty LSP completion additional edits
This commit is contained in:
parent
44c3cedc48
commit
ad698fd110
2 changed files with 34 additions and 15 deletions
|
@ -4146,14 +4146,26 @@ async fn test_completion(cx: &mut gpui::TestAppContext) {
|
||||||
|
|
||||||
handle_resolve_completion_request(
|
handle_resolve_completion_request(
|
||||||
&mut cx,
|
&mut cx,
|
||||||
Some((
|
Some(vec![
|
||||||
indoc! {"
|
(
|
||||||
one.second_completion
|
//This overlaps with the primary completion edit which is
|
||||||
two
|
//misbehavior from the LSP spec, test that we filter it out
|
||||||
threeˇ
|
indoc! {"
|
||||||
"},
|
one.second_ˇcompletion
|
||||||
"\nadditional edit",
|
two
|
||||||
)),
|
threeˇ
|
||||||
|
"},
|
||||||
|
"overlapping aditional edit",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
indoc! {"
|
||||||
|
one.second_completion
|
||||||
|
two
|
||||||
|
threeˇ
|
||||||
|
"},
|
||||||
|
"\nadditional edit",
|
||||||
|
),
|
||||||
|
]),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
apply_additional_edits.await.unwrap();
|
apply_additional_edits.await.unwrap();
|
||||||
|
@ -4303,19 +4315,24 @@ async fn test_completion(cx: &mut gpui::TestAppContext) {
|
||||||
|
|
||||||
async fn handle_resolve_completion_request<'a>(
|
async fn handle_resolve_completion_request<'a>(
|
||||||
cx: &mut EditorLspTestContext<'a>,
|
cx: &mut EditorLspTestContext<'a>,
|
||||||
edit: Option<(&'static str, &'static str)>,
|
edits: Option<Vec<(&'static str, &'static str)>>,
|
||||||
) {
|
) {
|
||||||
let edit = edit.map(|(marked_string, new_text)| {
|
let edits = edits.map(|edits| {
|
||||||
let (_, marked_ranges) = marked_text_ranges(marked_string, false);
|
edits
|
||||||
let replace_range = cx.to_lsp_range(marked_ranges[0].clone());
|
.iter()
|
||||||
vec![lsp::TextEdit::new(replace_range, new_text.to_string())]
|
.map(|(marked_string, new_text)| {
|
||||||
|
let (_, marked_ranges) = marked_text_ranges(marked_string, false);
|
||||||
|
let replace_range = cx.to_lsp_range(marked_ranges[0].clone());
|
||||||
|
lsp::TextEdit::new(replace_range, new_text.to_string())
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>()
|
||||||
});
|
});
|
||||||
|
|
||||||
cx.handle_request::<lsp::request::ResolveCompletionItem, _, _>(move |_, _, _| {
|
cx.handle_request::<lsp::request::ResolveCompletionItem, _, _>(move |_, _, _| {
|
||||||
let edit = edit.clone();
|
let edits = edits.clone();
|
||||||
async move {
|
async move {
|
||||||
Ok(lsp::CompletionItem {
|
Ok(lsp::CompletionItem {
|
||||||
additional_text_edits: edit,
|
additional_text_edits: edits,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -3481,6 +3481,8 @@ impl Project {
|
||||||
let end_within = range.start.cmp(&primary.end, buffer).is_le()
|
let end_within = range.start.cmp(&primary.end, buffer).is_le()
|
||||||
&& range.end.cmp(&primary.end, buffer).is_ge();
|
&& range.end.cmp(&primary.end, buffer).is_ge();
|
||||||
|
|
||||||
|
//Skip addtional edits which overlap with the primary completion edit
|
||||||
|
//https://github.com/zed-industries/zed/pull/1871
|
||||||
if !start_within && !end_within {
|
if !start_within && !end_within {
|
||||||
buffer.edit([(range, text)], None, cx);
|
buffer.edit([(range, text)], None, cx);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue