mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-18 09:53:23 +01:00
finish fixing unsafe type assertions in search (#211991)
This commit is contained in:
@@ -152,7 +152,7 @@ class FileSearchEngine {
|
||||
}
|
||||
|
||||
this.matchDirectoryTree(tree, queryTester, onResult);
|
||||
return <IFileSearchProviderStats>{
|
||||
return {
|
||||
providerTime,
|
||||
postProcessTime: postProcessSW.elapsed()
|
||||
};
|
||||
@@ -286,14 +286,15 @@ export class FileSearchManager {
|
||||
|
||||
return this.doSearch(engine, FileSearchManager.BATCH_SIZE, onInternalResult, token).then(
|
||||
result => {
|
||||
return <ISearchCompleteStats>{
|
||||
return {
|
||||
limitHit: result.limitHit,
|
||||
stats: {
|
||||
stats: result.stats ? {
|
||||
fromCache: false,
|
||||
type: 'fileSearchProvider',
|
||||
resultCount,
|
||||
detailStats: result.stats
|
||||
}
|
||||
} : undefined,
|
||||
messages: []
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ export class QueryBuilder {
|
||||
});
|
||||
|
||||
const commonQuery = this.commonQuery(folderResources?.map(toWorkspaceFolder), options);
|
||||
return <ITextQuery>{
|
||||
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 <IFileQuery>{
|
||||
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 <IFolderQuery>{
|
||||
return {
|
||||
folder: folderUri,
|
||||
folderName: includeFolderName ? folderName : undefined,
|
||||
excludePattern: Object.keys(excludePattern).length > 0 ? excludePattern : undefined,
|
||||
|
||||
@@ -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(<ITextSearchContext>{
|
||||
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(<ITextSearchContext>{
|
||||
results.push({
|
||||
text: model.getLineContent(a + 1),
|
||||
lineNumber: a + 1
|
||||
});
|
||||
|
||||
@@ -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 = <TextSearchOptions>{
|
||||
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
|
||||
|
||||
@@ -123,7 +123,7 @@ export class SearchService implements IRawSearchService {
|
||||
const engine = new EngineClass(config);
|
||||
|
||||
return this.doSearch(engine, fileProgressCallback, batchSize, token).then(complete => {
|
||||
return <ISerializedSearchSuccess>{
|
||||
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
|
||||
];
|
||||
});
|
||||
|
||||
@@ -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<ISerializedSearchSuccess> {
|
||||
if ((!this.query.folderQueries || !this.query.folderQueries.length) && (!this.query.extraFileResources || !this.query.extraFileResources.length)) {
|
||||
return Promise.resolve(<ISerializedSearchSuccess>{
|
||||
return Promise.resolve({
|
||||
type: 'success',
|
||||
limitHit: false,
|
||||
stats: <ITextSearchStats>{
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user