Skip to content

Commit a50d8ad

Browse files
authored
Work around tree-sitter query search bug (#1800)
- Fixes #1609 - Required by / tested by #1448 ## Checklist - [ ] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [ ] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [ ] I have not broken the cheatsheet
1 parent 8c9cfc3 commit a50d8ad

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

packages/cursorless-engine/src/languages/TreeSitterQuery/TreeSitterQuery.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ export class TreeSitterQuery {
6363

6464
matches(
6565
document: TextDocument,
66-
start: Position,
67-
end: Position,
66+
start?: Position,
67+
end?: Position,
6868
): QueryMatch[] {
6969
return this.query
7070
.matches(
7171
this.treeSitter.getTree(document).rootNode,
72-
positionToPoint(start),
73-
positionToPoint(end),
72+
start == null ? undefined : positionToPoint(start),
73+
end == null ? undefined : positionToPoint(end),
7474
)
7575
.map(
7676
({ pattern, captures }): MutableQueryMatch => ({

packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/TreeSitterScopeHandler/BaseTreeSitterScopeHandler.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,18 @@ export abstract class BaseTreeSitterScopeHandler extends BaseScopeHandler {
2626
editor: TextEditor,
2727
position: Position,
2828
direction: Direction,
29-
hints: ScopeIteratorRequirements,
29+
_hints: ScopeIteratorRequirements,
3030
): Iterable<TargetScope> {
3131
const { document } = editor;
3232

33-
/** Narrow the range within which tree-sitter searches, for performance */
34-
const { start, end } = getQuerySearchRange(
35-
document,
36-
position,
37-
direction,
38-
hints,
39-
);
33+
// Due to a tree-sitter bug, we generate all scopes from the entire file
34+
// instead of using `_hints` to restrict the search range to scopes we care
35+
// about. The actual scopes yielded to the client are filtered by
36+
// `BaseScopeHandler` anyway, so there's no impact on correctness, just
37+
// performance. We'd like to roll this back; see #1769.
4038

4139
const scopes = this.query
42-
.matches(document, start, end)
40+
.matches(document)
4341
.map((match) => this.matchToScope(editor, match))
4442
.filter((scope): scope is ExtendedTargetScope => scope != null)
4543
.sort((a, b) => compareTargetScopes(direction, position, a, b));

0 commit comments

Comments
 (0)