Skip to content

Commit

Permalink
support ignored globs & limit in file search & plugin-ext
Browse files Browse the repository at this point in the history
- in current Theia, passing "ignored globs" or "limit" to plugins-api from plugins does not work, as the data is dropped before reaching the file search service. This change ensures the data goes through and handled by the service.

Signed-off-by: elaihau <liang.huang@ericsson.com>
  • Loading branch information
elaihau committed Feb 26, 2019
1 parent 41bbd0e commit 6e54f3c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,12 @@ describe('search-service', function () {
expect(matches).to.be.not.undefined;
expect(matches.length).to.eq(2);
});

it('should ignore globs passed through the search options', async () => {
const rootUri = FileUri.create(path.resolve(__dirname, '../../test-resources/subdir1/sub2')).toString();

const matches = await service.find('foo', { rootUris: [rootUri], defaultIgnorePatterns: ['foo'] });
expect(matches).to.be.not.undefined;
expect(matches.length).to.eq(0);
});
});
38 changes: 29 additions & 9 deletions packages/file-search/src/node/file-search-service-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,14 @@ export class FileSearchServiceImpl implements FileSearchService {
limit: Number.MAX_SAFE_INTEGER,
useGitIgnore: true,
defaultIgnorePatterns: [
'^.git$'
'.git'
],
...options
};
const args: string[] = [
'--files',
'--sort-files',
];
if (!options.useGitIgnore) {
args.push('-uu');
}

const process = this.rawProcessFactory({
command: rgPath,
args: [...args, ...opts.rootUris.map(r => FileUri.fsPath(r))]
args: this.getSearchArgs(opts)
});
const result: string[] = [];
const fuzzyMatches: string[] = [];
Expand Down Expand Up @@ -94,4 +88,30 @@ export class FileSearchServiceImpl implements FileSearchService {
return resultDeferred.promise;
}

private getSearchArgs(options: FileSearchService.Options): string[] {
const args: string[] = [
'--sort-files'
];
if (!options.useGitIgnore) {
args.push('-uu');
}
if (options && options.defaultIgnorePatterns) {
options.defaultIgnorePatterns.filter(p => p !== '')
.forEach(ignore => {
if (!ignore.endsWith('*')) {
ignore = `${ignore}*`;
}
if (!ignore.startsWith('*')) {
ignore = `!*${ignore}`;
} else {
ignore = `!${ignore}`;
}
args.push('--glob');
args.push(ignore);
});
}
args.push('--files');
args.push(...options.rootUris.map(r => FileUri.fsPath(r)));
return args;
}
}
9 changes: 8 additions & 1 deletion packages/plugin-ext/src/main/browser/workspace-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,14 @@ export class WorkspaceMainImpl implements WorkspaceMain {

async $startFileSearch(includePattern: string, excludePatternOrDisregardExcludes?: string | false,
maxResults?: number, token?: theia.CancellationToken): Promise<UriComponents[]> {
const uriStrs = await this.fileSearchService.find(includePattern, { rootUris: this.roots.map(r => r.uri) });
const opts: FileSearchService.Options = { rootUris: this.roots.map(r => r.uri) };
if (typeof excludePatternOrDisregardExcludes === 'string') {
opts.defaultIgnorePatterns = [excludePatternOrDisregardExcludes];
}
if (typeof maxResults === 'number') {
opts.limit = maxResults;
}
const uriStrs = await this.fileSearchService.find(includePattern, opts);
return uriStrs.map(uriStr => Uri.parse(uriStr));
}

Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-ext/src/plugin/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ export function createAPIFactory(
};

const workspace: typeof theia.workspace = {
get rootPath(): string | undefined {
get rootPath(): string | undefined {
return workspaceExt.rootPath;
},
get workspaceFolders(): theia.WorkspaceFolder[] | undefined {
Expand Down Expand Up @@ -418,7 +418,7 @@ export function createAPIFactory(
return workspaceExt.createFileSystemWatcher(globPattern, ignoreCreateEvents, ignoreChangeEvents, ignoreDeleteEvents);
},
findFiles(include: theia.GlobPattern, exclude?: theia.GlobPattern | undefined, maxResults?: number, token?: CancellationToken): PromiseLike<Uri[]> {
return workspaceExt.findFiles(include, undefined, maxResults, token);
return workspaceExt.findFiles(include, exclude, maxResults, token);
},
applyEdit(edit: theia.WorkspaceEdit): PromiseLike<boolean> {
return editors.applyWorkspaceEdit(edit);
Expand Down

0 comments on commit 6e54f3c

Please sign in to comment.