Skip to content

Commit 70ab0ad

Browse files
committed
Fix 'null' exclude for findFiles, add more tests
Fix microsoft#77813
1 parent ea1f613 commit 70ab0ad

File tree

7 files changed

+33
-5
lines changed

7 files changed

+33
-5
lines changed

extensions/vscode-api-tests/src/singlefolder-tests/workspace.test.ts

+14
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,20 @@ suite('workspace-namespace', () => {
520520
});
521521
});
522522

523+
test('findFiles - null exclude', async () => {
524+
await vscode.workspace.findFiles('**/file.txt').then((res) => {
525+
// search.exclude folder is still searched, files.exclude folder is not
526+
assert.equal(res.length, 1);
527+
assert.equal(basename(vscode.workspace.asRelativePath(res[0])), 'file.txt');
528+
});
529+
530+
await vscode.workspace.findFiles('**/file.txt', null).then((res) => {
531+
// search.exclude and files.exclude folders are both searched
532+
assert.equal(res.length, 2);
533+
assert.equal(basename(vscode.workspace.asRelativePath(res[0])), 'file.txt');
534+
});
535+
});
536+
523537
test('findFiles - exclude', () => {
524538
return vscode.workspace.findFiles('**/*.png').then((res) => {
525539
assert.equal(res.length, 2);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"search.exclude": {
3+
"**/search-exclude/**": true
4+
},
5+
"files.exclude": {
6+
"**/files-exclude/**": true
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
file
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
file

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -988,8 +988,9 @@ export namespace GlobPattern {
988988

989989
export function from(pattern: vscode.GlobPattern): string | types.RelativePattern;
990990
export function from(pattern: undefined): undefined;
991-
export function from(pattern: vscode.GlobPattern | undefined): string | types.RelativePattern | undefined;
992-
export function from(pattern: vscode.GlobPattern | undefined): string | types.RelativePattern | undefined {
991+
export function from(pattern: null): null;
992+
export function from(pattern: vscode.GlobPattern | undefined | null): string | types.RelativePattern | undefined | null;
993+
export function from(pattern: vscode.GlobPattern | undefined | null): string | types.RelativePattern | undefined | null {
993994
if (pattern instanceof types.RelativePattern) {
994995
return pattern;
995996
}

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,10 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac
408408

409409
// --- search ---
410410

411-
findFiles(include: string | RelativePattern | undefined, exclude: vscode.GlobPattern | undefined, maxResults: number | undefined, extensionId: ExtensionIdentifier, token: vscode.CancellationToken = CancellationToken.None): Promise<vscode.Uri[]> {
411+
/**
412+
* Note, null/undefined have different and important meanings for "exclude"
413+
*/
414+
findFiles(include: string | RelativePattern | undefined, exclude: vscode.GlobPattern | null | undefined, maxResults: number | undefined, extensionId: ExtensionIdentifier, token: vscode.CancellationToken = CancellationToken.None): Promise<vscode.Uri[]> {
412415
this._logService.trace(`extHostWorkspace#findFiles: fileSearch, extension: ${extensionId.value}, entryPoint: findFiles`);
413416

414417
let includePattern: string | undefined;

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

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

0 commit comments

Comments
 (0)