Do not repeat proposed LSP completions in the word completions (#26682)
Follow-up of https://github.com/zed-industries/zed/pull/26410 Release Notes: - N/A
This commit is contained in:
parent
8ec0309645
commit
b0b65420f6
2 changed files with 85 additions and 19 deletions
|
@ -4104,23 +4104,26 @@ impl Editor {
|
||||||
|
|
||||||
match completion_settings.words {
|
match completion_settings.words {
|
||||||
WordsCompletionMode::Enabled => {
|
WordsCompletionMode::Enabled => {
|
||||||
completions.extend(
|
let mut words = words.await;
|
||||||
words
|
if let Some(word_to_exclude) = &word_to_exclude {
|
||||||
.await
|
words.remove(word_to_exclude);
|
||||||
.into_iter()
|
}
|
||||||
.filter(|(word, _)| word_to_exclude.as_ref() != Some(word))
|
for lsp_completion in &completions {
|
||||||
.map(|(word, word_range)| Completion {
|
words.remove(&lsp_completion.new_text);
|
||||||
old_range: old_range.clone(),
|
}
|
||||||
new_text: word.clone(),
|
completions.extend(words.into_iter().map(|(word, word_range)| {
|
||||||
label: CodeLabel::plain(word, None),
|
Completion {
|
||||||
documentation: None,
|
old_range: old_range.clone(),
|
||||||
source: CompletionSource::BufferWord {
|
new_text: word.clone(),
|
||||||
word_range,
|
label: CodeLabel::plain(word, None),
|
||||||
resolved: false,
|
documentation: None,
|
||||||
},
|
source: CompletionSource::BufferWord {
|
||||||
confirm: None,
|
word_range,
|
||||||
}),
|
resolved: false,
|
||||||
);
|
},
|
||||||
|
confirm: None,
|
||||||
|
}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
WordsCompletionMode::Fallback => {
|
WordsCompletionMode::Fallback => {
|
||||||
if completions.is_empty() {
|
if completions.is_empty() {
|
||||||
|
|
|
@ -9236,11 +9236,11 @@ async fn test_words_completion(cx: &mut TestAppContext) {
|
||||||
Ok(Some(lsp::CompletionResponse::Array(vec![
|
Ok(Some(lsp::CompletionResponse::Array(vec![
|
||||||
lsp::CompletionItem {
|
lsp::CompletionItem {
|
||||||
label: "first".into(),
|
label: "first".into(),
|
||||||
..Default::default()
|
..lsp::CompletionItem::default()
|
||||||
},
|
},
|
||||||
lsp::CompletionItem {
|
lsp::CompletionItem {
|
||||||
label: "last".into(),
|
label: "last".into(),
|
||||||
..Default::default()
|
..lsp::CompletionItem::default()
|
||||||
},
|
},
|
||||||
])))
|
])))
|
||||||
}
|
}
|
||||||
|
@ -9290,6 +9290,69 @@ async fn test_words_completion(cx: &mut TestAppContext) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[gpui::test]
|
||||||
|
async fn test_word_completions_do_not_duplicate_lsp_ones(cx: &mut TestAppContext) {
|
||||||
|
init_test(cx, |language_settings| {
|
||||||
|
language_settings.defaults.completions = Some(CompletionSettings {
|
||||||
|
words: WordsCompletionMode::Enabled,
|
||||||
|
lsp: true,
|
||||||
|
lsp_fetch_timeout_ms: 0,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
let mut cx = EditorLspTestContext::new_rust(
|
||||||
|
lsp::ServerCapabilities {
|
||||||
|
completion_provider: Some(lsp::CompletionOptions {
|
||||||
|
trigger_characters: Some(vec![".".to_string(), ":".to_string()]),
|
||||||
|
..lsp::CompletionOptions::default()
|
||||||
|
}),
|
||||||
|
signature_help_provider: Some(lsp::SignatureHelpOptions::default()),
|
||||||
|
..lsp::ServerCapabilities::default()
|
||||||
|
},
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
let _completion_requests_handler =
|
||||||
|
cx.lsp
|
||||||
|
.server
|
||||||
|
.on_request::<lsp::request::Completion, _, _>(move |_, _| async move {
|
||||||
|
Ok(Some(lsp::CompletionResponse::Array(vec![
|
||||||
|
lsp::CompletionItem {
|
||||||
|
label: "first".into(),
|
||||||
|
..lsp::CompletionItem::default()
|
||||||
|
},
|
||||||
|
lsp::CompletionItem {
|
||||||
|
label: "last".into(),
|
||||||
|
..lsp::CompletionItem::default()
|
||||||
|
},
|
||||||
|
])))
|
||||||
|
});
|
||||||
|
|
||||||
|
cx.set_state(indoc! {"ˇ
|
||||||
|
first
|
||||||
|
last
|
||||||
|
second
|
||||||
|
"});
|
||||||
|
cx.simulate_keystroke(".");
|
||||||
|
cx.executor().run_until_parked();
|
||||||
|
cx.condition(|editor, _| editor.context_menu_visible())
|
||||||
|
.await;
|
||||||
|
cx.update_editor(|editor, window, cx| {
|
||||||
|
if let Some(CodeContextMenu::Completions(menu)) = editor.context_menu.borrow_mut().as_ref()
|
||||||
|
{
|
||||||
|
assert_eq!(
|
||||||
|
completion_menu_entries(&menu),
|
||||||
|
&["first", "last", "second"],
|
||||||
|
"Word completions that has the same edit as the any of the LSP ones, should not be proposed"
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
panic!("expected completion menu to be open");
|
||||||
|
}
|
||||||
|
editor.cancel(&Cancel, window, cx);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_multiline_completion(cx: &mut TestAppContext) {
|
async fn test_multiline_completion(cx: &mut TestAppContext) {
|
||||||
init_test(cx, |_| {});
|
init_test(cx, |_| {});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue