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);