mirror of
https://github.com/zed-industries/zed.git
synced 2026-11-19 23:20:18 +01:00
language: Reset max start depth on pooled query cursors (#66983)
## Summary `QueryCursorHandle` returns its cursor to a shared pool on drop. It reset the cursor's byte and point ranges but not `max_start_depth`, and tree-sitter keeps that setting across executions. Only `SyntaxMapMatches` sets a depth, and it sets one on every query. The other pool users never set it: highlight captures, injection queries, `SyntaxLayer::override_id`, and `with_query_cursor`. After a depth-limited matches query, the next of those to take the same cursor matched only nodes within that depth. `Drop` now clears it. The depth-limited queries are the text object queries behind Vim's method, section, and comment motions (`] m`, `] ]`, `] /`), with depths of 3 to 6. Missing highlights after those motions are inferred from the code; only the syntax map is tested. ## Testing `cargo test -p language --lib` passes. `test_max_start_depth_does_not_carry_over_to_later_queries` is new and fails without the fix. ## Self-review - [x] I've reviewed my diff for quality, security, reliability, and performance. - [x] UI changes follow the [checklist](https://zed.dev/docs/development/ui-checklist). - [x] Tests cover the new or changed behavior. Release Notes: - Fixed syntax highlighting sometimes going missing after Vim method, section, and comment motions
This commit is contained in:
@@ -2274,6 +2274,7 @@ impl Drop for QueryCursorHandle {
|
||||
cursor.set_point_range(Point::zero().to_ts_point()..Point::MAX.to_ts_point());
|
||||
cursor.set_containing_byte_range(0..usize::MAX);
|
||||
cursor.set_containing_point_range(Point::zero().to_ts_point()..Point::MAX.to_ts_point());
|
||||
cursor.set_max_start_depth(None);
|
||||
QUERY_CURSORS.lock().push(cursor)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1385,6 +1385,34 @@ fn test_injection_grouped_by_host(cx: &mut App) {
|
||||
}
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_max_start_depth_does_not_carry_over_to_later_queries(cx: &mut App) {
|
||||
fn highlights_query(grammar: &Grammar) -> Option<&Query> {
|
||||
grammar
|
||||
.highlights_config
|
||||
.as_ref()
|
||||
.map(|config| &config.query)
|
||||
}
|
||||
|
||||
let (buffer, syntax_map) = test_edit_sequence("Rust", &["fn a() { b(c); }"], cx);
|
||||
let capture_count = || {
|
||||
syntax_map
|
||||
.captures(0..buffer.len(), &buffer, highlights_query)
|
||||
.count()
|
||||
};
|
||||
|
||||
let expected_capture_count = capture_count();
|
||||
assert!(expected_capture_count > 0);
|
||||
|
||||
drop(syntax_map.matches_with_options(
|
||||
0..buffer.len(),
|
||||
&buffer,
|
||||
TreeSitterOptions::max_start_depth(1),
|
||||
highlights_query,
|
||||
));
|
||||
assert_eq!(capture_count(), expected_capture_count);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_syntax_map_languages_loading_with_erb(cx: &mut App) {
|
||||
let text = r#"
|
||||
|
||||
Reference in New Issue
Block a user