From 2d6df400a7ee2c3bc458ff23b18b9df4d6500ad6 Mon Sep 17 00:00:00 2001 From: Andrea Mah <31675041+andreamah@users.noreply.github.com> Date: Fri, 3 May 2024 16:13:28 -0700 Subject: [PATCH] finish fixing unsafe type assertions in search (#211991) --- .../services/search/common/fileSearchManager.ts | 9 +++++---- .../services/search/common/queryBuilder.ts | 6 +++--- .../services/search/common/searchHelpers.ts | 6 +++--- .../services/search/common/textSearchManager.ts | 4 ++-- .../services/search/node/rawSearchService.ts | 13 +++++++------ .../services/search/node/textSearchAdapter.ts | 11 ++++++----- 6 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/vs/workbench/services/search/common/fileSearchManager.ts b/src/vs/workbench/services/search/common/fileSearchManager.ts index 960c90492fd..1685b1f258f 100644 --- a/src/vs/workbench/services/search/common/fileSearchManager.ts +++ b/src/vs/workbench/services/search/common/fileSearchManager.ts @@ -152,7 +152,7 @@ class FileSearchEngine { } this.matchDirectoryTree(tree, queryTester, onResult); - return { + return { providerTime, postProcessTime: postProcessSW.elapsed() }; @@ -286,14 +286,15 @@ export class FileSearchManager { return this.doSearch(engine, FileSearchManager.BATCH_SIZE, onInternalResult, token).then( result => { - return { + return { limitHit: result.limitHit, - stats: { + stats: result.stats ? { fromCache: false, type: 'fileSearchProvider', resultCount, detailStats: result.stats - } + } : undefined, + messages: [] }; }); } diff --git a/src/vs/workbench/services/search/common/queryBuilder.ts b/src/vs/workbench/services/search/common/queryBuilder.ts index 9259afa1d89..0db88575f27 100644 --- a/src/vs/workbench/services/search/common/queryBuilder.ts +++ b/src/vs/workbench/services/search/common/queryBuilder.ts @@ -110,7 +110,7 @@ export class QueryBuilder { }); const commonQuery = this.commonQuery(folderResources?.map(toWorkspaceFolder), options); - return { + return { ...commonQuery, type: QueryType.Text, contentPattern, @@ -180,7 +180,7 @@ export class QueryBuilder { file(folders: (IWorkspaceFolderData | URI)[], options: IFileQueryBuilderOptions = {}): IFileQuery { const commonQuery = this.commonQuery(folders, options); - return { + return { ...commonQuery, type: QueryType.File, filePattern: options.filePattern @@ -540,7 +540,7 @@ export class QueryBuilder { }; const folderName = URI.isUri(folder) ? basename(folder) : folder.name; - return { + return { folder: folderUri, folderName: includeFolderName ? folderName : undefined, excludePattern: Object.keys(excludePattern).length > 0 ? excludePattern : undefined, diff --git a/src/vs/workbench/services/search/common/searchHelpers.ts b/src/vs/workbench/services/search/common/searchHelpers.ts index 3f63134b5bf..fceb65c61a0 100644 --- a/src/vs/workbench/services/search/common/searchHelpers.ts +++ b/src/vs/workbench/services/search/common/searchHelpers.ts @@ -5,7 +5,7 @@ import { Range } from 'vs/editor/common/core/range'; import { FindMatch, ITextModel } from 'vs/editor/common/model'; -import { ITextSearchPreviewOptions, TextSearchMatch, ITextSearchResult, ITextSearchMatch, ITextQuery, ITextSearchContext } from 'vs/workbench/services/search/common/search'; +import { ITextSearchPreviewOptions, TextSearchMatch, ITextSearchResult, ITextSearchMatch, ITextQuery } from 'vs/workbench/services/search/common/search'; function editorMatchToTextSearchResult(matches: FindMatch[], model: ITextModel, previewOptions?: ITextSearchPreviewOptions): TextSearchMatch { const firstLine = matches[0].range.startLineNumber; @@ -53,7 +53,7 @@ export function getTextSearchMatchWithModelContext(matches: ITextSearchMatch[], if (typeof query.beforeContext === 'number' && query.beforeContext > 0) { const beforeContextStartLine = Math.max(prevLine + 1, matchStartLine - query.beforeContext); for (let b = beforeContextStartLine; b < matchStartLine; b++) { - results.push({ + results.push({ text: model.getLineContent(b + 1), lineNumber: b + 1 }); @@ -67,7 +67,7 @@ export function getTextSearchMatchWithModelContext(matches: ITextSearchMatch[], if (typeof query.afterContext === 'number' && query.afterContext > 0) { const afterContextToLine = Math.min(nextMatchStartLine - 1, matchEndLine + query.afterContext, model.getLineCount() - 1); for (let a = matchEndLine + 1; a <= afterContextToLine; a++) { - results.push({ + results.push({ text: model.getLineContent(a + 1), lineNumber: a + 1 }); diff --git a/src/vs/workbench/services/search/common/textSearchManager.ts b/src/vs/workbench/services/search/common/textSearchManager.ts index 7409ea8cd1c..3abb626f64b 100644 --- a/src/vs/workbench/services/search/common/textSearchManager.ts +++ b/src/vs/workbench/services/search/common/textSearchManager.ts @@ -200,7 +200,7 @@ export class TextSearchManager { const includes = resolvePatternsForProvider(this.query.includePattern, fq.includePattern); const excludes = resolvePatternsForProvider(this.query.excludePattern, fq.excludePattern); - const options = { + const options = { folder: URI.from(fq.folder), excludes, includes, @@ -210,7 +210,7 @@ export class TextSearchManager { followSymlinks: !fq.ignoreSymlinks, encoding: fq.fileEncoding && this.fileUtils.toCanonicalName(fq.fileEncoding), maxFileSize: this.query.maxFileSize, - maxResults: this.query.maxResults, + maxResults: this.query.maxResults ?? Number.MAX_SAFE_INTEGER, previewOptions: this.query.previewOptions, afterContext: this.query.afterContext, beforeContext: this.query.beforeContext diff --git a/src/vs/workbench/services/search/node/rawSearchService.ts b/src/vs/workbench/services/search/node/rawSearchService.ts index caad308a7d2..8849a128971 100644 --- a/src/vs/workbench/services/search/node/rawSearchService.ts +++ b/src/vs/workbench/services/search/node/rawSearchService.ts @@ -123,7 +123,7 @@ export class SearchService implements IRawSearchService { const engine = new EngineClass(config); return this.doSearch(engine, fileProgressCallback, batchSize, token).then(complete => { - return { + return { limitHit: complete.limitHit, type: 'success', stats: { @@ -132,7 +132,8 @@ export class SearchService implements IRawSearchService { fromCache: false, resultCount, sortingTime: undefined - } + }, + messages: [] }; }); } @@ -196,12 +197,11 @@ export class SearchService implements IRawSearchService { sortingTime, fromCache: false, type: this.processType, - workspaceFolderCount: config.folderQueries.length, resultCount: sortedResults.length }, messages: result.messages, limitHit: result.limitHit || typeof config.maxResults === 'number' && results.length > config.maxResults - } as ISerializedSearchSuccess, sortedResults]; + }, sortedResults]; }); }); } @@ -239,8 +239,9 @@ export class SearchService implements IRawSearchService { { type: 'success', limitHit: result.limitHit || typeof config.maxResults === 'number' && results.length > config.maxResults, - stats - } as ISerializedSearchSuccess, + stats, + messages: [], + } satisfies ISerializedSearchSuccess, sortedResults ]; }); diff --git a/src/vs/workbench/services/search/node/textSearchAdapter.ts b/src/vs/workbench/services/search/node/textSearchAdapter.ts index 97c8af5e69b..45b8aab2922 100644 --- a/src/vs/workbench/services/search/node/textSearchAdapter.ts +++ b/src/vs/workbench/services/search/node/textSearchAdapter.ts @@ -5,7 +5,7 @@ import { CancellationToken } from 'vs/base/common/cancellation'; import * as pfs from 'vs/base/node/pfs'; -import { IFileMatch, IProgressMessage, ITextQuery, ITextSearchStats, ITextSearchMatch, ISerializedFileMatch, ISerializedSearchSuccess } from 'vs/workbench/services/search/common/search'; +import { IFileMatch, IProgressMessage, ITextQuery, ITextSearchMatch, ISerializedFileMatch, ISerializedSearchSuccess } from 'vs/workbench/services/search/common/search'; import { RipgrepTextSearchEngine } from 'vs/workbench/services/search/node/ripgrepTextSearchEngine'; import { NativeTextSearchManager } from 'vs/workbench/services/search/node/textSearchManager'; @@ -15,12 +15,13 @@ export class TextSearchEngineAdapter { search(token: CancellationToken, onResult: (matches: ISerializedFileMatch[]) => void, onMessage: (message: IProgressMessage) => void): Promise { if ((!this.query.folderQueries || !this.query.folderQueries.length) && (!this.query.extraFileResources || !this.query.extraFileResources.length)) { - return Promise.resolve({ + return Promise.resolve({ type: 'success', limitHit: false, - stats: { + stats: { type: 'searchProcess' - } + }, + messages: [] }); } @@ -38,7 +39,7 @@ export class TextSearchEngineAdapter { }, token) .then( - c => resolve({ limitHit: c.limitHit, type: 'success', stats: c.stats } as ISerializedSearchSuccess), + c => resolve({ limitHit: c.limitHit ?? false, type: 'success', stats: c.stats, messages: [] }), reject); }); }