Skip to content

Commit

Permalink
Change setting name and add comment explaining the consequences
Browse files Browse the repository at this point in the history
  • Loading branch information
hendrikvanantwerpen committed Nov 20, 2023
1 parent 3d32fbb commit 294596a
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion languages/tree-sitter-stack-graphs-typescript/rust/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ pub fn try_language_configuration(
lc.special_files
.add("tsconfig.json".to_string(), TsConfigAnalyzer {})
.add("package.json".to_string(), NpmPackageAnalyzer {});
lc.has_similar_paths = false;
lc.no_similar_paths_in_file = true;
Ok(lc)
}
1 change: 1 addition & 0 deletions stack-graphs/src/stitching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,7 @@ impl<H> ForwardPartialPathStitcher<H> {
initial_paths: next_iteration.0.len(),
next_iteration,
appended_paths,
// By default, all paths are checked for similarity
similar_path_detector: Some(SimilarPathDetector::new()),
// By default, all nodes are checked for cycles and (if enabled) similarity
check_only_join_nodes: false,
Expand Down
2 changes: 1 addition & 1 deletion tree-sitter-stack-graphs/src/cli/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ impl<'a> Indexer<'a> {
Err(e) => return Err(IndexError::LoadError(e)),
};
let stitcher_config =
StitcherConfig::default().with_detect_similar_paths(lcs.has_similar_paths());
StitcherConfig::default().with_detect_similar_paths(!lcs.no_similar_paths_in_file());

let source = file_reader.get(source_path)?;
let tag = sha1(source);
Expand Down
2 changes: 1 addition & 1 deletion tree-sitter-stack-graphs/src/cli/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ impl TestArgs {
}
}
let stitcher_config =
StitcherConfig::default().with_detect_similar_paths(lc.has_similar_paths);
StitcherConfig::default().with_detect_similar_paths(!lc.no_similar_paths_in_file);
let mut partials = PartialPaths::new();
let mut db = Database::new();
for file in test.graph.iter_files() {
Expand Down
23 changes: 12 additions & 11 deletions tree-sitter-stack-graphs/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ pub struct LanguageConfiguration {
pub sgl: StackGraphLanguage,
pub builtins: StackGraph,
pub special_files: FileAnalyzers,
pub has_similar_paths: bool,
/// Can be set to true if the stack graph rules ensure that there can be no similar
/// paths in a file, in which case it is safe to turn of similar path detection. If
/// incorrectly set to true, performance of path finding suffers from exponential
/// blow up.
pub no_similar_paths_in_file: bool,
}

impl LanguageConfiguration {
Expand Down Expand Up @@ -98,7 +102,7 @@ impl LanguageConfiguration {
sgl,
builtins,
special_files: FileAnalyzers::new(),
has_similar_paths: true,
no_similar_paths_in_file: false,
})
}

Expand Down Expand Up @@ -369,18 +373,15 @@ impl FileLanguageConfigurations<'_> {
self.primary.is_some() || !self.secondary.is_empty()
}

pub fn has_similar_paths(&self) -> bool {
pub fn no_similar_paths_in_file(&self) -> bool {
let mut no_similar_paths_in_file = true;
if let Some(lc) = &self.primary {
if lc.has_similar_paths {
return true;
}
no_similar_paths_in_file &= lc.no_similar_paths_in_file;
}
for (lc, _) in &self.secondary {
if lc.has_similar_paths {
return true;
}
no_similar_paths_in_file &= lc.no_similar_paths_in_file;
}
return false;
return no_similar_paths_in_file;
}
}

Expand Down Expand Up @@ -593,7 +594,7 @@ impl PathLoader {
builtins,
special_files: FileAnalyzers::new(),
// always detect similar paths, we don't know the language configuration when loading from the file system
has_similar_paths: true,
no_similar_paths_in_file: false,
};
self.cache.push((language.language, lc));

Expand Down
2 changes: 1 addition & 1 deletion tree-sitter-stack-graphs/tests/it/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn can_load_from_provided_language_configuration() {
sgl,
builtins: StackGraph::new(),
special_files: FileAnalyzers::new(),
has_similar_paths: true,
no_similar_paths_in_file: false,
};
let mut loader =
Loader::from_language_configurations(vec![lc], None).expect("Expected loader to succeed");
Expand Down

0 comments on commit 294596a

Please sign in to comment.