Add containing range APIs to query cursor

Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
Co-authored-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
Co-authored-by: dino <dinojoaocosta@gmail.com>
Co-authored-by: John Tur <john-tur@outlook.com>
Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com>
Co-authored-by: dino <dinojoaocosta@gmail.com>
Co-authored-by: Will Lillis <will.lillis24@gmail.com>
This commit is contained in:
Piotr Osiewicz 2025-10-02 19:02:05 +02:00 committed by Will Lillis
parent 7d3feeae9a
commit c0b1710f8a
13 changed files with 420 additions and 34 deletions

View file

@ -20,12 +20,32 @@ export interface QueryOptions {
/** The end position of the range to query */
endPosition?: Point;
/** The start position of the range to query Only the matches that are fully
* contained within provided range will be returned.
**/
startContainingPosition?: Point;
/** The end position of the range to query Only the matches that are fully
* contained within provided range will be returned.
**/
endContainingPosition?: Point;
/** The start index of the range to query */
startIndex?: number;
/** The end index of the range to query */
endIndex?: number;
/** The start index of the range to query Only the matches that are fully
* contained within provided range will be returned.
**/
startContainingIndex?: number;
/** The end index of the range to query Only the matches that are fully
* contained within provided range will be returned.
**/
endContainingIndex?: number;
/**
* The maximum number of in-progress matches for this query.
* The limit must be > 0 and <= 65536.
@ -695,6 +715,10 @@ export class Query {
const endPosition = options.endPosition ?? ZERO_POINT;
const startIndex = options.startIndex ?? 0;
const endIndex = options.endIndex ?? 0;
const startContainingPosition = options.startContainingPosition ?? ZERO_POINT;
const endContainingPosition = options.endContainingPosition ?? ZERO_POINT;
const startContainingIndex = options.startContainingIndex ?? 0;
const endContainingIndex = options.endContainingIndex ?? 0;
const matchLimit = options.matchLimit ?? 0xFFFFFFFF;
const maxStartDepth = options.maxStartDepth ?? 0xFFFFFFFF;
const progressCallback = options.progressCallback;
@ -715,6 +739,18 @@ export class Query {
throw new Error('`startPosition` cannot be greater than `endPosition`');
}
if (endContainingIndex !== 0 && startContainingIndex > endContainingIndex) {
throw new Error('`startContainingIndex` cannot be greater than `endContainingIndex`');
}
if (endContainingPosition !== ZERO_POINT && (
startContainingPosition.row > endContainingPosition.row ||
(startContainingPosition.row === endContainingPosition.row &&
startContainingPosition.column > endContainingPosition.column)
)) {
throw new Error('`startContainingPosition` cannot be greater than `endContainingPosition`');
}
if (progressCallback) {
C.currentQueryProgressCallback = progressCallback;
}
@ -730,6 +766,12 @@ export class Query {
endPosition.column,
startIndex,
endIndex,
startContainingPosition.row,
startContainingPosition.column,
endContainingPosition.row,
endContainingPosition.column,
startContainingIndex,
endContainingIndex,
matchLimit,
maxStartDepth,
);
@ -788,6 +830,10 @@ export class Query {
const endPosition = options.endPosition ?? ZERO_POINT;
const startIndex = options.startIndex ?? 0;
const endIndex = options.endIndex ?? 0;
const startContainingPosition = options.startContainingPosition ?? ZERO_POINT;
const endContainingPosition = options.endContainingPosition ?? ZERO_POINT;
const startContainingIndex = options.startContainingIndex ?? 0;
const endContainingIndex = options.endContainingIndex ?? 0;
const matchLimit = options.matchLimit ?? 0xFFFFFFFF;
const maxStartDepth = options.maxStartDepth ?? 0xFFFFFFFF;
const progressCallback = options.progressCallback;
@ -808,6 +854,18 @@ export class Query {
throw new Error('`startPosition` cannot be greater than `endPosition`');
}
if (endContainingIndex !== 0 && startContainingIndex > endContainingIndex) {
throw new Error('`startContainingIndex` cannot be greater than `endContainingIndex`');
}
if (endContainingPosition !== ZERO_POINT && (
startContainingPosition.row > endContainingPosition.row ||
(startContainingPosition.row === endContainingPosition.row &&
startContainingPosition.column > endContainingPosition.column)
)) {
throw new Error('`startContainingPosition` cannot be greater than `endContainingPosition`');
}
if (progressCallback) {
C.currentQueryProgressCallback = progressCallback;
}
@ -823,6 +881,12 @@ export class Query {
endPosition.column,
startIndex,
endIndex,
startContainingPosition.row,
startContainingPosition.column,
endContainingPosition.row,
endContainingPosition.column,
startContainingIndex,
endContainingIndex,
matchLimit,
maxStartDepth,
);