Skip to content

Commit

Permalink
Usage of useDefaultExcludes and useDefaultSearchExcludes is confu…
Browse files Browse the repository at this point in the history
…sing

Fixes #205692
  • Loading branch information
andreamah committed Apr 26, 2024
1 parent caf1185 commit f74f3e2
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 35 deletions.
97 changes: 89 additions & 8 deletions src/vs/workbench/api/common/extHostWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,8 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac
return this._findFilesImpl(include, undefined, {
exclude: excludeString,
maxResults,
useDefaultExcludes: useFileExcludes,
useDefaultSearchExcludes: false,
useIgnoreFiles: false
excludeSettings: useFileExcludes ? vscode.ExcludeSettingOptions.filesExclude : vscode.ExcludeSettingOptions.none,
ignoreFilesToUse: vscode.SearchIgnoreOptions.none
}, token);
}

Expand All @@ -474,6 +473,85 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac
return this._findFilesImpl(undefined, filePattern, options, token);
}

private _parseIgnoreFileSettings(options: vscode.FindFiles2Options): {
disregardLocalIgnoreFiles: boolean | undefined;
disregardParentIgnoreFiles: boolean | undefined;
disregardGlobalIgnoreFiles: boolean | undefined;
} {

let disregardLocalIgnoreFiles: boolean | undefined = undefined;
let disregardParentIgnoreFiles: boolean | undefined = undefined;
let disregardGlobalIgnoreFiles: boolean | undefined = undefined;

if (options.excludeSettings) {
switch (options.ignoreFilesToUse) {
case vscode.SearchIgnoreOptions.none:
disregardLocalIgnoreFiles = true;
disregardParentIgnoreFiles = true;
disregardGlobalIgnoreFiles = true;
break;
case vscode.SearchIgnoreOptions.localOnly:
disregardLocalIgnoreFiles = false;
disregardParentIgnoreFiles = true;
disregardGlobalIgnoreFiles = true;
break;
case vscode.SearchIgnoreOptions.localAndFollowSettings:
disregardLocalIgnoreFiles = false;
break;
case vscode.SearchIgnoreOptions.localAndParent:
disregardLocalIgnoreFiles = false;
disregardParentIgnoreFiles = false;
disregardGlobalIgnoreFiles = true;
break;
case vscode.SearchIgnoreOptions.localAndGlobal:
disregardLocalIgnoreFiles = false;
disregardParentIgnoreFiles = true;
disregardGlobalIgnoreFiles = false;
break;
case vscode.SearchIgnoreOptions.all:
disregardLocalIgnoreFiles = false;
disregardParentIgnoreFiles = false;
disregardGlobalIgnoreFiles = false;
break;
default:
// vscode.SearchIgnoreOptions.followSettings also follows this
break;
}
}

return {
disregardLocalIgnoreFiles,
disregardParentIgnoreFiles,
disregardGlobalIgnoreFiles
};
}

private _parseShouldUseExcludeSetting(options: vscode.FindFiles2Options): {
disregardExcludeSettings: boolean;
disregardSearchExcludeSettings: boolean;
} {

let disregardExcludeSettings: boolean = false;
let disregardSearchExcludeSettings: boolean = false;

if (options.excludeSettings) {
switch (options.excludeSettings) {
case vscode.ExcludeSettingOptions.none:
disregardExcludeSettings = true;
disregardSearchExcludeSettings = true;
break;
case vscode.ExcludeSettingOptions.filesExclude:
disregardSearchExcludeSettings = true;
break;
default:
// includes the case for vscode.ExcludeSettingOptions.searchAndFilesExclude
break;
}
}

return { disregardExcludeSettings, disregardSearchExcludeSettings };
}

