Make the fields of buffer::Language private
This commit is contained in:
parent
0282e6f255
commit
3cb7ba0f57
6 changed files with 97 additions and 100 deletions
|
@ -1,10 +1,11 @@
|
|||
use crate::{HighlightMap};
|
||||
use crate::HighlightMap;
|
||||
use anyhow::Result;
|
||||
use parking_lot::Mutex;
|
||||
use serde::Deserialize;
|
||||
use std::{path::Path, str, sync::Arc};
|
||||
use theme::SyntaxTheme;
|
||||
use tree_sitter::{Language as Grammar, Query};
|
||||
pub use tree_sitter::{Parser, Tree};
|
||||
use theme::SyntaxTheme;
|
||||
|
||||
#[derive(Default, Deserialize)]
|
||||
pub struct LanguageConfig {
|
||||
|
@ -12,18 +13,12 @@ pub struct LanguageConfig {
|
|||
pub path_suffixes: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct BracketPair {
|
||||
pub start: String,
|
||||
pub end: String,
|
||||
}
|
||||
|
||||
pub struct Language {
|
||||
pub config: LanguageConfig,
|
||||
pub grammar: Grammar,
|
||||
pub highlight_query: Query,
|
||||
pub brackets_query: Query,
|
||||
pub highlight_map: Mutex<HighlightMap>,
|
||||
pub(crate) config: LanguageConfig,
|
||||
pub(crate) grammar: Grammar,
|
||||
pub(crate) highlight_query: Query,
|
||||
pub(crate) brackets_query: Query,
|
||||
pub(crate) highlight_map: Mutex<HighlightMap>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -62,6 +57,26 @@ impl LanguageRegistry {
|
|||
}
|
||||
|
||||
impl Language {
|
||||
pub fn new(config: LanguageConfig, grammar: Grammar) -> Self {
|
||||
Self {
|
||||
config,
|
||||
brackets_query: Query::new(grammar, "").unwrap(),
|
||||
highlight_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)?;
|
||||
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)?;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn name(&self) -> &str {
|
||||
self.config.name.as_str()
|
||||
}
|
||||
|
|
|
@ -4078,19 +4078,16 @@ mod tests {
|
|||
}
|
||||
|
||||
fn rust_lang() -> Arc<Language> {
|
||||
let lang = tree_sitter_rust::language();
|
||||
let brackets_query = r#"
|
||||
("{" @open "}" @close)
|
||||
"#;
|
||||
Arc::new(Language {
|
||||
config: LanguageConfig {
|
||||
name: "Rust".to_string(),
|
||||
path_suffixes: vec!["rs".to_string()],
|
||||
},
|
||||
grammar: tree_sitter_rust::language(),
|
||||
highlight_query: tree_sitter::Query::new(lang.clone(), "").unwrap(),
|
||||
brackets_query: tree_sitter::Query::new(lang.clone(), brackets_query).unwrap(),
|
||||
highlight_map: Default::default(),
|
||||
})
|
||||
Arc::new(
|
||||
Language::new(
|
||||
LanguageConfig {
|
||||
name: "Rust".to_string(),
|
||||
path_suffixes: vec!["rs".to_string()],
|
||||
},
|
||||
tree_sitter_rust::language(),
|
||||
)
|
||||
.with_brackets_query(r#" ("{" @open "}" @close) "#)
|
||||
.unwrap(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue