Skip to content

Commit 6474a91

Browse files
Clean up
1 parent d8d44ed commit 6474a91

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/SurroundingPairScopeHandler/getDelimiterOccurrences.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { matchAllIterator, Range, type TextDocument } from "@cursorless/common";
1+
import {
2+
matchAllIterator,
3+
Range,
4+
type SimpleScopeTypeType,
5+
type TextDocument,
6+
} from "@cursorless/common";
27
import type { LanguageDefinition } from "../../../../languages/LanguageDefinition";
38
import type { QueryCapture } from "../../../../languages/TreeSitterQuery/QueryCapture";
49
import { createRangeTree } from "./createRangeTree";
@@ -24,15 +29,12 @@ export function getDelimiterOccurrences(
2429
}
2530

2631
const disqualifyDelimiters = new RangeIterator(
27-
getSortedCaptures(
28-
languageDefinition?.getCaptures(document, "disqualifyDelimiter"),
29-
),
32+
getSortedCaptures(languageDefinition, document, "disqualifyDelimiter"),
3033
);
3134
const textFragments = new RangeIterator(
35+
// We need to create a tree for text fragments since they can be nested
3236
createRangeTree(
33-
getSortedCaptures(
34-
languageDefinition?.getCaptures(document, "textFragment"),
35-
),
37+
getSortedCaptures(languageDefinition, document, "textFragment"),
3638
),
3739
);
3840

@@ -76,9 +78,11 @@ export function getDelimiterOccurrences(
7678
}
7779

7880
function getSortedCaptures(
79-
captures: QueryCapture[] | undefined,
81+
languageDefinition: LanguageDefinition | undefined,
82+
document: TextDocument,
83+
captureName: SimpleScopeTypeType,
8084
): QueryCapture[] {
81-
const items = captures ?? [];
85+
const items = languageDefinition?.getCaptures(document, captureName) ?? [];
8286
items.sort((a, b) => a.range.start.compareTo(b.range.start));
8387
return items;
8488
}

0 commit comments

Comments
 (0)