@@ -16,6 +16,7 @@ use std::collections::HashMap;
1616use std:: ffi:: OsStr ;
1717use std:: path:: Path ;
1818use std:: path:: PathBuf ;
19+ use std:: sync:: Arc ;
1920use thiserror:: Error ;
2021use tree_sitter:: Language ;
2122use tree_sitter_graph:: ast:: File as TsgFile ;
@@ -25,6 +26,7 @@ use tree_sitter_loader::LanguageConfiguration as TSLanguageConfiguration;
2526use tree_sitter_loader:: Loader as TsLoader ;
2627
2728use crate :: CancellationFlag ;
29+ use crate :: FileAnalyzer ;
2830use crate :: StackGraphLanguage ;
2931
3032lazy_static ! {
@@ -42,6 +44,7 @@ pub struct LanguageConfiguration {
4244 pub file_types : Vec < String > ,
4345 pub sgl : StackGraphLanguage ,
4446 pub builtins : StackGraph ,
47+ pub special_files : FileAnalyzers ,
4548}
4649
4750impl LanguageConfiguration {
@@ -53,6 +56,7 @@ impl LanguageConfiguration {
5356 tsg_source : & str ,
5457 builtins_source : Option < & str > ,
5558 builtins_config : Option < & str > ,
59+ special_files : FileAnalyzers ,
5660 cancellation_flag : & dyn CancellationFlag ,
5761 ) -> Result < Self , LoadError > {
5862 let sgl = StackGraphLanguage :: from_str ( language, tsg_source) ?;
@@ -78,6 +82,7 @@ impl LanguageConfiguration {
7882 file_types,
7983 sgl,
8084 builtins,
85+ special_files,
8186 } )
8287 }
8388
@@ -86,6 +91,28 @@ impl LanguageConfiguration {
8691 }
8792}
8893
94+ #[ derive( Clone , Default ) ]
95+ pub struct FileAnalyzers {
96+ file_analyzers : HashMap < String , Arc < dyn FileAnalyzer > > ,
97+ }
98+
99+ impl FileAnalyzers {
100+ pub fn new ( ) -> Self {
101+ FileAnalyzers {
102+ file_analyzers : HashMap :: new ( ) ,
103+ }
104+ }
105+
106+ pub fn add ( mut self , file_name : String , analyzer : impl FileAnalyzer + ' static ) -> Self {
107+ self . file_analyzers . insert ( file_name, Arc :: new ( analyzer) ) ;
108+ self
109+ }
110+
111+ pub fn get ( & self , file_name : & str ) -> Option < & Arc < dyn FileAnalyzer > > {
112+ self . file_analyzers . get ( file_name)
113+ }
114+ }
115+
89116/// A load path specifies a file to load from, either as a regular path or relative to the grammar location.
90117#[ derive( Clone , Debug ) ]
91118pub enum LoadPath {
@@ -415,6 +442,7 @@ impl PathLoader {
415442 file_types : language. file_types ,
416443 sgl,
417444 builtins,
445+ special_files : FileAnalyzers :: new ( ) ,
418446 } ;
419447 self . cache . push ( ( language. language , lc) ) ;
420448
0 commit comments