Skip to content

Commit

Permalink
update 'exclude' of file search in plugin api
Browse files Browse the repository at this point in the history
- vscode.workspace.findFiles() supports passing either a GlobPattern, undefined, or null to represent the pattern to ignore, while in theia, passing null is not allowed. This change aligned the theia pplugin api with that of vscode.

Signed-off-by: elaihau <liang.huang@ericsson.com>
  • Loading branch information
elaihau authored and elaihau committed Feb 28, 2019
1 parent f8794dd commit 7e49f87
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/file-search/src/common/file-search-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export namespace FileSearchService {
fuzzyMatch?: boolean
limit?: number
useGitIgnore?: boolean
/** when `undefined`, no excludes will apply, when empty array, default excludes will apply */
defaultIgnorePatterns?: string[]
}
}
6 changes: 3 additions & 3 deletions packages/file-search/src/node/file-search-service-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ export class FileSearchServiceImpl implements FileSearchService {
@inject(RawProcessFactory) protected readonly rawProcessFactory: RawProcessFactory) { }

async find(searchPattern: string, options: FileSearchService.Options, cancellationToken?: CancellationToken): Promise<string[]> {
if (options.defaultIgnorePatterns && options.defaultIgnorePatterns.length === 0) { // default excludes
options.defaultIgnorePatterns.push('.git');
}
const opts = {
fuzzyMatch: true,
limit: Number.MAX_SAFE_INTEGER,
useGitIgnore: true,
defaultIgnorePatterns: [
'.git'
],
...options
};
const args: string[] = this.getSearchArgs(opts);
Expand Down
8 changes: 7 additions & 1 deletion packages/plugin-ext/src/main/browser/workspace-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,13 @@ export class WorkspaceMainImpl implements WorkspaceMain {
maxResults?: number, token?: theia.CancellationToken): Promise<UriComponents[]> {
const opts: FileSearchService.Options = { rootUris: this.roots.map(r => r.uri) };
if (typeof excludePatternOrDisregardExcludes === 'string') {
opts.defaultIgnorePatterns = [excludePatternOrDisregardExcludes];
if (excludePatternOrDisregardExcludes === '') { // default excludes
opts.defaultIgnorePatterns = [];
} else {
opts.defaultIgnorePatterns = [excludePatternOrDisregardExcludes];
}
} else {
opts.defaultIgnorePatterns = undefined; // no excludes
}
if (typeof maxResults === 'number') {
opts.limit = maxResults;
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-ext/src/plugin/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ export function createAPIFactory(
ignoreDeleteEvents?: boolean): theia.FileSystemWatcher {
return workspaceExt.createFileSystemWatcher(globPattern, ignoreCreateEvents, ignoreChangeEvents, ignoreDeleteEvents);
},
findFiles(include: theia.GlobPattern, exclude?: theia.GlobPattern | undefined, maxResults?: number, token?: CancellationToken): PromiseLike<Uri[]> {
findFiles(include: theia.GlobPattern, exclude?: theia.GlobPattern | null, maxResults?: number, token?: CancellationToken): PromiseLike<Uri[]> {
return workspaceExt.findFiles(include, exclude, maxResults, token);
},
applyEdit(edit: theia.WorkspaceEdit): PromiseLike<boolean> {
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-ext/src/plugin/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class WorkspaceExtImpl implements WorkspaceExt {
});
}

findFiles(include: theia.GlobPattern, exclude?: theia.GlobPattern | undefined, maxResults?: number,
findFiles(include: theia.GlobPattern, exclude?: theia.GlobPattern | null, maxResults?: number,
token: CancellationToken = CancellationToken.None): PromiseLike<URI[]> {
let includePattern: string;
if (include) {
Expand All @@ -127,15 +127,15 @@ export class WorkspaceExtImpl implements WorkspaceExt {

let excludePatternOrDisregardExcludes: string | false;
if (exclude === undefined) {
excludePatternOrDisregardExcludes = false;
excludePatternOrDisregardExcludes = ''; // default excludes
} else if (exclude) {
if (typeof exclude === 'string') {
excludePatternOrDisregardExcludes = exclude;
} else {
excludePatternOrDisregardExcludes = exclude.pattern;
}
} else {
excludePatternOrDisregardExcludes = false;
excludePatternOrDisregardExcludes = false; // no excludes
}

if (token && token.isCancellationRequested) {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4028,7 +4028,7 @@ declare module '@theia/plugin' {
* @return A thenable that resolves to an array of resource identifiers. Will return no results if no
* [workspace folders](#workspace.workspaceFolders) are opened.
*/
export function findFiles(include: GlobPattern, exclude?: GlobPattern | undefined, maxResults?: number, token?: CancellationToken): PromiseLike<Uri[]>;
export function findFiles(include: GlobPattern, exclude?: GlobPattern | null, maxResults?: number, token?: CancellationToken): PromiseLike<Uri[]>;

/**
* Make changes to one or many resources or create, delete, and rename resources as defined by the given
Expand Down

0 comments on commit 7e49f87

Please sign in to comment.