From 6ac691b3e94147a70fc5a263799a935ddca62f02 Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Thu, 5 Dec 2024 13:28:43 +0100 Subject: [PATCH] Fix snippet completion will be trigger, when certain symbols are pressed (cherry-pick #21578) (#21585) Cherry-picked Fix snippet completion will be trigger, when certain symbols are pressed (#21578) Closes #21576 This issue is caused by the fuzzy matching for snippets I added [here](https://github.com/zed-industries/zed/pull/21524). When encountering symbols such as `:`, `(`, `.`, etc., the `last_word` becomes empty, which results in an empty string being passed to `fuzzy_match`, leading to the return of all templates. This fix adds an early return when `last_word` is empty. Release Notes: - N/A Co-authored-by: tims <0xtimsb@gmail.com> --- crates/editor/src/editor.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 40e2d7ab2e371e1a8336c4a9e97a13895edfd1fb..137cf379cd71b3fe71ecedcdf330b7bba3d73290 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -13835,6 +13835,11 @@ fn snippet_completions( .take_while(|c| classifier.is_word(*c)) .collect::(); last_word = last_word.chars().rev().collect(); + + if last_word.is_empty() { + return Ok(vec![]); + } + let as_offset = text::ToOffset::to_offset(&buffer_position, &snapshot); let to_lsp = |point: &text::Anchor| { let end = text::ToPointUtf16::to_point_utf16(point, &snapshot);