WIP: Saved state from Friday.

Co-authored-by: Julia Risley <julia@zed.dev>
This commit is contained in:
Piotr Osiewicz
2023-08-21 17:09:03 +02:00
co-authored by Julia Risley
parent 273a8b4368
commit 3e8522b5f2
5 changed files with 32 additions and 16 deletions
+2 -1
View File
@@ -2657,7 +2657,8 @@ impl Editor {
false
});
}
// $language = true;
// language
fn completion_query(buffer: &MultiBufferSnapshot, position: impl ToOffset) -> Option<String> {
let offset = position.to_offset(buffer);
let (word_range, kind) = buffer.surrounding_word(offset);
+6 -2
View File
@@ -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'
+7 -4
View File
@@ -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;