1
>
/*---------------------------------------------------------------------------------------------
searchExtTypes.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { CancellationToken } from '../../../../base/common/cancellation.js';
7
>
import { URI } from '../../../../base/common/uri.js';
8
>
import { IProgress } from '../../../../platform/progress/common/progress.js';
9
>
10
>
export class Position {
11
>
constructor(readonly line: number, readonly character: number) { }
12
>
13
>
isBefore(other: Position): boolean { return false; }
14
>
isBeforeOrEqual(other: Position): boolean { return false; }
15
>
isAfter(other: Position): boolean { return false; }
16
>
isAfterOrEqual(other: Position): boolean { return false; }
17
>
isEqual(other: Position): boolean { return false; }
18
>
compareTo(other: Position): number { return 0; }
19
>
translate(lineDelta?: number, characterDelta?: number): Position;
20
>
translate(change: { lineDelta?: number; characterDelta?: number }): Position;
21
>
translate(_?: any, _2?: any): Position { return new Position(0, 0); }
22
>
with(line?: number, character?: number): Position;
23
>
with(change: { line?: number; character?: number }): Position;
24
>
with(_: any): Position { return new Position(0, 0); }
25
>
}
26
>
27
>
export class Range {
28
>
readonly start: Position;
29
>
readonly end: Position;
30
>
31
>
constructor(startLine: number, startCol: number, endLine: number, endCol: number) {
32
this.start = new Position(startLine, startCol);
33
this.end = new Position(endLine, endCol);
34
}
36
>
isEmpty = false;
37
>
isSingleLine = false;
38
>
contains(positionOrRange: Position | Range): boolean { return false; }
39
>
isEqual(other: Range): boolean { return false; }
40
>
intersection(range: Range): Range | undefined { return undefined; }
41
>
union(other: Range): Range { return new Range(0, 0, 0, 0); }
42
>
43
>
with(start?: Position, end?: Position): Range;
44
>
with(change: { start?: Position; end?: Position }): Range;
45
>
with(_: any): Range { return new Range(0, 0, 0, 0); }
46
>
}
47
>
48
>
export type ProviderResult<T> = T | undefined | null | Thenable<T | undefined | null>;
49
>
50
>
/**
51
>
* A relative pattern is a helper to construct glob patterns that are matched
52
>
* relatively to a base path. The base path can either be an absolute file path
53
>
* or a [workspace folder](#WorkspaceFolder).
54
>
*/
55
>
export interface RelativePattern {
56
>
57
>
/**
58
>
* A base file path to which this pattern will be matched against relatively. The
59
>
* file path must be absolute, should not have any trailing path separators and
60
>
* not include any relative segments (`.` or `..`).
61
>
*/
62
>
baseUri: URI;
63
>
64
>
/**
65
>
* A file glob pattern like `*.{ts,js}` that will be matched on file paths
66
>
* relative to the base path.
67
>
*
68
>
* Example: Given a base of `/home/work/folder` and a file path of `/home/work/folder/index.js`,
69
>
* the file glob pattern will match on `index.js`.
70
>
*/
71
>
pattern: string;
72
>
}
73
>
74
>
/**
75
>
* A file glob pattern to match file paths against. This can either be a glob pattern string
76
>
* (like `** /*.{ts,js}` without space before / or `*.{ts,js}`) or a [relative pattern](#RelativePattern).
77
>
*
78
>
* Glob patterns can have the following syntax:
79
>
* * `*` to match zero or more characters in a path segment
80
>
* * `?` to match on one character in a path segment
81
>
* * `**` to match any number of path segments, including none
82
>
* * `{}` to group conditions (e.g. `** /*.{ts,js}` without space before / matches all TypeScript and JavaScript files)
83
>
* * `[]` to declare a range of characters to match in a path segment (e.g., `example.[0-9]` to match on `example.0`, `example.1`, …)
84
>
* * `[!...]` to negate a range of characters to match in a path segment (e.g., `example.[!0-9]` to match on `example.a`, `example.b`, but not `example.0`)
85
>
*
86
>
* Note: a backslash (`\`) is not valid within a glob pattern. If you have an existing file
87
>
* path to match against, consider to use the [relative pattern](#RelativePattern) support
88
>
* that takes care of converting any backslash into slash. Otherwise, make sure to convert
89
>
* any backslash to slash when creating the glob pattern.
90
>
*/
91
>
export type GlobPattern = string | RelativePattern;
92
>
93
>
/**
94
>
* The parameters of a query for text search.
95
>
*/
96
>
export interface TextSearchQuery2 {
97
>
/**
98
>
* The text pattern to search for.
99
>
*/
100
>
pattern: string;
101
>
102
>
/**
103
>
* Whether or not `pattern` should match multiple lines of text.
104
>
*/
105
>
isMultiline?: boolean;
106
>
107
>
/**
108
>
* Whether or not `pattern` should be interpreted as a regular expression.
109
>
*/
110
>
isRegExp?: boolean;
111
>
112
>
/**
113
>
* Whether or not the search should be case-sensitive.
114
>
*/
115
>
isCaseSensitive?: boolean;
116
>
117
>
/**
118
>
* Whether or not to search for whole word matches only.
119
>
*/
120
>
isWordMatch?: boolean;
121
>
}
122
>
123
>
124
>
export interface TextSearchProviderFolderOptions {
125
>
/**
126
>
* The root folder to search within.
127
>
*/
128
>
folder: URI;
129
>
130
>
/**
131
>
* Files that match an `includes` glob pattern should be included in the search.
132
>
*/
133
>
includes: string[];
134
>
135
>
/**
136
>
* Files that match an `excludes` glob pattern should be excluded from the search.
137
>
*/
138
>
excludes: GlobPattern[];
139
>
140
>
/**
141
>
* Whether to ignore case for glob patterns.
142
>
*/
143
>
ignoreGlobCase?: boolean;
144
>
145
>
/**
146
>
* Whether symlinks should be followed while searching.
147
>
* For more info, see the setting description for `search.followSymlinks`.
148
>
*/
149
>
followSymlinks: boolean;
150
>
151
>
/**
152
>
* Which file locations we should look for ignore (.gitignore or .ignore) files to respect.
153
>
*/
154
>
useIgnoreFiles: {
155
>
/**
156
>
* Use ignore files at the current workspace root.
157
>
*/
158
>
local: boolean;
159
>
/**
160
>
* Use ignore files at the parent directory. If set, `local` in {@link TextSearchProviderFolderOptions.useIgnoreFiles} should also be `true`.
161
>
*/
162
>
parent: boolean;
163
>
/**
164
>
* Use global ignore files. If set, `local` in {@link TextSearchProviderFolderOptions.useIgnoreFiles} should also be `true`.
165
>
*/
166
>
global: boolean;
167
>
};
168
>
169
>
/**
170
>
* Interpret files using this encoding.
171
>
* See the vscode setting `"files.encoding"`
172
>
*/
173
>
encoding: string;
174
>
}
175
>
176
>
/**
177
>
* Options that apply to text search.
178
>
*/
179
>
export interface TextSearchProviderOptions {
180
>
181
>
folderOptions: TextSearchProviderFolderOptions[];
182
>
183
>
/**
184
>
* The maximum number of results to be returned.
185
>
*/
186
>
maxResults: number;
187
>
188
>
/**
189
>
* Options to specify the size of the result text preview.
190
>
*/
191
>
previewOptions: {
192
>
/**
193
>
* The maximum number of lines in the preview.
194
>
* Only search providers that support multiline search will ever return more than one line in the match.
195
>
* Defaults to 100.
196
>
*/
197
>
matchLines: number;
198
>
199
>
/**
200
>
* The maximum number of characters included per line.
201
>
* Defaults to 10000.
202
>
*/
203
>
charsPerLine: number;
204
>
};
205
>
206
>
/**
207
>
* Exclude files larger than `maxFileSize` in bytes.
208
>
*/
209
>
maxFileSize: number | undefined;
210
>
211
>
212
>
/**
213
>
* Number of lines of context to include before and after each match.
214
>
*/
215
>
surroundingContext: number;
216
>
}
217
>
218
>
219
>
/**
220
>
* Information collected when text search is complete.
221
>
*/
222
>
export interface TextSearchComplete2 {
223
>
/**
224
>
* Whether the search hit the limit on the maximum number of search results.
225
>
* `maxResults` on [`TextSearchOptions`](#TextSearchOptions) specifies the max number of results.
226
>
* - If exactly that number of matches exist, this should be false.
227
>
* - If `maxResults` matches are returned and more exist, this should be true.
228
>
* - If search hits an internal limit which is less than `maxResults`, this should be true.
229
>
*/
230
>
limitHit?: boolean;
231
>
}
232
>
233
>
export interface FileSearchProviderFolderOptions {
234
>
/**
235
>
* The root folder to search within.
236
>
*/
237
>
folder: URI;
238
>
239
>
/**
240
>
* Files that match an `includes` glob pattern should be included in the search.
241
>
*/
242
>
includes: string[];
243
>
244
>
/**
245
>
* Files that match an `excludes` glob pattern should be excluded from the search.
246
>
*/
247
>
excludes: GlobPattern[];
248
>
249
>
/**
250
>
* Whether symlinks should be followed while searching.
251
>
* For more info, see the setting description for `search.followSymlinks`.
252
>
*/
253
>
followSymlinks: boolean;
254
>
255
>
/**
256
>
* Which file locations we should look for ignore (.gitignore or .ignore) files to respect.
257
>
*/
258
>
useIgnoreFiles: {
259
>
/**
260
>
* Use ignore files at the current workspace root.
261
>
*/
262
>
local: boolean;
263
>
/**
264
>
* Use ignore files at the parent directory. If set, {@link FileSearchProviderOptions.useIgnoreFiles.local} should also be `true`.
265
>
*/
266
>
parent: boolean;
267
>
/**
268
>
* Use global ignore files. If set, {@link FileSearchProviderOptions.useIgnoreFiles.local} should also be `true`.
269
>
*/
270
>
global: boolean;
271
>
};
272
>
}
273
>
274
>
/**
275
>
* Options that apply to file search.
276
>
*/
277
>
export interface FileSearchProviderOptions {
278
>
folderOptions: FileSearchProviderFolderOptions[];
279
>
280
>
/**
281
>
* An object with a lifespan that matches the session's lifespan. If the provider chooses to, this object can be used as the key for a cache,
282
>
* and searches with the same session object can search the same cache. When the token is cancelled, the session is complete and the cache can be cleared.
283
>
*/
284
>
session: unknown;
285
>
286
>
/**
287
>
* The maximum number of results to be returned.
288
>
*/
289
>
maxResults: number;
290
>
}
291
>
292
>
/**
293
>
* The main match information for a {@link TextSearchResult2}.
294
>
*/
295
>
export class TextSearchMatch2 {
296
>
/**
297
>
* @param uri The uri for the matching document.
298
>
* @param ranges The ranges associated with this match.
299
>
* @param previewText The text that is used to preview the match. The highlighted range in `previewText` is specified in `ranges`.
300
>
*/
301
>
constructor(
302
public uri: URI,
303
public ranges: { sourceRange: Range; previewRange: Range }[],
304
public previewText: string) { }
306
>
}
307
>
308
>
/**
309
>
* The potential context information for a {@link TextSearchResult2}.
310
>
*/
311
>
export class TextSearchContext2 {
312
>
/**
313
>
* @param uri The uri for the matching document.
314
>
* @param text The line of context text.
315
>
* @param lineNumber The line number of this line of context.
316
>
*/
317
>
constructor(
318
public uri: URI,
319
public text: string,
320
public lineNumber: number) { }
322
>
323
>
/**
324
>
/**
325
>
* Keyword suggestion for AI search.
326
>
*/
327
>
export class AISearchKeyword {
328
>
/**
329
>
* @param keyword The keyword associated with the search.
330
>
*/
331
>
constructor(public keyword: string) { }
332
>
}
333
>
334
>
/**
335
>
* A result payload for a text search, pertaining to matches within a single file.
336
>
*/
337
>
export type TextSearchResult2 = TextSearchMatch2 | TextSearchContext2;
338
>
339
>
/**
340
>
* A result payload for an AI search.
341
>
* This can be a {@link TextSearchMatch2 match} or a {@link AISearchKeyword keyword}.
342
>
* The result can be a match or a keyword.
343
>
*/
344
>
export type AISearchResult = TextSearchResult2 | AISearchKeyword;
345
>
346
>
/**
347
>
* A FileSearchProvider provides search results for files in the given folder that match a query string. It can be invoked by quickaccess or other extensions.
348
>
*
349
>
* A FileSearchProvider is the more powerful of two ways to implement file search in VS Code. Use a FileSearchProvider if you wish to search within a folder for
350
>
* all files that match the user's query.
351
>
*
352
>
* The FileSearchProvider will be invoked on every keypress in quickaccess. When `workspace.findFiles` is called, it will be invoked with an empty query string,
353
>
* and in that case, every file in the folder should be returned.
354
>
*/
355
>
export interface FileSearchProvider2 {
356
>
/**
357
>
* Provide the set of files that match a certain file path pattern.
358
>
* @param query The parameters for this query.
359
>
* @param options A set of options to consider while searching files.
360
>
* @param progress A progress callback that must be invoked for all results.
361
>
* @param token A cancellation token.
362
>
*/
363
>
provideFileSearchResults(pattern: string, options: FileSearchProviderOptions, token: CancellationToken): ProviderResult<URI[]>;
364
>
}
365
>
366
>
/**
367
>
* A TextSearchProvider provides search results for text results inside files in the workspace.
368
>
*/
369
>
export interface TextSearchProvider2 {
370
>
/**
371
>
* Provide results that match the given text pattern.
372
>
* @param query The parameters for this query.
373
>
* @param options A set of options to consider while searching.
374
>
* @param progress A progress callback that must be invoked for all results.
375
>
* @param token A cancellation token.
376
>
*/
377
>
provideTextSearchResults(query: TextSearchQuery2, options: TextSearchProviderOptions, progress: IProgress<TextSearchResult2>, token: CancellationToken): ProviderResult<TextSearchComplete2>;
378
>
}
379
>
380
>
/**
381
>
* Information collected when text search is complete.
382
>
*/
383
>
export interface TextSearchComplete2 {
384
>
/**
385
>
* Whether the search hit the limit on the maximum number of search results.
386
>
* `maxResults` on {@linkcode TextSearchOptions} specifies the max number of results.
387
>
* - If exactly that number of matches exist, this should be false.
388
>
* - If `maxResults` matches are returned and more exist, this should be true.
389
>
* - If search hits an internal limit which is less than `maxResults`, this should be true.
390
>
*/
391
>
limitHit?: boolean;
392
>
393
>
/**
394
>
* Additional information regarding the state of the completed search.
395
>
*
396
>
* Messages with "Information" style support links in markdown syntax:
397
>
* - Click to [run a command](command:workbench.action.OpenQuickPick)
398
>
* - Click to [open a website](https://aka.ms)
399
>
*
400
>
* Commands may optionally return { triggerSearch: true } to signal to the editor that the original search should run be again.
401
>
*/
402
>
message?: TextSearchCompleteMessage2[];
403
>
}
404
>
405
>
/**
406
>
* A message regarding a completed search.
407
>
*/
408
>
export interface TextSearchCompleteMessage2 {
409
>
/**
410
>
* Markdown text of the message.
411
>
*/
412
>
text: string;
413
>
/**
414
>
* Whether the source of the message is trusted, command links are disabled for untrusted message sources.
415
>
* Messaged are untrusted by default.
416
>
*/
417
>
trusted?: boolean;
418
>
/**
419
>
* The message type, this affects how the message will be rendered.
420
>
*/
421
>
type: TextSearchCompleteMessageType;
422
>
}
423
>
424
>
425
>
/**
426
>
* A FileSearchProvider provides search results for files in the given folder that match a query string. It can be invoked by quickaccess or other extensions.
427
>
*
428
>
* A FileSearchProvider is the more powerful of two ways to implement file search in VS Code. Use a FileSearchProvider if you wish to search within a folder for
429
>
* all files that match the user's query.
430
>
*
431
>
* The FileSearchProvider will be invoked on every keypress in quickaccess. When `workspace.findFiles` is called, it will be invoked with an empty query string,
432
>
* and in that case, every file in the folder should be returned.
433
>
*/
434
>
export interface FileSearchProvider2 {
435
>
/**
436
>
* Provide the set of files that match a certain file path pattern.
437
>
* @param query The parameters for this query.
438
>
* @param options A set of options to consider while searching files.
439
>
* @param progress A progress callback that must be invoked for all results.
440
>
* @param token A cancellation token.
441
>
*/
442
>
provideFileSearchResults(pattern: string, options: FileSearchProviderOptions, token: CancellationToken): ProviderResult<URI[]>;
443
>
}
444
>
445
>
/**
446
>
* A TextSearchProvider provides search results for text results inside files in the workspace.
447
>
*/
448
>
export interface TextSearchProvider2 {
449
>
/**
450
>
* Provide results that match the given text pattern.
451
>
* @param query The parameters for this query.
452
>
* @param options A set of options to consider while searching.
453
>
* @param progress A progress callback that must be invoked for all results.
454
>
* @param token A cancellation token.
455
>
*/
456
>
provideTextSearchResults(query: TextSearchQuery2, options: TextSearchProviderOptions, progress: IProgress<TextSearchResult2>, token: CancellationToken): ProviderResult<TextSearchComplete2>;
457
>
}
458
>
459
>
/**
460
>
* Information collected when text search is complete.
461
>
*/
462
>
export interface TextSearchComplete2 {
463
>
/**
464
>
* Whether the search hit the limit on the maximum number of search results.
465
>
* `maxResults` on {@link TextSearchOptions} specifies the max number of results.
466
>
* - If exactly that number of matches exist, this should be false.
467
>
* - If `maxResults` matches are returned and more exist, this should be true.
468
>
* - If search hits an internal limit which is less than `maxResults`, this should be true.
469
>
*/
470
>
limitHit?: boolean;
471
>
472
>
/**
473
>
* Additional information regarding the state of the completed search.
474
>
*
475
>
* Messages with "Information" style support links in markdown syntax:
476
>
* - Click to [run a command](command:workbench.action.OpenQuickPick)
477
>
* - Click to [open a website](https://aka.ms)
478
>
*
479
>
* Commands may optionally return { triggerSearch: true } to signal to the editor that the original search should run be again.
480
>
*/
481
>
message?: TextSearchCompleteMessage2[];
482
>
}
483
>
484
>
/**
485
>
* A message regarding a completed search.
486
>
*/
487
>
export interface TextSearchCompleteMessage2 {
488
>
/**
489
>
* Markdown text of the message.
490
>
*/
491
>
text: string;
492
>
/**
493
>
* Whether the source of the message is trusted, command links are disabled for untrusted message sources.
494
>
* Messaged are untrusted by default.
495
>
*/
496
>
trusted?: boolean;
497
>
/**
498
>
* The message type, this affects how the message will be rendered.
499
>
*/
500
>
type: TextSearchCompleteMessageType;
501
>
}
502
>
503
>
/**
504
>
* Options for following search.exclude and files.exclude settings.
505
>
*/
506
>
export enum ExcludeSettingOptions {
507
>
/*
508
>
* Don't use any exclude settings.
509
>
*/
510
>
None = 1,
511
>
/*
512
>
* Use:
513
>
* - files.exclude setting
514
>
*/
515
>
FilesExclude = 2,
516
>
/*
517
>
* Use:
518
>
* - files.exclude setting
519
>
* - search.exclude setting
520
>
*/
521
>
SearchAndFilesExclude = 3
522
>
}
523
>
524
>
export enum TextSearchCompleteMessageType {
525
>
Information = 1,
526
>
Warning = 2,
527
>
}
528
>
529
>
530
>
/**
531
>
* A message regarding a completed search.
532
>
*/
533
>
export interface TextSearchCompleteMessage {
534
>
/**
535
>
* Markdown text of the message.
536
>
*/
537
>
text: string;
538
>
/**
539
>
* Whether the source of the message is trusted, command links are disabled for untrusted message sources.
540
>
*/
541
>
trusted?: boolean;
542
>
/**
543
>
* The message type, this affects how the message will be rendered.
544
>
*/
545
>
type: TextSearchCompleteMessageType;
546
>
}
547
>
548
>
549
>
/**
550
>
* An AITextSearchProvider provides additional AI text search results in the workspace.
551
>
*/
552
>
export interface AITextSearchProvider {
553
>
554
>
/**
555
>
* The name of the AI searcher. Will be displayed as `{name} Results` in the Search View.
556
>
*/
557
>
readonly name?: string;
558
>
559
>
/**
560
>
* WARNING: VERY EXPERIMENTAL.
561
>
*
562
>
* Provide results that match the given text pattern.
563
>
* @param query The parameter for this query.
564
>
* @param options A set of options to consider while searching.
565
>
* @param progress A progress callback that must be invoked for all results.
566
>
* @param token A cancellation token.
567
>
*/
568
>
provideAITextSearchResults(query: string, options: TextSearchProviderOptions, progress: IProgress<TextSearchResult2>, token: CancellationToken): ProviderResult<TextSearchComplete2>;
569
>
}