on master help sign in
build_assets.rs: Make OtherSyntaxLookup come before SyntaxToDependencies

It makes more sense structurally when we later introduce SyntaxToDependents.

commita6dc25a2169432245edf2d62472a34e2193a55ae authorMartin Nordholts <enselic@gmail.com> dateMon 20 Sep 2021, 20:35 (5 years ago) parentf04d2a9
1 file changed+10−10
src/assets/build_assets.rs+10−10
src/assets/build_assets.rs+10−10
@@ -10,12 +10,12 @@ use crate::assets::*;
1010
1111type SyntaxName = String;
1212
13−/// Used to look up what dependencies a given [SyntaxDefinition] has
14−type SyntaxToDependencies = HashMap<SyntaxName, Vec<OtherSyntax>>;
15−
1613/// Used to look up which [SyntaxDefinition] corresponds to a given [OtherSyntax]
1714type OtherSyntaxLookup<'a> = HashMap<OtherSyntax, &'a SyntaxDefinition>;
1815
16+/// Used to look up what dependencies a given [SyntaxDefinition] has
17+type SyntaxToDependencies = HashMap<SyntaxName, Vec<OtherSyntax>>;
18+
1919/// Represents some other `*.sublime-syntax` file, i.e. another [SyntaxDefinition].
2020#[derive(Debug, Eq, PartialEq, Clone, Hash)]
2121enum OtherSyntax {
@@ -215,7 +215,7 @@ fn build_minimal_syntax_sets(
215215 let syntaxes = syntax_set_builder.syntaxes();
216216
217217 // Build the data structures we need for dependency resolution
218− let (syntax_to_dependencies, other_syntax_lookup) = generate_maps(syntaxes);
218+ let (other_syntax_lookup, syntax_to_dependencies) = generate_maps(syntaxes);
219219
220220 // Create one minimal SyntaxSet from each (non-hidden) SyntaxDefinition
221221 syntaxes.iter().filter_map(move |syntax| {
@@ -224,7 +224,7 @@ fn build_minimal_syntax_sets(
224224 }
225225
226226 let mut builder = SyntaxSetDependencyBuilder::new();
227− builder.add_with_dependencies(syntax, &syntax_to_dependencies, &other_syntax_lookup);
227+ builder.add_with_dependencies(syntax, &other_syntax_lookup, &syntax_to_dependencies);
228228 let syntax_set = builder.build();
229229
230230 if std::env::var("BAT_PRINT_SYNTAX_DEPENDENCIES").is_ok() {
@@ -241,9 +241,9 @@ fn build_minimal_syntax_sets(
241241/// First, when we have a [OtherSyntax], we need to know what [SyntaxDefinition] that
242242/// corresponds to. Second, when we have a [SyntaxDefinition], we need to know
243243/// what dependencies it has. This functions generates that data for each syntax.
244−fn generate_maps(syntaxes: &[SyntaxDefinition]) -> (SyntaxToDependencies, OtherSyntaxLookup) {
245− let mut syntax_to_dependencies = HashMap::new();
244+fn generate_maps(syntaxes: &[SyntaxDefinition]) -> (OtherSyntaxLookup, SyntaxToDependencies) {
246245 let mut other_syntax_lookup = HashMap::new();
246+ let mut syntax_to_dependencies = HashMap::new();
247247
248248 for syntax in syntaxes {
249249 syntax_to_dependencies.insert(syntax.name.clone(), dependencies_for_syntax(syntax));
@@ -252,7 +252,7 @@ fn generate_maps(syntaxes: &[SyntaxDefinition]) -> (SyntaxToDependencies, OtherS
252252 other_syntax_lookup.insert(OtherSyntax::ByScope(syntax.scope), syntax);
253253 }
254254
255− (syntax_to_dependencies, other_syntax_lookup)
255+ (other_syntax_lookup, syntax_to_dependencies)
256256}
257257
258258/// Gets what external dependencies a given [SyntaxDefinition] has.
@@ -320,8 +320,8 @@ impl SyntaxSetDependencyBuilder {
320320 fn add_with_dependencies(
321321 &mut self,
322322 syntax: &SyntaxDefinition,
323− syntax_to_dependencies: &SyntaxToDependencies,
324323 other_syntax_lookup: &OtherSyntaxLookup,
324+ syntax_to_dependencies: &SyntaxToDependencies,
325325 ) {
326326 let name = &syntax.name;
327327 if self.is_syntax_already_added(name) {
@@ -340,8 +340,8 @@ impl SyntaxSetDependencyBuilder {
340340 if let Some(syntax_definition_dependency) = other_syntax_lookup.get(dependency) {
341341 self.add_with_dependencies(
342342 syntax_definition_dependency,
343− syntax_to_dependencies,
344343 other_syntax_lookup,
344+ syntax_to_dependencies,
345345 )
346346 }
347347 }