fileSearchManager.ts ×20

Frontier kind: Code frontier

unlabeled · c_515f5ea96ae3

17 tests · 78980 LOC · 282 files · introduces 0 tests · 133 LOC · 4 files

Introduces — evidence that enters the hierarchy at this concept

Code
30 ranges133 lines · 4 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
5434 ranges78980 lines · 282 files · Browse complete extent
All tests (intent)
17 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.

4 files ranked by introduced lines: 133 introduced LOC across 30 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/workbench/services/search/common/fileSearchManager.ts 98 introduced LOC · 20 ranges

Open complete file

57
58 constructor(private config: IFileQuery, private provider: FileSearchProvider2, private sessionLifecycle?: SessionLifecycle) {
59 > this.filePattern = config.filePattern; fileSearchManager.ts
60 > const globOptions = config.ignoreGlobCase ? { ignoreCase: true } : undefined;
61 > this.includePattern = config.includePattern && glob.parse(config.includePattern, globOptions);
62 > this.maxResults = config.maxResults || undefined;
63 > this.exists = config.exists;
64 > this.activeCancellationTokens = new Set<CancellationTokenSource>();
65 >
66 > this.globalExcludePattern = config.excludePattern && glob.parse(config.excludePattern, globOptions);
67 > }
68
69 cancel(): void {
74
75 search(_onResult: (match: IInternalFileMatch) => void): Promise<IInternalSearchComplete> {
76 > const folderQueries = this.config.folderQueries || []; fileSearchManager.ts
77 >
78 > return new Promise((resolve, reject) => {
79 > const onResult = (match: IInternalFileMatch) => {
80 this.resultCount++;
81 _onResult(match);
82 };
84 > // Support that the file pattern is a full path to a file that exists
85 > if (this.isCanceled) {
86 return resolve({ limitHit: this.isLimitHit });
87 }
89 > // For each extra file
90 > if (this.config.extraFileResources) {
91 this.config.extraFileResources
92 .forEach(extraFile => {
101 });
102 }
104 > // For each root folder'
105 >
106 > // NEW: can just call with an array of folder info
107 > this.doSearch(folderQueries, onResult).then(stats => {
108 > resolve({
109 > limitHit: this.isLimitHit,
110 > stats: stats || undefined // Only looking at single-folder workspace stats...
111 > });
112 > }, (err: Error) => {
113 reject(new Error(toErrorMessage(err)));
115 > });
116 > }
117
118
119 private async doSearch(fqs: IFolderQuery<URI>[], onResult: (match: IInternalFileMatch) => void): Promise<IFileSearchProviderStats | null> {
120 > const cancellation = new CancellationTokenSource(); fileSearchManager.ts
121 > const folderOptions = fqs.map(fq => this.getSearchOptionsForFolder(fq));
122 > const session = this.provider instanceof OldFileSearchProviderConverter ? this.sessionLifecycle?.tokenSource.token : this.sessionLifecycle?.obj;
123 > const options: FileSearchProviderOptions = {
124 > folderOptions,
125 > maxResults: this.config.maxResults ?? DEFAULT_MAX_SEARCH_RESULTS,
126 > session
127 > };
128 >
129 >
130 > const getFolderQueryInfo = (fq: IFolderQuery) => {
131 const queryTester = new QueryGlobTester(this.config, fq);
132 const noSiblingsClauses = !queryTester.hasSiblingExcludeClauses();
133 return { queryTester, noSiblingsClauses, folder: fq.folder, tree: this.initDirectoryTree() };
134 };
136 > const folderMappings: FolderQuerySearchTree<FolderQueryInfo> = new FolderQuerySearchTree<FolderQueryInfo>(fqs, getFolderQueryInfo);
137 >
138 > let providerSW: StopWatch;
139 >
140 > try {
141 > this.activeCancellationTokens.add(cancellation);
142 >
143 > providerSW = StopWatch.create();
144 > const results = await this.provider.provideFileSearchResults(
145 > this.config.filePattern || '',
146 > options,
147 > cancellation.token);
148 > const providerTime = providerSW.elapsed();
149 > const postProcessSW = StopWatch.create();
150 >
151 > if (this.isCanceled && !this.isLimitHit) {
152 return null;
153 }
171 }
172
173 > if (this.isCanceled && !this.isLimitHit) { fileSearchManager.ts
174 return null;
175 }
183 postProcessTime: postProcessSW.elapsed()
184 };
185 > } finally { fileSearchManager.ts
186 > cancellation.dispose();
187 > this.activeCancellationTokens.delete(cancellation);
188 > }
189 > }
190
191 private getSearchOptionsForFolder(fq: IFolderQuery<URI>): FileSearchProviderFolderOptions {
339
340 fileSearch(config: IFileQuery, provider: FileSearchProvider2, onBatch: (matches: IFileMatch[]) => void, token: CancellationToken): Promise<ISearchCompleteStats> {
341 > const sessionTokenSource = this.getSessionTokenSource(config.cacheKey); fileSearchManager.ts
342 > const engine = new FileSearchEngine(config, provider, sessionTokenSource);
343 >
344 > let resultCount = 0;
345 > const onInternalResult = (batch: IInternalFileMatch[]) => {
346 resultCount += batch.length;
347 onBatch(batch.map(m => this.rawMatchToSearchItem(m)));
348 };
350 > return this.doSearch(engine, FileSearchManager.BATCH_SIZE, onInternalResult, token).then(
351 > result => {
352 > return {
353 > limitHit: result.limitHit,
354 > stats: result.stats ? {
355 fromCache: false,
356 type: 'fileSearchProvider',
357 resultCount,
358 detailStats: result.stats
359 > } : undefined, fileSearchManager.ts
360 > messages: []
361 > };
362 > });
363 > }
364
365 clearCache(cacheKey: string): void {
371
372 private getSessionTokenSource(cacheKey: string | undefined): SessionLifecycle | undefined {
373 > if (!cacheKey) { fileSearchManager.ts
374 return undefined;
375 }
380
381 return this.sessions.get(cacheKey);
383
384 private rawMatchToSearchItem(match: IInternalFileMatch): IFileMatch {
396
397 private doSearch(engine: FileSearchEngine, batchSize: number, onResultBatch: (matches: IInternalFileMatch[]) => void, token: CancellationToken): Promise<IInternalSearchComplete> {
398 > const listener = token.onCancellationRequested(() => { fileSearchManager.ts
399 engine.cancel();
401 >
402 > const _onResult = (match: IInternalFileMatch) => {
403 if (match) {
404 batch.push(match);
409 }
410 };
412 > let batch: IInternalFileMatch[] = [];
413 > return engine.search(_onResult).then(result => {
414 > if (batch.length) {
415 onResultBatch(batch);
416 }
418 > listener.dispose();
419 > return result;
420 > }, error => {
421 if (batch.length) {
422 onResultBatch(batch);
425 listener.dispose();
426 return Promise.reject(error);
428 > }
429 }
src/vs/workbench/api/common/extHostSearch.ts 19 introduced LOC · 5 ranges

Open complete file

115
116 registerFileSearchProviderOld(scheme: string, provider: vscode.FileSearchProvider): IDisposable {
117 > if (this._fileSearchUsedSchemes.has(scheme)) { extHostSearch.ts
118 throw new Error(`a file search provider for the scheme '${scheme}' is already registered`);
119 }
121 > this._fileSearchUsedSchemes.add(scheme);
122 > const handle = this._handlePool++;
123 > this._fileSearchProvider.set(handle, new OldFileSearchProviderConverter(provider));
124 > this._proxy.$registerFileSearchProvider(handle, this._transformScheme(scheme));
125 > return toDisposable(() => {
126 > this._fileSearchUsedSchemes.delete(scheme);
127 > this._fileSearchProvider.delete(handle);
128 > this._proxy.$unregisterProvider(handle);
129 > });
130 > }
131
132 registerFileSearchProvider(scheme: string, provider: vscode.FileSearchProvider2): IDisposable {
147
148 $provideFileSearchResults(handle: number, session: number, rawQuery: IRawFileQuery, token: vscode.CancellationToken): Promise<ISearchCompleteStats> {
149 > const query = reviveQuery(rawQuery); extHostSearch.ts
150 > const provider = this._fileSearchProvider.get(handle);
151 > if (provider) {
152 > return this._fileSearchManager.fileSearch(query, provider, batch => {
153 this._proxy.$handleFileMatch(handle, session, batch.map(p => p.resource));
154 > }, token); extHostSearch.ts
155 > } else {
156 throw new Error('unknown provider: ' + handle);
157 }
159
160 async doInternalFileSearchWithCustomCallback(query: IFileQuery, token: CancellationToken, handleFileMatch: (data: URI[]) => void): Promise<ISearchCompleteStats> {
src/vs/workbench/services/search/common/searchExtConversionTypes.ts 11 introduced LOC · 3 ranges

Open complete file

437 }
438
439 > function newToOldFileProviderOptions(options: FileSearchProviderOptions): FileSearchOptions[] { searchExtConversionTypes.ts
440 > return options.folderOptions.map(folderOption => ({
441 folder: folderOption.folder,
442 excludes: folderOption.excludes.map(e => typeof (e) === 'string' ? e : e.pattern),
448 maxResults: options.maxResults,
449 session: <CancellationToken | undefined>options.session // TODO: make sure that we actually use a cancellation token here.
450 > } satisfies FileSearchOptions)); searchExtConversionTypes.ts
451 > }
452
453 export class OldFileSearchProviderConverter implements FileSearchProvider2 {
455
456 provideFileSearchResults(pattern: string, options: FileSearchProviderOptions, token: CancellationToken): ProviderResult<URI[]> {
457 > const getResult = async () => { searchExtConversionTypes.ts
458 > const newOpts = newToOldFileProviderOptions(options);
459 > return Promise.all(newOpts.map(
460 > o => this.provider.provideFileSearchResults({ pattern }, o, token)));
461 > };
462 > return getResult().then(e => coalesce(e).flat());
463 > }
464 }
465
src/vs/workbench/api/node/extHostSearch.ts 5 introduced LOC · 2 ranges

Open complete file

114
115 override $provideFileSearchResults(handle: number, session: number, rawQuery: IRawFileQuery, token: vscode.CancellationToken): Promise<ISearchCompleteStats> {
116 > const query = reviveQuery(rawQuery); extHostSearch.ts
117 > if (handle === this._internalFileSearchHandle) {
118 const start = Date.now();
119 return this.doInternalFileSearch(handle, session, query, token).then(result => {
123 });
124 }
126 > return super.$provideFileSearchResults(handle, session, rawQuery, token);
127 > }
128
129 override async doInternalFileSearchWithCustomCallback(rawQuery: IFileQuery, token: vscode.CancellationToken, handleFileMatch: (data: URI[]) => void): Promise<ISearchCompleteStats> {