Skip to content

Commit 3931440

Browse files
authored
connections for findTextInFilesNew and FindFiles2New to function (microsoft#223151)
* connections for findTextInFilesNew and FindFiles2New to function * remove log and fix typos
1 parent 4c03026 commit 3931440

File tree

6 files changed

+94
-23
lines changed

6 files changed

+94
-23
lines changed

src/vs/workbench/api/common/extHost.api.impl.ts

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ import { ExtensionDescriptionRegistry } from 'vs/workbench/services/extensions/c
107107
import { UIKind } from 'vs/workbench/services/extensions/common/extensionHostProtocol';
108108
import { checkProposedApiEnabled, isProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
109109
import { ProxyIdentifier } from 'vs/workbench/services/extensions/common/proxyIdentifier';
110-
import { ExcludeSettingOptions, TextSearchCompleteMessageType, TextSearchCompleteMessageTypeNew, TextSearchContextNew, TextSearchMatchNew } from 'vs/workbench/services/search/common/searchExtTypes';
110+
import { ExcludeSettingOptions, oldToNewTextSearchResult, TextSearchCompleteMessageType, TextSearchCompleteMessageTypeNew, TextSearchContextNew, TextSearchMatchNew } from 'vs/workbench/services/search/common/searchExtTypes';
111111
import type * as vscode from 'vscode';
112112

113113
export interface IExtensionRegistries {
@@ -973,7 +973,18 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
973973
},
974974
findFiles2New: (filePattern: vscode.GlobPattern[], options?: vscode.FindFiles2OptionsNew, token?: vscode.CancellationToken): Thenable<vscode.Uri[]> => {
975975
checkProposedApiEnabled(extension, 'findFiles2New');
976-
return Promise.resolve([]);
976+
977+
const oldOptions = {
978+
exclude: options?.exclude && options.exclude.length > 0 ? options.exclude[0] : undefined,
979+
useDefaultExcludes: !options?.useExcludeSettings || (options?.useExcludeSettings === ExcludeSettingOptions.filesExclude || options?.useExcludeSettings === ExcludeSettingOptions.searchAndFilesExclude),
980+
useDefaultSearchExcludes: !options?.useExcludeSettings || (options?.useExcludeSettings === ExcludeSettingOptions.searchAndFilesExclude),
981+
maxResults: options?.maxResults,
982+
useIgnoreFiles: options?.useIgnoreFiles?.local,
983+
useGlobalIgnoreFiles: options?.useIgnoreFiles?.global,
984+
useParentIgnoreFiles: options?.useIgnoreFiles?.parent,
985+
followSymlinks: options?.followSymlinks,
986+
};
987+
return extHostWorkspace.findFiles2(filePattern && filePattern.length > 0 ? filePattern[0] : undefined, oldOptions, extension.identifier, token);
977988
},
978989
findTextInFiles: (query: vscode.TextSearchQuery, optionsOrCallback: vscode.FindTextInFilesOptions | ((result: vscode.TextSearchResult) => void), callbackOrToken?: vscode.CancellationToken | ((result: vscode.TextSearchResult) => void), token?: vscode.CancellationToken) => {
979990
checkProposedApiEnabled(extension, 'findTextInFiles');
@@ -993,11 +1004,56 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
9931004
},
9941005
findTextInFilesNew: (query: vscode.TextSearchQueryNew, options?: vscode.FindTextInFilesOptionsNew, token?: vscode.CancellationToken): vscode.FindTextInFilesResponse => {
9951006
checkProposedApiEnabled(extension, 'findTextInFilesNew');
1007+
checkProposedApiEnabled(extension, 'textSearchProviderNew');
1008+
let oldOptions = {};
1009+
1010+
1011+
if (options) {
1012+
oldOptions = {
1013+
include: options.include && options.include.length > 0 ? options.include[0] : undefined,
1014+
exclude: options.exclude && options.exclude.length > 0 ? options.exclude[0] : undefined,
1015+
useDefaultExcludes: options.useExcludeSettings === undefined || (options.useExcludeSettings === ExcludeSettingOptions.filesExclude || options.useExcludeSettings === ExcludeSettingOptions.searchAndFilesExclude),
1016+
useSearchExclude: options.useExcludeSettings === undefined || (options.useExcludeSettings === ExcludeSettingOptions.searchAndFilesExclude),
1017+
maxResults: options.maxResults,
1018+
useIgnoreFiles: options.useIgnoreFiles?.local,
1019+
useGlobalIgnoreFiles: options.useIgnoreFiles?.global,
1020+
useParentIgnoreFiles: options.useIgnoreFiles?.parent,
1021+
followSymlinks: options.followSymlinks,
1022+
encoding: options.encoding,
1023+
previewOptions: options.previewOptions ? {
1024+
matchLines: options.previewOptions?.matchLines ?? 100,
1025+
charsPerLine: options.previewOptions?.charsPerLine ?? 10000,
1026+
} : undefined,
1027+
beforeContext: options.surroundingContext,
1028+
afterContext: options.surroundingContext,
1029+
} satisfies vscode.FindTextInFilesOptions & { useSearchExclude?: boolean };
1030+
}
1031+
1032+
const complete: Promise<undefined | vscode.TextSearchComplete> = Promise.resolve(undefined);
1033+
1034+
const asyncIterable = new AsyncIterableObject<vscode.TextSearchResultNew>(async emitter => {
1035+
const callback = async (result: vscode.TextSearchResult) => {
1036+
emitter.emitOne(oldToNewTextSearchResult(result));
1037+
return result;
1038+
};
1039+
await complete.then(e => {
1040+
return extHostWorkspace.findTextInFiles(
1041+
query,
1042+
oldOptions,
1043+
callback,
1044+
extension.identifier,
1045+
token
1046+
);
1047+
});
1048+
});
1049+
9961050
return {
997-
results: AsyncIterableObject.fromArray([]),
998-
complete: Promise.resolve({
999-
limitHit: false
1000-
})
1051+
results: asyncIterable,
1052+
complete: complete.then((e) => {
1053+
return {
1054+
limitHit: e?.limitHit ?? false
1055+
};
1056+
}),
10011057
};
10021058
},
10031059
save: (uri) => {

src/vs/workbench/api/common/extHostWorkspace.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac
522522
.then(data => Array.isArray(data) ? data.map(d => URI.revive(d)) : []);
523523
}
524524

525-
async findTextInFiles(query: vscode.TextSearchQuery, options: vscode.FindTextInFilesOptions, callback: (result: vscode.TextSearchResult) => void, extensionId: ExtensionIdentifier, token: vscode.CancellationToken = CancellationToken.None): Promise<vscode.TextSearchComplete> {
525+
async findTextInFiles(query: vscode.TextSearchQuery, options: vscode.FindTextInFilesOptions & { useSearchExclude?: boolean }, callback: (result: vscode.TextSearchResult) => void, extensionId: ExtensionIdentifier, token: vscode.CancellationToken = CancellationToken.None): Promise<vscode.TextSearchComplete> {
526526
this._logService.trace(`extHostWorkspace#findTextInFiles: textSearch, extension: ${extensionId.value}, entryPoint: findTextInFiles`);
527527

528528
const requestId = this._requestIdProvider.getNext();
@@ -543,6 +543,7 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac
543543
disregardGlobalIgnoreFiles: typeof options.useGlobalIgnoreFiles === 'boolean' ? !options.useGlobalIgnoreFiles : undefined,
544544
disregardParentIgnoreFiles: typeof options.useParentIgnoreFiles === 'boolean' ? !options.useParentIgnoreFiles : undefined,
545545
disregardExcludeSettings: typeof options.useDefaultExcludes === 'boolean' ? !options.useDefaultExcludes : true,
546+
disregardSearchExcludeSettings: typeof options.useSearchExclude === 'boolean' ? !options.useSearchExclude : true,
546547
fileEncoding: options.encoding,
547548
maxResults: options.maxResults,
548549
previewOptions,

src/vs/workbench/services/search/common/searchExtTypes.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import { asArray } from 'vs/base/common/arrays';
67
import { CancellationToken } from 'vs/base/common/cancellation';
78
import { URI } from 'vs/base/common/uri';
89
import { IProgress } from 'vs/platform/progress/common/progress';
@@ -501,6 +502,10 @@ export interface FindTextInFilesOptions {
501502

502503
// NEW TYPES
503504
// added temporarily for testing new API shape
505+
/**
506+
* A result payload for a text search, pertaining to matches within a single file.
507+
*/
508+
export type TextSearchResultNew = TextSearchMatchNew | TextSearchContextNew;
504509

505510
/**
506511
* The main match information for a {@link TextSearchResultNew}.
@@ -555,3 +560,16 @@ export enum TextSearchCompleteMessageTypeNew {
555560
Information = 1,
556561
Warning = 2,
557562
}
563+
564+
function isTextSearchMatch(object: any): object is TextSearchMatch {
565+
return 'uri' in object && 'ranges' in object && 'preview' in object;
566+
}
567+
568+
export function oldToNewTextSearchResult(result: TextSearchResult): TextSearchResultNew {
569+
if (isTextSearchMatch(result)) {
570+
const ranges = asArray(result.ranges).map(r => ({ sourceRange: r, previewRange: r }));
571+
return new TextSearchMatchNew(result.uri, ranges, result.preview.text);
572+
} else {
573+
return new TextSearchContextNew(result.uri, result.text, result.lineNumber);
574+
}
575+
}

src/vscode-dts/vscode.proposed.findFiles2New.d.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ declare module 'vscode' {
1010
* A {@link GlobPattern glob pattern} that defines files and folders to exclude. The glob pattern
1111
* will be matched against the file paths of resulting matches relative to their workspace.
1212
*/
13-
exclude?: GlobPattern;
13+
exclude?: GlobPattern[];
1414

1515
/**
1616
* Which settings to follow when searching for files. Defaults to {@link ExcludeSettingOptions.searchAndFilesExclude}.
@@ -58,17 +58,14 @@ declare module 'vscode' {
5858
followSymlinks?: boolean;
5959
}
6060

61-
/**
62-
* Represents a session of a currently logged in user.
63-
*/
6461
export namespace workspace {
6562
/**
6663
* WARNING: VERY EXPERIMENTAL.
6764
*
6865
* Find files across all {@link workspace.workspaceFolders workspace folders} in the workspace.
6966
*
7067
* @example
71-
* findFiles('**​/*.js', {exclude: '**​/out/**', useIgnoreFiles: true, maxResults: 10})
68+
* findFiles(['**​/*.js'], {exclude: ['**​/out/**'], useIgnoreFiles: true, maxResults: 10})
7269
*
7370
* @param filePattern A {@link GlobPattern glob pattern} that defines the files to search for. The glob pattern
7471
* will be matched against the file paths of resulting matches relative to their workspace. Use a {@link RelativePattern relative pattern}

src/vscode-dts/vscode.proposed.findTextInFilesNew.d.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ declare module 'vscode' {
77

88
// https://github.com/microsoft/vscode/issues/59924
99

10-
/**
11-
* Options that can be set on a findTextInFiles search.
12-
*/
1310
export interface FindTextInFilesOptionsNew {
11+
/**
12+
* A {@link GlobPattern glob pattern} that defines the files to search for. The glob pattern
13+
* will be matched against the file paths of files relative to their workspace. Use a {@link RelativePattern relative pattern}
14+
* to restrict the search results to a {@link WorkspaceFolder workspace folder}.
15+
*/
16+
include?: GlobPattern[];
17+
1418
/**
1519
* A {@link GlobPattern glob pattern} that defines files and folders to exclude. The glob pattern
1620
* will be matched against the file paths of resulting matches relative to their workspace.
1721
*/
18-
exclude?: GlobPattern;
22+
exclude?: GlobPattern[];
1923

2024
/**
2125
* Which settings to follow when searching for files. Defaults to {@link ExcludeSettingOptions.searchAndFilesExclude}.
@@ -63,13 +67,6 @@ declare module 'vscode' {
6367
*/
6468
followSymlinks?: boolean;
6569

66-
/**
67-
* A {@link GlobPattern glob pattern} that defines the files to search for. The glob pattern
68-
* will be matched against the file paths of files relative to their workspace. Use a {@link RelativePattern relative pattern}
69-
* to restrict the search results to a {@link WorkspaceFolder workspace folder}.
70-
*/
71-
include?: GlobPattern;
72-
7370
/**
7471
* Interpret files using this encoding.
7572
* See the vscode setting `"files.encoding"`

src/vscode-dts/vscode.proposed.textSearchProviderNew.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,13 @@ declare module 'vscode' {
9595
/**
9696
* The maximum number of lines in the preview.
9797
* Only search providers that support multiline search will ever return more than one line in the match.
98+
* Defaults to 100.
9899
*/
99100
matchLines: number;
100101

101102
/**
102103
* The maximum number of characters included per line.
104+
* Defaults to 10000.
103105
*/
104106
charsPerLine: number;
105107
};

0 commit comments

Comments
 (0)