@@ -44,11 +44,12 @@ pub struct LanguageConfiguration {
4444 pub sgl : StackGraphLanguage ,
4545 pub builtins : StackGraph ,
4646 pub special_files : FileAnalyzers ,
47+ pub has_similar_paths : bool ,
4748}
4849
4950impl LanguageConfiguration {
5051 /// Build a language configuration from tsg and builtins sources. The tsg path
51- /// is kept for informational only, see [`StackGraphLanguage::from_source`][].
52+ /// is kept for informational use only, see [`StackGraphLanguage::from_source`][].
5253 pub fn from_sources < ' a > (
5354 language : Language ,
5455 scope : Option < String > ,
@@ -58,7 +59,6 @@ impl LanguageConfiguration {
5859 tsg_source : & ' a str ,
5960 builtins_source : Option < ( PathBuf , & ' a str ) > ,
6061 builtins_config : Option < & str > ,
61- special_files : FileAnalyzers ,
6262 cancellation_flag : & dyn CancellationFlag ,
6363 ) -> Result < Self , LoadError < ' a > > {
6464 let sgl = StackGraphLanguage :: from_source ( language, tsg_path. clone ( ) , tsg_source) . map_err (
@@ -97,7 +97,8 @@ impl LanguageConfiguration {
9797 file_types,
9898 sgl,
9999 builtins,
100- special_files,
100+ special_files : FileAnalyzers :: new ( ) ,
101+ has_similar_paths : true ,
101102 } )
102103 }
103104
@@ -143,7 +144,7 @@ impl FileAnalyzers {
143144 }
144145 }
145146
146- pub fn add (
147+ pub fn with (
147148 mut self ,
148149 file_name : String ,
149150 analyzer : impl FileAnalyzer + Send + Sync + ' static ,
@@ -152,6 +153,15 @@ impl FileAnalyzers {
152153 self
153154 }
154155
156+ pub fn add (
157+ & mut self ,
158+ file_name : String ,
159+ analyzer : impl FileAnalyzer + Send + Sync + ' static ,
160+ ) -> & mut Self {
161+ self . file_analyzers . insert ( file_name, Arc :: new ( analyzer) ) ;
162+ self
163+ }
164+
155165 pub fn get ( & self , file_name : & str ) -> Option < Arc < dyn FileAnalyzer + Send + Sync > > {
156166 self . file_analyzers . get ( file_name) . cloned ( )
157167 }
@@ -358,6 +368,20 @@ impl FileLanguageConfigurations<'_> {
358368 pub fn has_some ( & self ) -> bool {
359369 self . primary . is_some ( ) || !self . secondary . is_empty ( )
360370 }
371+
372+ pub fn has_similar_paths ( & self ) -> bool {
373+ if let Some ( lc) = & self . primary {
374+ if lc. has_similar_paths {
375+ return true ;
376+ }
377+ }
378+ for ( lc, _) in & self . secondary {
379+ if lc. has_similar_paths {
380+ return true ;
381+ }
382+ }
383+ return false ;
384+ }
361385}
362386
363387#[ derive( Debug , Error ) ]
@@ -568,6 +592,8 @@ impl PathLoader {
568592 sgl,
569593 builtins,
570594 special_files : FileAnalyzers :: new ( ) ,
595+ // always detect similar paths, we don't know the language configuration when loading from the file system
596+ has_similar_paths : true ,
571597 } ;
572598 self . cache . push ( ( language. language , lc) ) ;
573599
0 commit comments