Add support for multi-word snippet prefixes (#42398)

Supercedes #41126

Closes #39559, #35397, and #41426

Release Notes:

- Added support for multi-word snippet prefixes

---------

Co-authored-by: Agus Zubiaga <hi@aguz.me>
Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
Co-authored-by: Cole Miller <cole@zed.dev>
This commit is contained in:
Andrew Farkas
2025-11-11 16:34:25 -05:00
committed by GitHub
co-authored by Agus Zubiaga Conrad Irwin Cole Miller
parent f62bfe1dfa
commit da94f898e6
16 changed files with 656 additions and 190 deletions
+6
View File
@@ -10143,6 +10143,8 @@ impl LspStore {
source: completion.source,
documentation: None,
label: CodeLabel::default(),
match_start: None,
snippet_deduplication_key: None,
insert_text_mode: None,
icon_path: None,
confirm: None,
@@ -12847,6 +12849,8 @@ async fn populate_labels_for_completions(
source: completion.source,
icon_path: None,
confirm: None,
match_start: None,
snippet_deduplication_key: None,
});
}
None => {
@@ -12861,6 +12865,8 @@ async fn populate_labels_for_completions(
insert_text_mode: None,
icon_path: None,
confirm: None,
match_start: None,
snippet_deduplication_key: None,
});
}
}
+16
View File
@@ -103,6 +103,7 @@ use search_history::SearchHistory;
use settings::{InvalidSettingsError, RegisterSetting, Settings, SettingsLocation, SettingsStore};
use smol::channel::Receiver;
use snippet::Snippet;
pub use snippet_provider;
use snippet_provider::SnippetProvider;
use std::{
borrow::Cow,
@@ -476,6 +477,12 @@ pub struct Completion {
pub source: CompletionSource,
/// A path to an icon for this completion that is shown in the menu.
pub icon_path: Option<SharedString>,
/// Text starting here and ending at the cursor will be used as the query for filtering this completion.
///
/// If None, the start of the surrounding word is used.
pub match_start: Option<text::Anchor>,
/// Key used for de-duplicating snippets. If None, always considered unique.
pub snippet_deduplication_key: Option<(usize, usize)>,
/// Whether to adjust indentation (the default) or not.
pub insert_text_mode: Option<InsertTextMode>,
/// An optional callback to invoke when this completion is confirmed.
@@ -5643,6 +5650,15 @@ impl Completion {
}
/// Whether this completion is a snippet.
pub fn is_snippet_kind(&self) -> bool {
matches!(
&self.source,
CompletionSource::Lsp { lsp_completion, .. }
if lsp_completion.kind == Some(CompletionItemKind::SNIPPET)
)
}
/// Whether this completion is a snippet or snippet-style LSP completion.
pub fn is_snippet(&self) -> bool {
self.source
// `lsp::CompletionListItemDefaults` has `insert_text_format` field