Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Fix completion-filtering by checking actual word boundaries & reduce Ruby word chars (#9170)
Thorsten Ballb2981f4baa14
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex bd4fccf4a9b..33335132905 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -10700,32 +10700,23 @@ pub fn styled_runs_for_code_label<'a>(}pub(crate) fn split_words(text: &str) -> impl std::iter::Iterator<Item = &str> + '_ {- let mut index = 0;- let mut codepoints = text.char_indices().peekable();-- std::iter::from_fn(move || {- let start_index = index;- while let Some((new_index, codepoint)) = codepoints.next() {- index = new_index + codepoint.len_utf8();- let current_upper = codepoint.is_uppercase();- let next_upper = codepoints- .peek()- .map(|(_, c)| c.is_uppercase())- .unwrap_or(false);-- if !current_upper && next_upper {- return Some(&text[start_index..index]);+ let mut prev_index = 0;+ let mut prev_codepoint: Option<char> = None;+ text.char_indices()+ .chain([(text.len(), '\0')])+ .filter_map(move |(index, codepoint)| {+ let prev_codepoint = prev_codepoint.replace(codepoint)?;+ let is_boundary = index == text.len()+ || !prev_codepoint.is_uppercase() && codepoint.is_uppercase()+ || !prev_codepoint.is_alphanumeric() && codepoint.is_alphanumeric();+ if is_boundary {+ let chunk = &text[prev_index..index];+ prev_index = index;+ Some(chunk)+ } else {+ None}- }-- index = text.len();- if start_index < text.len() {- return Some(&text[start_index..]);- }- None- })- .flat_map(|word| word.split_inclusive('_'))- .flat_map(|word| word.split_inclusive('-'))+ })}trait RangeToAnchorExt {diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rsindex 21a24817ea9..c1db51fef8c 100644--- a/crates/editor/src/editor_tests.rs+++ b/crates/editor/src/editor_tests.rs@@ -7442,6 +7442,8 @@ fn test_split_words() {assert_eq!(split("Hello_World"), &["Hello_", "World"]);assert_eq!(split("helloWOrld"), &["hello", "WOrld"]);assert_eq!(split("helloworld"), &["helloworld"]);++ assert_eq!(split(":do_the_thing"), &[":", "do_", "the_", "thing"]);}#[gpui::test]diff --git a/crates/languages/src/ruby/config.toml b/crates/languages/src/ruby/config.tomlindex 3784952f6c7..54072d801bd 100644--- a/crates/languages/src/ruby/config.toml+++ b/crates/languages/src/ruby/config.toml@@ -37,4 +37,3 @@ brackets = [] },]collapsed_placeholder = "# ..."-word_characters = ["_", "$", "=", "@", "!", ":", "?"]diff --git a/crates/languages/src/ruby/overrides.scm b/crates/languages/src/ruby/overrides.scmindex 8a58e304e5c..7ff82bd3457 100644--- a/crates/languages/src/ruby/overrides.scm+++ b/crates/languages/src/ruby/overrides.scm@@ -1,2 +1,3 @@(comment) @comment(string) @string+[(simple_symbol) (delimited_symbol)] @simple_symbol