query: Don't attempt to match top-level sibling patterns directly in ERROR nodes
Co-authored-by: Keith Simmons <keith@zed.dev>
This commit is contained in:
parent
01df16ca9f
commit
1401767689
2 changed files with 45 additions and 2 deletions
|
|
@ -1687,6 +1687,43 @@ fn test_query_matches_with_too_many_permutations_to_track() {
|
|||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_query_sibling_patterns_dont_match_children_of_an_error() {
|
||||
allocations::record(|| {
|
||||
let language = get_language("rust");
|
||||
let query = Query::new(
|
||||
language,
|
||||
r#"
|
||||
("{" @open "}" @close)
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let source = "
|
||||
fn a() {}
|
||||
|
||||
<<<<<<<<<< add pub b fn () {}
|
||||
pub fn b() {
|
||||
==========
|
||||
pub fn c() {
|
||||
>>>>>>>>>> add pub c fn () {}
|
||||
}
|
||||
";
|
||||
|
||||
let mut parser = Parser::new();
|
||||
parser.set_language(language).unwrap();
|
||||
|
||||
let tree = parser.parse(&source, None).unwrap();
|
||||
|
||||
let mut cursor = QueryCursor::new();
|
||||
let matches = cursor.matches(&query, tree.root_node(), source.as_bytes());
|
||||
assert_eq!(
|
||||
collect_matches(matches, &query, source),
|
||||
&[(0, vec![("open", "{"), ("close", "}")])],
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_query_matches_with_alternatives_and_too_many_permutations_to_track() {
|
||||
allocations::record(|| {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue