mirror of https://github.com/helix-editor/helix
Allow multiple `#not-kind-eq?` predicates in indent queries
This fixes a regression from the switch to tree-house with one of the custom predicates in indent queries: `#not-kind-eq?`. This predicate should be allowed to be written multiple times in a pattern. For example in the Go indents: ; Switches and selects aren't indented, only their case bodies are. ; Outdent all closing braces except those closing switches or selects. ( (_ "}" @outdent) @outer (#not-kind-eq? @outer "select_statement") (#not-kind-eq? @outer "type_switch_statement") (#not-kind-eq? @outer "expression_switch_statement") ) So instead of an `Option<T>` of one we need a `Vec<T>` and we need to check that all of these predicates are individually satisfied (basically `iter().all(/* node kind is not expected kind for that capture */)`).pull/13675/merge
parent
25b299abc5
commit
b1f4717356
|
@ -297,7 +297,7 @@ fn is_first_in_line(node: &Node, text: RopeSlice, new_line_byte_pos: Option<u32>
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct IndentQueryPredicates {
|
pub struct IndentQueryPredicates {
|
||||||
not_kind_eq: Option<(Capture, Box<str>)>,
|
not_kind_eq: Vec<(Capture, Box<str>)>,
|
||||||
same_line: Option<(Capture, Capture, bool)>,
|
same_line: Option<(Capture, Capture, bool)>,
|
||||||
one_line: Option<(Capture, bool)>,
|
one_line: Option<(Capture, bool)>,
|
||||||
}
|
}
|
||||||
|
@ -309,12 +309,9 @@ impl IndentQueryPredicates {
|
||||||
text: RopeSlice,
|
text: RopeSlice,
|
||||||
new_line_byte_pos: Option<u32>,
|
new_line_byte_pos: Option<u32>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if let Some((capture, not_expected_kind)) = self.not_kind_eq.as_ref() {
|
for (capture, not_expected_kind) in self.not_kind_eq.iter() {
|
||||||
if !match_
|
let node = match_.nodes_for_capture(*capture).next();
|
||||||
.nodes_for_capture(*capture)
|
if node.is_some_and(|n| n.kind() == not_expected_kind.as_ref()) {
|
||||||
.next()
|
|
||||||
.is_some_and(|node| node.kind() != not_expected_kind.as_ref())
|
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -394,8 +391,11 @@ impl IndentQuery {
|
||||||
let capture = predicate.capture_arg(0)?;
|
let capture = predicate.capture_arg(0)?;
|
||||||
let not_expected_kind = predicate.str_arg(1)?;
|
let not_expected_kind = predicate.str_arg(1)?;
|
||||||
|
|
||||||
predicates.entry(pattern).or_default().not_kind_eq =
|
predicates
|
||||||
Some((capture, not_expected_kind.to_string().into_boxed_str()));
|
.entry(pattern)
|
||||||
|
.or_default()
|
||||||
|
.not_kind_eq
|
||||||
|
.push((capture, not_expected_kind.into()));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
"same-line?" | "not-same-line?" => {
|
"same-line?" | "not-same-line?" => {
|
||||||
|
|
Loading…
Reference in New Issue