Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ export class TreeSitterQuery {

matches(
document: TextDocument,
start: Position,
end: Position,
start?: Position,
end?: Position,
): QueryMatch[] {
return this.query
.matches(
this.treeSitter.getTree(document).rootNode,
positionToPoint(start),
positionToPoint(end),
start == null ? undefined : positionToPoint(start),
end == null ? undefined : positionToPoint(end),
)
.map(
({ pattern, captures }): MutableQueryMatch => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,18 @@ export abstract class BaseTreeSitterScopeHandler extends BaseScopeHandler {
editor: TextEditor,
position: Position,
direction: Direction,
hints: ScopeIteratorRequirements,
_hints: ScopeIteratorRequirements,
): Iterable<TargetScope> {
const { document } = editor;

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

const scopes = this.query
.matches(document, start, end)
.matches(document)
.map((match) => this.matchToScope(editor, match))
.filter((scope): scope is ExtendedTargetScope => scope != null)
.sort((a, b) => compareTargetScopes(direction, position, a, b));
Expand Down