Skip to content

Commit

Permalink
build_assets.rs: Make OtherSyntaxLookup come before SyntaxToDependencies
Browse files Browse the repository at this point in the history
It makes more sense structurally when we later introduce SyntaxToDependents.
  • Loading branch information
Enselic committed Sep 20, 2021
1 parent 5897956 commit 50e6b06
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/assets/build_assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ use crate::assets::*;

type SyntaxName = String;

/// Used to look up what dependencies a given [SyntaxDefinition] has
type SyntaxToDependencies = HashMap<SyntaxName, Vec<OtherSyntax>>;

/// Used to look up which [SyntaxDefinition] corresponds to a given [OtherSyntax]
type OtherSyntaxLookup<'a> = HashMap<OtherSyntax, &'a SyntaxDefinition>;

/// Used to look up what dependencies a given [SyntaxDefinition] has
type SyntaxToDependencies = HashMap<SyntaxName, Vec<OtherSyntax>>;

/// Represents some other `*.sublime-syntax` file, i.e. another [SyntaxDefinition].
#[derive(Debug, Eq, PartialEq, Clone, Hash)]
enum OtherSyntax {
Expand Down Expand Up @@ -215,7 +215,7 @@ fn build_minimal_syntax_sets(
let syntaxes = syntax_set_builder.syntaxes();

// Build the data structures we need for dependency resolution
let (syntax_to_dependencies, other_syntax_lookup) = generate_maps(syntaxes);
let (other_syntax_lookup, syntax_to_dependencies) = generate_maps(syntaxes);

// Create one minimal SyntaxSet from each (non-hidden) SyntaxDefinition
syntaxes.iter().filter_map(move |syntax| {
Expand All @@ -224,7 +224,7 @@ fn build_minimal_syntax_sets(
}

let mut builder = SyntaxSetDependencyBuilder::new();
builder.add_with_dependencies(syntax, &syntax_to_dependencies, &other_syntax_lookup);
builder.add_with_dependencies(syntax, &other_syntax_lookup, &syntax_to_dependencies);
let syntax_set = builder.build();

if std::env::var("BAT_PRINT_SYNTAX_DEPENDENCIES").is_ok() {
Expand All @@ -241,9 +241,9 @@ fn build_minimal_syntax_sets(
/// First, when we have a [OtherSyntax], we need to know what [SyntaxDefinition] that
/// corresponds to. Second, when we have a [SyntaxDefinition], we need to know
/// what dependencies it has. This functions generates that data for each syntax.
fn generate_maps(syntaxes: &[SyntaxDefinition]) -> (SyntaxToDependencies, OtherSyntaxLookup) {
let mut syntax_to_dependencies = HashMap::new();
fn generate_maps(syntaxes: &[SyntaxDefinition]) -> (OtherSyntaxLookup, SyntaxToDependencies) {
let mut other_syntax_lookup = HashMap::new();
let mut syntax_to_dependencies = HashMap::new();

for syntax in syntaxes {
syntax_to_dependencies.insert(syntax.name.clone(), dependencies_for_syntax(syntax));
Expand All @@ -252,7 +252,7 @@ fn generate_maps(syntaxes: &[SyntaxDefinition]) -> (SyntaxToDependencies, OtherS
other_syntax_lookup.insert(OtherSyntax::ByScope(syntax.scope), syntax);
}

(syntax_to_dependencies, other_syntax_lookup)
(other_syntax_lookup, syntax_to_dependencies)
}

/// Gets what external dependencies a given [SyntaxDefinition] has.
Expand Down Expand Up @@ -320,8 +320,8 @@ impl SyntaxSetDependencyBuilder {
fn add_with_dependencies(
&mut self,
syntax: &SyntaxDefinition,
syntax_to_dependencies: &SyntaxToDependencies,
other_syntax_lookup: &OtherSyntaxLookup,
syntax_to_dependencies: &SyntaxToDependencies,
) {
let name = &syntax.name;
if self.is_syntax_already_added(name) {
Expand All @@ -340,8 +340,8 @@ impl SyntaxSetDependencyBuilder {
if let Some(syntax_definition_dependency) = other_syntax_lookup.get(dependency) {
self.add_with_dependencies(
syntax_definition_dependency,
syntax_to_dependencies,
other_syntax_lookup,
syntax_to_dependencies,
)
}
}
Expand Down

0 comments on commit 50e6b06

Please sign in to comment.