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.

lsp: Use CompletionTriggerKind::TRIGGER_CHARACTER only for characters allowlisted by the server (#14734)

Piotr Osiewicz3fb3148995da
diff --git a/crates/editor/src/actions.rs b/crates/editor/src/actions.rs
index 192162c594e..d6b3403da72 100644
--- a/crates/editor/src/actions.rs
+++ b/crates/editor/src/actions.rs
@@ -129,7 +129,7 @@ pub struct ExpandExcerptsDown {
#[derive(PartialEq, Clone, Deserialize, Default)]
pub struct ShowCompletions {
#[serde(default)]
- pub(super) trigger: Option<char>,
+ pub(super) trigger: Option<String>,
}
impl_actions!(
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs
index e5c9568b267..67cd0e3e6b1 100644
--- a/crates/editor/src/editor.rs
+++ b/crates/editor/src/editor.rs
@@ -3638,7 +3638,7 @@ impl Editor {
if self.is_completion_trigger(text, trigger_in_words, cx) {
self.show_completions(
&ShowCompletions {
- trigger: text.chars().last(),
+ trigger: Some(text.to_owned()).filter(|x| !x.is_empty()),
},
cx,
);
@@ -4062,15 +4062,18 @@ impl Editor {
Some(ContextMenu::Completions(_))
)
};
- let trigger_kind = match (options.trigger, is_followup_invoke) {
+ let trigger_kind = match (&options.trigger, is_followup_invoke) {
(_, true) => CompletionTriggerKind::TRIGGER_FOR_INCOMPLETE_COMPLETIONS,
- (Some(_), _) => CompletionTriggerKind::TRIGGER_CHARACTER,
+ (Some(trigger), _) if buffer.read(cx).completion_triggers().contains(&trigger) => {
+ CompletionTriggerKind::TRIGGER_CHARACTER
+ }
+
_ => CompletionTriggerKind::INVOKED,
};
let completion_context = CompletionContext {
- trigger_character: options.trigger.and_then(|c| {
+ trigger_character: options.trigger.as_ref().and_then(|trigger| {
if trigger_kind == CompletionTriggerKind::TRIGGER_CHARACTER {
- Some(String::from(c))
+ Some(String::from(trigger))
} else {
None
}