textSearchManager.ts ×23

Frontier kind: Code frontier

unlabeled · c_5134d4b2bce2

34 tests · 10221 LOC · 48 files · introduces 0 tests · 124 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
25 ranges124 lines · 2 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1362 ranges10221 lines · 48 files · Browse complete extent
All tests (intent)
34 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

2 files ranked by introduced lines: 124 introduced LOC across 25 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/workbench/services/search/common/textSearchManager.ts 109 introduced LOC · 23 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- textSearchManager.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 { isThenable } from '../../../../base/common/async.js';
7 > import { CancellationToken, CancellationTokenSource } from '../../../../base/common/cancellation.js';
8 > import { toErrorMessage } from '../../../../base/common/errorMessage.js';
9 > import { Schemas } from '../../../../base/common/network.js';
10 > import * as path from '../../../../base/common/path.js';
11 > import * as resources from '../../../../base/common/resources.js';
12 > import { URI } from '../../../../base/common/uri.js';
13 > import { FolderQuerySearchTree } from './folderQuerySearchTree.js';
14 > import { DEFAULT_MAX_SEARCH_RESULTS, hasSiblingPromiseFn, IAITextQuery, IFileMatch, IFolderQuery, excludeToGlobPattern, IPatternInfo, ISearchCompleteStats, ITextQuery, ITextSearchContext, ITextSearchMatch, ITextSearchResult, ITextSearchStats, QueryGlobTester, QueryType, resolvePatternsForProvider, ISearchRange, DEFAULT_TEXT_SEARCH_PREVIEW_OPTIONS } from './search.js';
15 > import { TextSearchComplete2, TextSearchMatch2, TextSearchProviderFolderOptions, TextSearchProvider2, TextSearchProviderOptions, TextSearchQuery2, TextSearchResult2, AITextSearchProvider, AISearchResult, AISearchKeyword } from './searchExtTypes.js';
16 >
17 > export interface IFileUtils {
18 > readdir: (resource: URI) => Promise<string[]>;
19 > toCanonicalName: (encoding: string) => string;
20 > }
21 > interface IAITextQueryProviderPair {
22 > query: IAITextQuery; provider: AITextSearchProvider;
23 > }
24 >
25 > interface ITextQueryProviderPair {
26 > query: ITextQuery; provider: TextSearchProvider2;
27 > }
28 > interface FolderQueryInfo {
29 > queryTester: QueryGlobTester;
30 > folder: URI;
31 > folderIdx: number;
32 > }
33 >
34 > export class TextSearchManager {
35 >
36 > private collector: TextSearchResultsCollector | null = null;
37 >
38 > private isLimitHit = false;
39 > private resultCount = 0;
40 >
41 > constructor(private queryProviderPair: IAITextQueryProviderPair | ITextQueryProviderPair,
42 private fileUtils: IFileUtils,
43 private processType: ITextSearchStats['type']) { }
45 > private get query() {
46 return this.queryProviderPair.query;
47 }
49 > search(onProgress: (matches: IFileMatch[]) => void, token: CancellationToken, onKeywordResult?: (keyword: AISearchKeyword) => void): Promise<ISearchCompleteStats> {
50 const folderQueries = this.query.folderQueries || [];
51 const tokenSource = new CancellationTokenSource(token);
103 });
104 }
106 > private getMessagesFromResults(result: TextSearchComplete2 | null | undefined) {
107 if (!result?.message) { return []; }
108 if (Array.isArray(result.message)) { return result.message; }
109 return [result.message];
110 }
112 > private resultSize(result: TextSearchResult2): number {
113 if (result instanceof TextSearchMatch2) {
114 return Array.isArray(result.ranges) ?
121 }
122 }
124 > private trimResultToSize(result: TextSearchMatch2, size: number): TextSearchMatch2 {
125 return new TextSearchMatch2(result.uri, result.ranges.slice(0, size), result.previewText);
126 }
128 > private async doSearch(folderQueries: IFolderQuery<URI>[], onResult: (result: TextSearchResult2, folderIdx: number) => void, token: CancellationToken, onKeywordResult?: (keyword: AISearchKeyword) => void): Promise<TextSearchComplete2 | null | undefined> {
129 const folderMappings: FolderQuerySearchTree<FolderQueryInfo> = new FolderQuerySearchTree<FolderQueryInfo>(
130 folderQueries,
194 return result;
195 }
197 > private getSearchOptionsForFolder(fq: IFolderQuery<URI>): TextSearchProviderFolderOptions {
198 const includes = resolvePatternsForProvider(this.query.includePattern, fq.includePattern);
199
226 return options;
227 }
229 >
230 function patternInfoToQuery(patternInfo: IPatternInfo): TextSearchQuery2 {
231 return {
237 };
238 }
240 > export class TextSearchResultsCollector {
241 > private _batchedCollector: BatchedCollector<IFileMatch>;
242 >
243 > private _currentFolderIdx: number = -1;
244 > private _currentUri: URI | undefined;
245 > private _currentFileMatch: IFileMatch | null = null;
246 >
247 > constructor(private _onResult: (result: IFileMatch[]) => void) {
248 this._batchedCollector = new BatchedCollector<IFileMatch>(512, items => this.sendItems(items));
249 }
251 > add(data: TextSearchResult2, folderIdx: number): void {
252 // Collects TextSearchResults into IInternalFileMatches and collates using BatchedCollector.
253 // This is efficient for ripgrep which sends results back one file at a time. It wouldn't be efficient for other search
269 this._currentFileMatch.results!.push(extensionResultToFrontendResult(data));
270 }
272 > private pushToCollector(): void {
273 const size = this._currentFileMatch && this._currentFileMatch.results ?
274 this._currentFileMatch.results.length :
276 this._batchedCollector.addItem(this._currentFileMatch!, size);
277 }
279 > flush(): void {
280 this.pushToCollector();
281 this._batchedCollector.flush();
282 }
284 > private sendItems(items: IFileMatch[]): void {
285 this._onResult(items);
286 }
288 >
289 function extensionResultToFrontendResult(data: TextSearchResult2): ITextSearchResult {
290 // Warning: result from RipgrepTextSearchEH has fake Range. Don't depend on any other props beyond these...
314 }
315 }
317 >
318 > /**
319 > * Collects items that have a size - before the cumulative size of collected items reaches START_BATCH_AFTER_COUNT, the callback is called for every
320 > * set of items collected.
321 > * But after that point, the callback is called with batches of maxBatchSize.
322 > * If the batch isn't filled within some time, the callback is also called.
323 > */
324 > export class BatchedCollector<T> {
325 > private static readonly TIMEOUT = 4000;
326 >
327 > // After START_BATCH_AFTER_COUNT items have been collected, stop flushing on timeout
328 > private static readonly START_BATCH_AFTER_COUNT = 50;
329 >
330 > private totalNumberCompleted = 0;
331 > private batch: T[] = [];
332 > private batchSize = 0;
333 > private timeoutHandle: Timeout | undefined;
334 >
335 > constructor(private maxBatchSize: number, private cb: (items: T[]) => void) {
336 }
338 > addItem(item: T, size: number): void {
339 if (!item) {
340 return;
343 this.addItemToBatch(item, size);
344 }
346 > addItems(items: T[], size: number): void {
347 if (!items) {
348 return;
351 this.addItemsToBatch(items, size);
352 }
354 > private addItemToBatch(item: T, size: number): void {
355 this.batch.push(item);
356 this.batchSize += size;
357 this.onUpdate();
358 }
360 > private addItemsToBatch(item: T[], size: number): void {
361 this.batch = this.batch.concat(item);
362 this.batchSize += size;
363 this.onUpdate();
364 }
366 > private onUpdate(): void {
367 if (this.totalNumberCompleted < BatchedCollector.START_BATCH_AFTER_COUNT) {
368 // Flush because we aren't batching yet
378 }
379 }
381 > flush(): void {
382 if (this.batchSize) {
383 this.totalNumberCompleted += this.batchSize;
src/vs/workbench/services/search/node/textSearchManager.ts 15 introduced LOC · 2 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- textSearchManager.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 { toCanonicalName } from '../../textfile/common/encoding.js';
7 > import * as pfs from '../../../../base/node/pfs.js';
8 > import { ITextQuery, ITextSearchStats } from '../common/search.js';
9 > import { TextSearchProvider2 } from '../common/searchExtTypes.js';
10 > import { TextSearchManager } from '../common/textSearchManager.js';
11 >
12 > export class NativeTextSearchManager extends TextSearchManager {
13 >
14 > constructor(query: ITextQuery, provider: TextSearchProvider2, _pfs: typeof pfs = pfs, processType: ITextSearchStats['type'] = 'searchProcess') {
15 super({ query, provider }, {
16 readdir: resource => _pfs.Promises.readdir(resource.fsPath),