Fix 'null' exclude for findFiles, add more tests

Fix #77813
This commit is contained in:
Rob Lourens 2019-07-24 14:24:04 -07:00
parent ea1f61356f
commit 70ab0ada55
7 changed files with 33 additions and 5 deletions

View file

@ -520,6 +520,20 @@ suite('workspace-namespace', () => {
});
});
test('findFiles - null exclude', async () => {
await vscode.workspace.findFiles('**/file.txt').then((res) => {
// search.exclude folder is still searched, files.exclude folder is not
assert.equal(res.length, 1);
assert.equal(basename(vscode.workspace.asRelativePath(res[0])), 'file.txt');
});
await vscode.workspace.findFiles('**/file.txt', null).then((res) => {
// search.exclude and files.exclude folders are both searched
assert.equal(res.length, 2);
assert.equal(basename(vscode.workspace.asRelativePath(res[0])), 'file.txt');
});
});
test('findFiles - exclude', () => {
return vscode.workspace.findFiles('**/*.png').then((res) => {
assert.equal(res.length, 2);

View file

@ -0,0 +1,8 @@
{
"search.exclude": {
"**/search-exclude/**": true
},
"files.exclude": {
"**/files-exclude/**": true
}
}

View file

@ -0,0 +1 @@
file

View file

@ -0,0 +1 @@
file

View file

@ -988,8 +988,9 @@ export namespace GlobPattern {
export function from(pattern: vscode.GlobPattern): string | types.RelativePattern;
export function from(pattern: undefined): undefined;
export function from(pattern: vscode.GlobPattern | undefined): string | types.RelativePattern | undefined;
export function from(pattern: vscode.GlobPattern | undefined): string | types.RelativePattern | undefined {
export function from(pattern: null): null;
export function from(pattern: vscode.GlobPattern | undefined | null): string | types.RelativePattern | undefined | null;
export function from(pattern: vscode.GlobPattern | undefined | null): string | types.RelativePattern | undefined | null {
if (pattern instanceof types.RelativePattern) {
return pattern;
}

View file

@ -408,7 +408,10 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac
// --- search ---
findFiles(include: string | RelativePattern | undefined, exclude: vscode.GlobPattern | undefined, maxResults: number | undefined, extensionId: ExtensionIdentifier, token: vscode.CancellationToken = CancellationToken.None): Promise<vscode.Uri[]> {
/**
* Note, null/undefined have different and important meanings for "exclude"
*/
findFiles(include: string | RelativePattern | undefined, exclude: vscode.GlobPattern | null | undefined, maxResults: number | undefined, extensionId: ExtensionIdentifier, token: vscode.CancellationToken = CancellationToken.None): Promise<vscode.Uri[]> {
this._logService.trace(`extHostWorkspace#findFiles: fileSearch, extension: ${extensionId.value}, entryPoint: findFiles`);
let includePattern: string | undefined;

View file

@ -63,7 +63,6 @@ import * as vscode from 'vscode';
import { ExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { originalFSPath } from 'vs/base/common/resources';
import { CLIServer } from 'vs/workbench/api/node/extHostCLIServer';
import { withNullAsUndefined } from 'vs/base/common/types';
import { values } from 'vs/base/common/collections';
import { Schemas } from 'vs/base/common/network';
import { IURITransformer } from 'vs/base/common/uriIpc';
@ -602,7 +601,8 @@ export function createApiFactory(
return extHostWorkspace.getRelativePath(pathOrUri, includeWorkspace);
},
findFiles: (include, exclude, maxResults?, token?) => {
return extHostWorkspace.findFiles(typeConverters.GlobPattern.from(include), typeConverters.GlobPattern.from(withNullAsUndefined(exclude)), maxResults, extension.identifier, token);
// Note, undefined/null have different meanings on "exclude"
return extHostWorkspace.findFiles(typeConverters.GlobPattern.from(include), typeConverters.GlobPattern.from(exclude), maxResults, extension.identifier, token);
},
findTextInFiles: (query: vscode.TextSearchQuery, optionsOrCallback: vscode.FindTextInFilesOptions | ((result: vscode.TextSearchResult) => void), callbackOrToken?: vscode.CancellationToken | ((result: vscode.TextSearchResult) => void), token?: vscode.CancellationToken) => {
let options: vscode.FindTextInFilesOptions;