diff --git a/src/syntax/tree_sitter_adapter.rs b/src/syntax/tree_sitter_adapter.rs index b239f55..a57f83b 100644 --- a/src/syntax/tree_sitter_adapter.rs +++ b/src/syntax/tree_sitter_adapter.rs @@ -26,12 +26,13 @@ use tree_sitter_highlight::{HighlightConfiguration, HighlightEvent, Highlighter} use tree_sitter_loader::{Config, LanguageConfiguration, Loader}; pub struct TreesitterSyntaxAdapter { - parsers_directory: PathBuf, + loader: Loader } impl TreesitterSyntaxAdapter { pub fn new(parsers_directory: PathBuf) -> anyhow::Result { - Ok(TreesitterSyntaxAdapter { parsers_directory }) + let loader = TreesitterSyntaxAdapter::get_loader(&parsers_directory)?; + Ok(TreesitterSyntaxAdapter { loader }) } pub fn get_loader(parsers_directory: &Path) -> anyhow::Result { @@ -93,8 +94,6 @@ impl TreesitterSyntaxAdapter { highlighter.highlight(highlight_config, code.as_bytes(), None, |lang| { loader.highlight_config_for_injection_string(lang) })?; - // loader.configure_highlights(&highlight_config.names().to_vec()); - Ok(highlights) } @@ -127,11 +126,10 @@ impl SyntaxHighlighterAdapter for TreesitterSyntaxAdapter { return Ok(()); }; - let loader = TreesitterSyntaxAdapter::get_loader(&self.parsers_directory).unwrap(); let mut highlighter = Highlighter::new(); - if let Ok(highlights) = self.get_highlights(&loader, &mut highlighter, code, scope.as_str()) + if let Ok(highlights) = self.get_highlights(&self.loader, &mut highlighter, code, scope.as_str()) { - let highlight_names = loader.highlight_names(); + let highlight_names = self.loader.highlight_names(); for event in highlights { match event.unwrap() {