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

Fixes #13823


Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2024-07-18 14:53:31 +02:00 committed by GitHub
parent 76ce1a8f50
commit 3fb3148995
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 6 deletions

View File

@ -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!(

View File

@ -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
}