Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit 43d6595

Browse files
author
Hendrik van Antwerpen
committed
Return file analyzer together with the language configuration so clients do not have to go through a seemingly fallible lookup themselves
1 parent fced615 commit 43d6595

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

tree-sitter-stack-graphs/src/cli/index.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -356,14 +356,7 @@ impl<'a> Indexer<'a> {
356356
tsg_str: &lc.sgl.tsg_source(),
357357
})?;
358358
}
359-
for lc in lcs.secondary {
360-
let fa = match source_path
361-
.file_name()
362-
.and_then(|file_name| lc.special_files.get(&file_name.to_string_lossy()))
363-
{
364-
Some(fa) => fa,
365-
None => panic!("secondary language missing analyzer"),
366-
};
359+
for (_, fa) in lcs.secondary {
367360
fa.build_stack_graph_into(
368361
graph,
369362
file,

tree-sitter-stack-graphs/src/cli/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ impl TestArgs {
211211
.load_for_file(&load_path, &mut file_reader, cancellation_flag)?
212212
.primary
213213
{
214-
Some(sgl) => sgl,
214+
Some(lc) => lc,
215215
None => return Ok(TestResult::new()),
216216
};
217217

tree-sitter-stack-graphs/src/loader.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,10 @@ pub struct FileLanguageConfigurations<'a> {
348348
/// The file's primary language. The language configuration's `StackGraphLanguage` should be used to process the file.
349349
pub primary: Option<&'a LanguageConfiguration>,
350350
/// Any secondary languages, which have special file analyzers for the file.
351-
pub secondary: Vec<&'a LanguageConfiguration>,
351+
pub secondary: Vec<(
352+
&'a LanguageConfiguration,
353+
Arc<dyn FileAnalyzer + Send + Sync>,
354+
)>,
352355
}
353356

354357
impl FileLanguageConfigurations<'_> {
@@ -470,12 +473,11 @@ impl LanguageConfigurationsLoader {
470473
let primary = LanguageConfiguration::best_for_file(&self.configurations, path, content)?;
471474
let mut secondary = Vec::new();
472475
for language in self.configurations.iter() {
473-
if path
476+
if let Some(fa) = path
474477
.file_name()
475478
.and_then(|file_name| language.special_files.get(&file_name.to_string_lossy()))
476-
.is_some()
477479
{
478-
secondary.push(language);
480+
secondary.push((language, fa));
479481
}
480482
}
481483
Ok(FileLanguageConfigurations { primary, secondary })

0 commit comments

Comments
 (0)