Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
WIP: Saved state from Friday.
Piotr Osiewicz3e8522b5f24d
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex 904e77c9f0f..0cbaf617933 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -2657,7 +2657,8 @@ impl Editor {false});}-+ // $language = true;+ // languagefn completion_query(buffer: &MultiBufferSnapshot, position: impl ToOffset) -> Option<String> {let offset = position.to_offset(buffer);let (word_range, kind) = buffer.surrounding_word(offset);diff --git a/crates/editor/src/movement.rs b/crates/editor/src/movement.rsindex f70436abeb4..345b7404d9d 100644--- a/crates/editor/src/movement.rs+++ b/crates/editor/src/movement.rs@@ -176,14 +176,18 @@ pub fn line_end(}pub fn previous_word_start(map: &DisplaySnapshot, point: DisplayPoint) -> DisplayPoint {+ let language = map.buffer_snapshot.language_at(point);find_preceding_boundary(map, point, |left, right| {- (char_kind(left) != char_kind(right) && !right.is_whitespace()) || left == '\n'+ (char_kind(language, left) != char_kind(language, right) && !right.is_whitespace())+ || left == '\n'})}pub fn previous_subword_start(map: &DisplaySnapshot, point: DisplayPoint) -> DisplayPoint {+ let language = map.buffer_snapshot.language_at(point);find_preceding_boundary(map, point, |left, right| {- let is_word_start = char_kind(left) != char_kind(right) && !right.is_whitespace();+ let is_word_start =+ char_kind(language, left) != char_kind(language, right) && !right.is_whitespace();let is_subword_start =left == '_' && right != '_' || left.is_lowercase() && right.is_uppercase();is_word_start || is_subword_start || left == '\n'diff --git a/crates/editor/src/multi_buffer.rs b/crates/editor/src/multi_buffer.rsindex 8417c411f24..d4061f25dc6 100644--- a/crates/editor/src/multi_buffer.rs+++ b/crates/editor/src/multi_buffer.rs@@ -1865,13 +1865,16 @@ impl MultiBufferSnapshot {let mut end = start;let mut next_chars = self.chars_at(start).peekable();let mut prev_chars = self.reversed_chars_at(start).peekable();++ let language = self.language_at(start);+ let kind = |c| char_kind(language, c);let word_kind = cmp::max(- prev_chars.peek().copied().map(char_kind),- next_chars.peek().copied().map(char_kind),+ prev_chars.peek().copied().map(kind),+ next_chars.peek().copied().map(kind),);for ch in prev_chars {- if Some(char_kind(ch)) == word_kind && ch != '\n' {+ if Some(kind(ch)) == word_kind && ch != '\n' {start -= ch.len_utf8();} else {break;@@ -1879,7 +1882,7 @@ impl MultiBufferSnapshot {}for ch in next_chars {- if Some(char_kind(ch)) == word_kind && ch != '\n' {+ if Some(kind(ch)) == word_kind && ch != '\n' {end += ch.len_utf8();} else {break;diff --git a/crates/language/src/buffer.rs b/crates/language/src/buffer.rsindex 48dc936a949..171df8f882e 100644--- a/crates/language/src/buffer.rs+++ b/crates/language/src/buffer.rs@@ -2173,13 +2173,16 @@ impl BufferSnapshot {let mut end = start;let mut next_chars = self.chars_at(start).peekable();let mut prev_chars = self.reversed_chars_at(start).peekable();++ let language = self.language_at(start);+ let kind = |c| char_kind(language, c);let word_kind = cmp::max(- prev_chars.peek().copied().map(char_kind),- next_chars.peek().copied().map(char_kind),+ prev_chars.peek().copied().map(kind),+ next_chars.peek().copied().map(kind),);for ch in prev_chars {- if Some(char_kind(ch)) == word_kind && ch != '\n' {+ if Some(kind(ch)) == word_kind && ch != '\n' {start -= ch.len_utf8();} else {break;@@ -2187,7 +2190,7 @@ impl BufferSnapshot {}for ch in next_chars {- if Some(char_kind(ch)) == word_kind && ch != '\n' {+ if Some(kind(ch)) == word_kind && ch != '\n' {end += ch.len_utf8();} else {break;@@ -2984,7 +2987,7 @@ pub fn contiguous_ranges(})}-pub fn char_kind(c: char) -> CharKind {+pub fn char_kind(language: Option<&Arc<Language>>, c: char) -> CharKind {if c.is_whitespace() {CharKind::Whitespace} else if c.is_alphanumeric() || c == '_' || c == '$' {diff --git a/crates/project/src/search.rs b/crates/project/src/search.rsindex 08ff803598f..6d9de9c974e 100644--- a/crates/project/src/search.rs+++ b/crates/project/src/search.rs@@ -39,6 +39,7 @@ pub enum SearchQuery {case_sensitive: bool,inner: SearchInputs,},+Regex {regex: Regex,@@ -220,6 +221,8 @@ impl SearchQuery {if self.as_str().is_empty() {return Default::default();}+ let language = rope.language(cx);+ let kind = |c| char_kind(language, c);let mut matches = Vec::new();match self {@@ -236,10 +239,10 @@ impl SearchQuery {let mat = mat.unwrap();if *whole_word {- let prev_kind = rope.reversed_chars_at(mat.start()).next().map(char_kind);- let start_kind = char_kind(rope.chars_at(mat.start()).next().unwrap());- let end_kind = char_kind(rope.reversed_chars_at(mat.end()).next().unwrap());- let next_kind = rope.chars_at(mat.end()).next().map(char_kind);+ let prev_kind = rope.reversed_chars_at(mat.start()).next().map(kind);+ let start_kind = kind(rope.chars_at(mat.start()).next().unwrap());+ let end_kind = kind(rope.reversed_chars_at(mat.end()).next().unwrap());+ let next_kind = rope.chars_at(mat.end()).next().map(kind);if Some(start_kind) == prev_kind || Some(end_kind) == next_kind {continue;}@@ -247,6 +250,7 @@ impl SearchQuery {matches.push(mat.start()..mat.end())}}+Self::Regex {regex, multiline, ..} => {@@ -284,6 +288,7 @@ impl SearchQuery {}}}+matches}