Skip to content

Commit 9b32ce9

Browse files
committed
refactor
1 parent d7b9372 commit 9b32ce9

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

highlighter/src/injections_query.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ pub struct InjectionsQuery {
8989
injection_language_capture: Option<Capture>,
9090
injection_filename_capture: Option<Capture>,
9191
injection_shebang_capture: Option<Capture>,
92-
injection_parent_layer_langs_predicate: Option<Vec<String>>,
93-
injection_parent_layer_langs_predicate_negated: bool,
92+
/// 1. The list of matches to compare the parent layer's language
93+
/// 1. Whether it is negated: `#any-of` or `#not-any-of?`
94+
injection_parent_layer_langs_predicate: Option<(Vec<String>, bool)>,
9495
// Note that the injections query is concatenated with the locals query.
9596
pub(crate) local_query: Query,
9697
// TODO: Use a Vec<bool> instead?
@@ -111,7 +112,6 @@ impl InjectionsQuery {
111112
query_source.push_str(local_query_text);
112113

113114
let mut injection_parent_layer_langs_predicate = None;
114-
let mut injection_parent_layer_langs_predicate_negated = false;
115115

116116
let mut injection_properties: HashMap<Pattern, InjectionProperties> = HashMap::new();
117117
let mut not_scope_inherits = HashSet::new();
@@ -134,9 +134,8 @@ impl InjectionsQuery {
134134
value: INJECTION_PARENT_LAYER,
135135
values,
136136
} => {
137-
injection_parent_layer_langs_predicate_negated = negated;
138137
injection_parent_layer_langs_predicate =
139-
Some(values.into_iter().map(ToOwned::to_owned).collect());
138+
Some((values.into_iter().map(ToOwned::to_owned).collect(), negated));
140139
}
141140
UserPredicate::SetProperty {
142141
key: "injection.include-children",
@@ -184,7 +183,6 @@ impl InjectionsQuery {
184183

185184
Ok(InjectionsQuery {
186185
injection_parent_layer_langs_predicate,
187-
injection_parent_layer_langs_predicate_negated,
188186
injection_properties,
189187
injection_content_capture: injection_query.get_capture("injection.content"),
190188
injection_language_capture: injection_query.get_capture("injection.language"),
@@ -271,15 +269,15 @@ impl InjectionsQuery {
271269
let matches_predicate = || {
272270
self.injection_parent_layer_langs_predicate
273271
.as_ref()
274-
.is_none_or(|predicate| {
272+
.is_none_or(|(predicate, is_negated)| {
275273
predicate.iter().any(|capture| {
276274
let Some(marker) = loader.language_for_marker(
277275
InjectionLanguageMarker::Name(capture),
278276
) else {
279277
return false;
280278
};
281279

282-
if self.injection_parent_layer_langs_predicate_negated {
280+
if *is_negated {
283281
marker != injection_parent_language
284282
} else {
285283
marker == injection_parent_language

0 commit comments

Comments
 (0)