Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Test for filtering out of faulty LSP completion additional edits

Juliaad698fd11002
diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs
index 763917a4648..7bd5dda522f 100644
--- a/crates/editor/src/editor_tests.rs
+++ b/crates/editor/src/editor_tests.rs
@@ -4146,14 +4146,26 @@ async fn test_completion(cx: &mut gpui::TestAppContext) {
handle_resolve_completion_request(
&mut cx,
- Some((
- indoc! {"
- one.second_completion
- two
- threeˇ
- "},
- "\nadditional edit",
- )),
+ Some(vec![
+ (
+ //This overlaps with the primary completion edit which is
+ //misbehavior from the LSP spec, test that we filter it out
+ indoc! {"
+ one.second_ˇcompletion
+ two
+ threeˇ
+ "},
+ "overlapping aditional edit",
+ ),
+ (
+ indoc! {"
+ one.second_completion
+ two
+ threeˇ
+ "},
+ "\nadditional edit",
+ ),
+ ]),
)
.await;
apply_additional_edits.await.unwrap();
@@ -4303,19 +4315,24 @@ async fn test_completion(cx: &mut gpui::TestAppContext) {
async fn handle_resolve_completion_request<'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 (_, marked_ranges) = marked_text_ranges(marked_string, false);
- let replace_range = cx.to_lsp_range(marked_ranges[0].clone());
- vec![lsp::TextEdit::new(replace_range, new_text.to_string())]
+ let edits = edits.map(|edits| {
+ edits
+ .iter()
+ .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 |_, _, _| {
- let edit = edit.clone();
+ let edits = edits.clone();
async move {
Ok(lsp::CompletionItem {
- additional_text_edits: edit,
+ additional_text_edits: edits,
..Default::default()
})
}
diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs
index 0e2723201a7..1563cb9de42 100644
--- a/crates/project/src/project.rs
+++ b/crates/project/src/project.rs
@@ -3481,6 +3481,8 @@ impl Project {
let end_within = range.start.cmp(&primary.end, buffer).is_le()
&& 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 {
buffer.edit([(range, text)], None, cx);
}