Skip to content

Commit

Permalink
feedback from search api finder TPI (#223950)
Browse files Browse the repository at this point in the history
* add documentation for includes and excludes as arrays.
Fixes #223286

* Tweaks to ExcludeSettingOptions
Fixes #223384
Fixes #223385
Fixes #223387

* `UseIgnoreFiles` cleanup and other tweaks
Fixes #223396
Fixes #223394
Fixes #223391

* document default value of maxResults
Fixes #223395

* clarify matchLines
Fixes #223324
  • Loading branch information
andreamah authored Jul 26, 2024
1 parent 9d4c0fd commit 00374b8
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 48 deletions.
10 changes: 5 additions & 5 deletions src/vs/workbench/api/common/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -976,8 +976,8 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I

const oldOptions = {
exclude: options?.exclude && options.exclude.length > 0 ? options.exclude[0] : undefined,
useDefaultExcludes: !options?.useExcludeSettings || (options?.useExcludeSettings === ExcludeSettingOptions.filesExclude || options?.useExcludeSettings === ExcludeSettingOptions.searchAndFilesExclude),
useDefaultSearchExcludes: !options?.useExcludeSettings || (options?.useExcludeSettings === ExcludeSettingOptions.searchAndFilesExclude),
useDefaultExcludes: !options?.useExcludeSettings || (options?.useExcludeSettings === ExcludeSettingOptions.FilesExclude || options?.useExcludeSettings === ExcludeSettingOptions.SearchAndFilesExclude),
useDefaultSearchExcludes: !options?.useExcludeSettings || (options?.useExcludeSettings === ExcludeSettingOptions.SearchAndFilesExclude),
maxResults: options?.maxResults,
useIgnoreFiles: options?.useIgnoreFiles?.local,
useGlobalIgnoreFiles: options?.useIgnoreFiles?.global,
Expand Down Expand Up @@ -1012,16 +1012,16 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
oldOptions = {
include: options.include && options.include.length > 0 ? options.include[0] : undefined,
exclude: options.exclude && options.exclude.length > 0 ? options.exclude[0] : undefined,
useDefaultExcludes: options.useExcludeSettings === undefined || (options.useExcludeSettings === ExcludeSettingOptions.filesExclude || options.useExcludeSettings === ExcludeSettingOptions.searchAndFilesExclude),
useSearchExclude: options.useExcludeSettings === undefined || (options.useExcludeSettings === ExcludeSettingOptions.searchAndFilesExclude),
useDefaultExcludes: options.useExcludeSettings === undefined || (options.useExcludeSettings === ExcludeSettingOptions.FilesExclude || options.useExcludeSettings === ExcludeSettingOptions.SearchAndFilesExclude),
useSearchExclude: options.useExcludeSettings === undefined || (options.useExcludeSettings === ExcludeSettingOptions.SearchAndFilesExclude),
maxResults: options.maxResults,
useIgnoreFiles: options.useIgnoreFiles?.local,
useGlobalIgnoreFiles: options.useIgnoreFiles?.global,
useParentIgnoreFiles: options.useIgnoreFiles?.parent,
followSymlinks: options.followSymlinks,
encoding: options.encoding,
previewOptions: options.previewOptions ? {
matchLines: options.previewOptions?.matchLines ?? 100,
matchLines: options.previewOptions?.numMatchLines ?? 100,
charsPerLine: options.previewOptions?.charsPerLine ?? 10000,
} : undefined,
beforeContext: options.surroundingContext,
Expand Down
9 changes: 6 additions & 3 deletions src/vs/workbench/services/search/common/searchExtTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,22 +538,25 @@ export class TextSearchContextNew {
public lineNumber: number) { }
}

/**
* Options for following search.exclude and files.exclude settings.
*/
export enum ExcludeSettingOptions {
/*
* Don't use any exclude settings.
*/
none = 1,
None = 1,
/*
* Use:
* - files.exclude setting
*/
filesExclude = 2,
FilesExclude = 2,
/*
* Use:
* - files.exclude setting
* - search.exclude setting
*/
searchAndFilesExclude = 3
SearchAndFilesExclude = 3
}

export enum TextSearchCompleteMessageTypeNew {
Expand Down
47 changes: 36 additions & 11 deletions src/vscode-dts/vscode.proposed.findFiles2New.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,19 @@ declare module 'vscode' {

export interface FindFiles2OptionsNew {
/**
* A {@link GlobPattern glob pattern} that defines files and folders to exclude. The glob pattern
* will be matched against the file paths of resulting matches relative to their workspace.
* An array of {@link GlobPattern GlobPattern} that defines files to exclude.
* The glob patterns will be matched against the file paths of files relative to their workspace or {@link RelativePattern.baseUri} if applicable.
*
* If more than one value is used, the values are combined with a logical AND.
* For example, consider the following code:
*
* ```ts
* const ab = findFiles(['**​/*.js'], {exclude: ['*.ts', '*.js']});
* const a = findFiles(['**​/*.js'], {exclude: ['*.ts']});
* const b = findFiles(['**​/*.js'], {exclude: ['*.js']});
* ```
*
* In this, `ab` will be the intersection of results from `a` and `b`.
*/
exclude?: GlobPattern[];

Expand All @@ -18,19 +29,21 @@ declare module 'vscode' {
useExcludeSettings?: ExcludeSettingOptions;

/**
* The maximum number of results to search for
* The maximum number of results to search for. Defaults to 20000 results.
*/
maxResults?: number;

/**
* Which file locations we should look for ignore (.gitignore or .ignore) files to respect.
* Which file locations have ignore (`.gitignore` or `.ignore`) files to follow.
*
* When any of these fields are `undefined`, we will:
* - assume the value if possible (e.g. if only one is valid)
* or
* - follow settings using the value for the corresponding `search.use*IgnoreFiles` settting.
* When any of these fields are `undefined`, the value will either be assumed (e.g. if only one is valid),
* or it will follow settings based on the corresponding `search.use*IgnoreFiles` setting.
*
* Will log an error if an invalid combination is set.
*
* Although `.ignore` files are uncommon, they can be leveraged if there are patterns
* that should not be known to git, but should be known to the search providers.
* They should be in the same locations where `.gitignore` files are found, and they follow the same format.
*/
useIgnoreFiles?: {
/**
Expand Down Expand Up @@ -67,9 +80,21 @@ declare module 'vscode' {
* @example
* findFiles(['**​/*.js'], {exclude: ['**​/out/**'], useIgnoreFiles: true, maxResults: 10})
*
* @param filePattern A {@link GlobPattern glob pattern} that defines the files to search for. The glob pattern
* will be matched against the file paths of resulting matches relative to their workspace. Use a {@link RelativePattern relative pattern}
* to restrict the search results to a {@link WorkspaceFolder workspace folder}.
* @param filePattern An array of {@link GlobPattern GlobPattern} that defines the files to search for.
* The glob patterns will be matched against the file paths of files relative to their workspace or {@link baseUri GlobPattern.baseUri} if applicable.
* Use a {@link RelativePattern RelativePatten} to restrict the search results to a {@link WorkspaceFolder workspace folder}.
*
* If more than one value is used, the values are combined with a logical OR.
*
* For example, consider the following code:
*
* ```ts
* const ab = findFiles(['*.ts', '*.js']);
* const a = findFiles(['**​/*.ts']);
* const b = findFiles(['**​/*.js']);
* ```
*
* In this, `ab` will be the union of results from `a` and `b`.
* @param options A set of {@link FindFiles2Options FindFiles2Options} that defines where and how to search (e.g. exclude settings).
* @param token A token that can be used to signal cancellation to the underlying search engine.
* @returns A thenable that resolves to an array of resource identifiers. Will return no results if no
Expand Down
79 changes: 50 additions & 29 deletions src/vscode-dts/vscode.proposed.findTextInFilesNew.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,38 @@ declare module 'vscode' {

export interface FindTextInFilesOptionsNew {
/**
* A {@link GlobPattern glob pattern} that defines the files to search for. The glob pattern
* will be matched against the file paths of files relative to their workspace. Use a {@link RelativePattern relative pattern}
* to restrict the search results to a {@link WorkspaceFolder workspace folder}.
* An array of {@link GlobPattern GlobPattern} that defines the files to search for.
* The glob patterns will be matched against the file paths of files relative to their workspace or {@link baseUri GlobPattern.baseUri} if applicable.
* Use a {@link RelativePattern RelativePattern} to restrict the search results to a {@link WorkspaceFolder workspace folder}.
*
* If more than one value is used, the values are combined with a logical OR.
*
* For example, consider the following code:
*
* ```ts
* const ab = findTextInFilesNew('foo', {include: ['*.ts', '*.js']});
* const a = findTextInFilesNew('foo', {include: ['*.ts']});
* const b = findTextInFilesNew('foo', {include: ['*.js']});
* ```
*
* In this, `ab` will be the union of results from `a` and `b`.
*/
include?: GlobPattern[];

/**
* A {@link GlobPattern glob pattern} that defines files and folders to exclude. The glob pattern
* will be matched against the file paths of resulting matches relative to their workspace.
* An array of {@link GlobPattern GlobPattern} that defines files to exclude.
* The glob patterns will be matched against the file paths of files relative to their workspace or {@link RelativePattern.baseUri} if applicable.
*
* If more than one value is used, the values are combined with a logical AND.
* For example, consider the following code:
*
* ```ts
* const ab = findTextInFilesNew('foo', {exclude: ['*.ts', '*.js']});
* const a = findTextInFilesNew('foo', {exclude: ['*.ts']});
* const b = findTextInFilesNew('foo', {exclude: ['*.js']});
* ```
*
* In this, `ab` will be the intersection of results from `a` and `b`.
*/
exclude?: GlobPattern[];

Expand All @@ -27,20 +50,21 @@ declare module 'vscode' {
useExcludeSettings?: ExcludeSettingOptions;

/**
* The maximum number of results to search for
* The maximum number of results to search for. Defaults to 20000 results.
*/
maxResults?: number;


/**
* Which file locations we should look for ignore (.gitignore or .ignore) files to respect.
* Which file locations have ignore (`.gitignore` or `.ignore`) files to follow.
*
* When any of these fields are `undefined`, we will:
* - assume the value if possible (e.g. if only one is valid)
* or
* - follow settings using the value for the corresponding `search.use*IgnoreFiles` settting.
* When any of these fields are `undefined`, the value will either be assumed (e.g. if only one is valid),
* or it will follow settings based on the corresponding `search.use*IgnoreFiles` setting.
*
* Will log an error if an invalid combination is set.
*
* Although `.ignore` files are uncommon, they can be leveraged if there are patterns
* that should not be known to git, but should be known to the search providers.
* They should be in the same locations where `.gitignore` files are found, and they follow the same format.
*/
useIgnoreFiles?: {
/**
Expand Down Expand Up @@ -78,10 +102,10 @@ declare module 'vscode' {
*/
previewOptions?: {
/**
* The maximum number of lines in the preview.
* The maximum number of lines in the preview of the match itself (not including surrounding context lines).
* Only search providers that support multiline search will ever return more than one line in the match.
*/
matchLines?: number;
numMatchLines?: number;

/**
* The maximum number of characters included per line.
Expand All @@ -106,25 +130,22 @@ declare module 'vscode' {
complete: Thenable<TextSearchCompleteNew>;
}

/*
* Options for following search.exclude and files.exclude settings.
*/
/**
* Options for following search.exclude and files.exclude settings.
*/
export enum ExcludeSettingOptions {
/*
/**
* Don't use any exclude settings.
*/
none = 1,
/*
* Use:
* - files.exclude setting
None = 1,
/**
* Use the `files.exclude` setting
*/
filesExclude = 2,
/*
* Use:
* - files.exclude setting
* - search.exclude setting
FilesExclude = 2,
/**
* Use the `files.exclude` and `search.exclude` settings
*/
searchAndFilesExclude = 3
SearchAndFilesExclude = 3
}

export namespace workspace {
Expand All @@ -133,7 +154,7 @@ declare module 'vscode' {
*
* Search text in files across all {@link workspace.workspaceFolders workspace folders} in the workspace.
* @param query The query parameters for the search - the search string, whether it's case-sensitive, or a regex, or matches whole words.
* @param options An optional set of query options. Include and exclude patterns, maxResults, etc.
* @param options An optional set of query options.
* @param callback A callback, called for each result
* @param token A token that can be used to signal cancellation to the underlying search engine.
* @return A thenable that resolves when the search is complete.
Expand Down

0 comments on commit 00374b8

Please sign in to comment.