Start work on a Buffer API for requesting autoindent on the next parse

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld 2021-10-06 16:09:30 -07:00
parent a0c8b60a1b
commit b83b4ad7c7
5 changed files with 341 additions and 31 deletions

View file

@ -23,8 +23,9 @@ pub struct AutoclosePair {
pub struct Language {
pub(crate) config: LanguageConfig,
pub(crate) grammar: Grammar,
pub(crate) highlight_query: Query,
pub(crate) highlights_query: Query,
pub(crate) brackets_query: Query,
pub(crate) indents_query: Query,
pub(crate) highlight_map: Mutex<HighlightMap>,
}
@ -68,19 +69,25 @@ impl Language {
Self {
config,
brackets_query: Query::new(grammar, "").unwrap(),
highlight_query: Query::new(grammar, "").unwrap(),
highlights_query: Query::new(grammar, "").unwrap(),
indents_query: Query::new(grammar, "").unwrap(),
grammar,
highlight_map: Default::default(),
}
}
pub fn with_highlights_query(mut self, highlights_query_source: &str) -> Result<Self> {
self.highlight_query = Query::new(self.grammar, highlights_query_source)?;
pub fn with_highlights_query(mut self, source: &str) -> Result<Self> {
self.highlights_query = Query::new(self.grammar, source)?;
Ok(self)
}
pub fn with_brackets_query(mut self, brackets_query_source: &str) -> Result<Self> {
self.brackets_query = Query::new(self.grammar, brackets_query_source)?;
pub fn with_brackets_query(mut self, source: &str) -> Result<Self> {
self.brackets_query = Query::new(self.grammar, source)?;
Ok(self)
}
pub fn with_indents_query(mut self, source: &str) -> Result<Self> {
self.indents_query = Query::new(self.grammar, source)?;
Ok(self)
}
@ -97,7 +104,8 @@ impl Language {
}
pub fn set_theme(&self, theme: &SyntaxTheme) {
*self.highlight_map.lock() = HighlightMap::new(self.highlight_query.capture_names(), theme);
*self.highlight_map.lock() =
HighlightMap::new(self.highlights_query.capture_names(), theme);
}
}
@ -110,28 +118,22 @@ mod tests {
let grammar = tree_sitter_rust::language();
let registry = LanguageRegistry {
languages: vec![
Arc::new(Language {
config: LanguageConfig {
Arc::new(Language::new(
LanguageConfig {
name: "Rust".to_string(),
path_suffixes: vec!["rs".to_string()],
..Default::default()
},
grammar,
highlight_query: Query::new(grammar, "").unwrap(),
brackets_query: Query::new(grammar, "").unwrap(),
highlight_map: Default::default(),
}),
Arc::new(Language {
config: LanguageConfig {
)),
Arc::new(Language::new(
LanguageConfig {
name: "Make".to_string(),
path_suffixes: vec!["Makefile".to_string(), "mk".to_string()],
..Default::default()
},
grammar,
highlight_query: Query::new(grammar, "").unwrap(),
brackets_query: Query::new(grammar, "").unwrap(),
highlight_map: Default::default(),
}),
)),
],
};