Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include ignored files in vscode.workspace.findFiles #14365

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/plugin-ext/src/common/plugin-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -743,10 +743,18 @@ export interface QuickOpenMain {
$showInputBox(options: TransferInputBox, validateInput: boolean): Promise<string | undefined>;
}

export interface FindFilesOptions {
exclude?: string;
useDefaultExcludes?: boolean;
useDefaultSearchExcludes?: boolean;
maxResults?: number;
useIgnoreFiles?: boolean;
fuzzy?: boolean;
}

export interface WorkspaceMain {
$pickWorkspaceFolder(options: WorkspaceFolderPickOptionsMain): Promise<theia.WorkspaceFolder | undefined>;
$startFileSearch(includePattern: string, includeFolder: string | undefined, excludePatternOrDisregardExcludes: string | false,
maxResults: number | undefined, token: theia.CancellationToken): PromiseLike<UriComponents[]>;
$startFileSearch(includePattern: string, includeFolder: string | undefined, options: FindFilesOptions, token: theia.CancellationToken): PromiseLike<UriComponents[]>;
$findTextInFiles(query: theia.TextSearchQuery, options: theia.FindTextInFilesOptions, searchRequestId: number,
token?: theia.CancellationToken): Promise<theia.TextSearchComplete>
$registerTextDocumentContentProvider(scheme: string): Promise<void>;
Expand Down
18 changes: 9 additions & 9 deletions packages/plugin-ext/src/main/browser/workspace-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import * as theia from '@theia/plugin';
import { interfaces, injectable } from '@theia/core/shared/inversify';
import { WorkspaceExt, StorageExt, MAIN_RPC_CONTEXT, WorkspaceMain, WorkspaceFolderPickOptionsMain } from '../../common/plugin-api-rpc';
import { WorkspaceExt, StorageExt, MAIN_RPC_CONTEXT, WorkspaceMain, WorkspaceFolderPickOptionsMain, FindFilesOptions } from '../../common/plugin-api-rpc';
import { RPCProtocol } from '../../common/rpc-protocol';
import { URI as Uri } from '@theia/core/shared/vscode-uri';
import { UriComponents } from '../../common/uri-components';
Expand Down Expand Up @@ -169,24 +169,24 @@ export class WorkspaceMainImpl implements WorkspaceMain, Disposable {
});
}

async $startFileSearch(includePattern: string, includeFolderUri: string | undefined, excludePatternOrDisregardExcludes?: string | false,
maxResults?: number): Promise<UriComponents[]> {
async $startFileSearch(includePattern: string, includeFolderUri: string | undefined, options: FindFilesOptions): Promise<UriComponents[]> {
const roots: FileSearchService.RootOptions = {};
const rootUris = includeFolderUri ? [includeFolderUri] : this.roots;
for (const rootUri of rootUris) {
roots[rootUri] = {};
}
const opts: FileSearchService.Options = {
rootOptions: roots,
useGitIgnore: excludePatternOrDisregardExcludes !== false
fuzzyMatch: options.fuzzy,
useGitIgnore: options.useIgnoreFiles
};
if (includePattern) {
opts.includePatterns = [includePattern];
}
if (typeof excludePatternOrDisregardExcludes === 'string') {
opts.excludePatterns = [excludePatternOrDisregardExcludes];
if (options.exclude) {
opts.excludePatterns = [options.exclude];
}
if (excludePatternOrDisregardExcludes !== false) {
if (options.useDefaultExcludes) {
for (const rootUri of rootUris) {
const filesExclude = this.fsPreferences.get('files.exclude', undefined, rootUri);
if (filesExclude) {
Expand All @@ -201,8 +201,8 @@ export class WorkspaceMainImpl implements WorkspaceMain, Disposable {
}
}
}
if (typeof maxResults === 'number') {
opts.limit = maxResults;
if (typeof options.maxResults === 'number') {
opts.limit = options.maxResults;
}
const uriStrs = await this.fileSearchService.find('', opts);
return uriStrs.map(uriStr => Uri.parse(uriStr));
Expand Down
27 changes: 15 additions & 12 deletions packages/plugin-ext/src/plugin/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ export class WorkspaceExtImpl implements WorkspaceExt {
});
}

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

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

if (token && token.isCancellationRequested) {
return Promise.resolve([]);
}

return this.proxy.$startFileSearch(includePattern, includeFolderUri, excludePatternOrDisregardExcludes, maxResults, token)
.then(data => Array.isArray(data) ? data.map(uri => URI.revive(uri)) : []);
return this.proxy.$startFileSearch(includePattern, includeFolderUri, {
maxResults,
exclude: excludeString,
useDefaultExcludes: useFileExcludes,
useDefaultSearchExcludes: false,
useIgnoreFiles: false
}, token).then(data => Array.isArray(data) ? data.map(uri => URI.revive(uri)) : []);
}

findTextInFiles(query: theia.TextSearchQuery, optionsOrCallback: theia.FindTextInFilesOptions | ((result: theia.TextSearchResult) => void),
Expand Down
Loading