Use new char_kind (parameterized by language)

This commit is contained in:
Piotr Osiewicz
2023-08-21 17:39:38 +02:00
parent 3e8522b5f2
commit ab5bd0ac5a
9 changed files with 93 additions and 47 deletions
+9 -5
View File
@@ -2989,12 +2989,16 @@ pub fn contiguous_ranges(
pub fn char_kind(language: Option<&Arc<Language>>, c: char) -> CharKind {
if c.is_whitespace() {
CharKind::Whitespace
} else if c.is_alphanumeric() || c == '_' || c == '$' {
CharKind::Word
} else {
CharKind::Punctuation
return CharKind::Whitespace;
} else if c.is_alphanumeric() || c == '_' {
return CharKind::Word;
}
if let Some(language) = language {
if language.config.word_boundaries.contains(&c) {
return CharKind::Word;
}
}
CharKind::Punctuation
}
/// Find all of the ranges of whitespace that occur at the ends of lines
+4 -1
View File
@@ -11,7 +11,7 @@ mod buffer_tests;
use anyhow::{anyhow, Context, Result};
use async_trait::async_trait;
use collections::HashMap;
use collections::{HashMap, HashSet};
use futures::{
channel::oneshot,
future::{BoxFuture, Shared},
@@ -344,6 +344,8 @@ pub struct LanguageConfig {
pub block_comment: Option<(Arc<str>, Arc<str>)>,
#[serde(default)]
pub overrides: HashMap<String, LanguageConfigOverride>,
#[serde(default)]
pub word_boundaries: HashSet<char>,
}
#[derive(Debug, Default)]
@@ -411,6 +413,7 @@ impl Default for LanguageConfig {
block_comment: Default::default(),
overrides: Default::default(),
collapsed_placeholder: Default::default(),
word_boundaries: Default::default(),
}
}
}