private async _findFilesImpl(
// the old `findFiles` used `include` to query, but the new `findFiles2` uses `filePattern` to query.
// `filePattern` is the proper way to handle this, since it takes less precedence than the ignore files.
Expand All @@ -488,13 +566,16 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac
const excludePattern = (typeof options.exclude === 'string') ? options.exclude :
options.exclude ? options.exclude.pattern : undefined;

const shouldUseExcludeSetting = this._parseShouldUseExcludeSetting(options);
const ignoreFileSettings = this._parseIgnoreFileSettings(options);

const fileQueries = <IFileQueryBuilderOptions>{
ignoreSymlinks: typeof options.followSymlinks === 'boolean' ? !options.followSymlinks : undefined,
disregardIgnoreFiles: typeof options.useIgnoreFiles === 'boolean' ? !options.useIgnoreFiles : undefined,
disregardGlobalIgnoreFiles: typeof options.useGlobalIgnoreFiles === 'boolean' ? !options.useGlobalIgnoreFiles : undefined,
disregardParentIgnoreFiles: typeof options.useParentIgnoreFiles === 'boolean' ? !options.useParentIgnoreFiles : undefined,
disregardExcludeSettings: typeof options.useDefaultExcludes === 'boolean' ? !options.useDefaultExcludes : false,
disregardSearchExcludeSettings: typeof options.useDefaultSearchExcludes === 'boolean' ? !options.useDefaultSearchExcludes : false,
disregardIgnoreFiles: ignoreFileSettings.disregardLocalIgnoreFiles,
disregardGlobalIgnoreFiles: ignoreFileSettings.disregardGlobalIgnoreFiles,
disregardParentIgnoreFiles: ignoreFileSettings.disregardParentIgnoreFiles,
disregardExcludeSettings: shouldUseExcludeSetting.disregardExcludeSettings,
disregardSearchExcludeSettings: shouldUseExcludeSetting.disregardSearchExcludeSettings,
maxResults: options.maxResults,
excludePattern: excludePattern,
shouldGlobSearch: typeof options.fuzzy === 'boolean' ? !options.fuzzy : true,
Expand Down
96 changes: 69 additions & 27 deletions src/vscode-dts/vscode.proposed.findFiles2.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,20 @@ declare module 'vscode' {
exclude?: GlobPattern;

/**
* Whether to use the values for files.exclude. Defaults to true.
* Which settings to follow when searching for files. Defaults to {@link ExcludeSettingOptions.searchAndFilesExclude}.
*/
useDefaultExcludes?: boolean;

/**
* Whether to use the values for search.exclude. Defaults to true. Will not be followed if `useDefaultExcludes` is set to `false`.
*/
useDefaultSearchExcludes?: boolean;
excludeSettings?: ExcludeSettingOptions;

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

/**
* Whether external files that exclude files, like .gitignore, should be respected.
* Defaults to the value for `search.useIgnoreFiles` in settings.
* For more info, see the setting listed above.
* Which file locations we should look for ignore (.gitignore or .ignore) files to follow.
* Defaults to {@link SearchIgnoreOptions.followSettings}.
*/
useIgnoreFiles?: boolean;

/**
* Whether global files that exclude files, like .gitignore, should be respected.
* Must set `useIgnoreFiles` to `true` to use this.
* Defaults to the value for `search.useGlobalIgnoreFiles` in settings.
* For more info, see the setting listed above.
*/
useGlobalIgnoreFiles?: boolean;

/**
* Whether files in parent directories that exclude files, like .gitignore, should be respected.
* Must set `useIgnoreFiles` to `true` to use this.
* Defaults to the value for `search.useParentIgnoreFiles` in settings.
* For more info, see the setting listed above.
*/
useParentIgnoreFiles?: boolean;
ignoreFilesToUse?: SearchIgnoreOptions;

/**
* Whether symlinks should be followed while searching.
Expand All @@ -66,6 +44,70 @@ declare module 'vscode' {
fuzzy?: boolean;
}

export enum ExcludeSettingOptions {
/*
* Don't use any exclude settings.
*/
none,
/*
* Use:
* - files.exclude setting
*/
filesExclude,
/*
* Use:
* - files.exclude setting
* - search.exclude setting
*/
searchAndFilesExclude
}

/*
* Which locations of .gitignore and .ignore files to follow.
*/
export enum SearchIgnoreOptions {
/*
* Don't use ignore files.
*/
none,
/*
* Use:
* - ignore files at the workspace root.
*/
localOnly,
/*
* Use:
* - ignore files at the workspace root.
*
* Follow `search.useParentIgnoreFiles`and `search.useGlobalIgnoreFiles` in settings
* to dictate whether to use parent and global ignore files.
*/
localAndFollowSettings,
/*
* Use:
* - ignore files at the workspace root.
* - ignore files directly under parent folder(s) of the workspace root.
*/
localAndParent,
/*
* Use:
* - ignore files at the workspace root.
* - global ignore files (e.g. $HOME/.config/git/ignore).
*/
localAndGlobal,
/*
* Use:
* - ignore files at the workspace root.
* - ignore files directly under parent folder(s) of the workspace root.
* - global ignore files (e.g. $HOME/.config/git/ignore).
*/
all,
/*
* Follow `search.useIgnoreFiles`, `search.useParentIgnoreFiles`, and `search.useGlobalIgnoreFiles` in settings.
*/
followSettings,
}

/**
* Represents a session of a currently logged in user.
*/
Expand Down

0 comments on commit f74f3e2

Please sign in to comment.