Skip to content

Commit

Permalink
Include ignored files in vscode.workspace.findFiles
Browse files Browse the repository at this point in the history
  • Loading branch information
msujew committed Oct 28, 2024
1 parent bcf96a3 commit 0d07e99
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 23 deletions.
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

0 comments on commit 0d07e99

Please sign in to comment.