From 0d07e990c6f015c295e1905643b1257d06a24475 Mon Sep 17 00:00:00 2001 From: Mark Sujew Date: Mon, 28 Oct 2024 15:47:37 +0100 Subject: [PATCH] Include ignored files in `vscode.workspace.findFiles` --- .../plugin-ext/src/common/plugin-api-rpc.ts | 12 +++++++-- .../src/main/browser/workspace-main.ts | 18 ++++++------- packages/plugin-ext/src/plugin/workspace.ts | 27 ++++++++++--------- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/packages/plugin-ext/src/common/plugin-api-rpc.ts b/packages/plugin-ext/src/common/plugin-api-rpc.ts index 7c21c72086927..8a549b7e4f840 100644 --- a/packages/plugin-ext/src/common/plugin-api-rpc.ts +++ b/packages/plugin-ext/src/common/plugin-api-rpc.ts @@ -743,10 +743,18 @@ export interface QuickOpenMain { $showInputBox(options: TransferInputBox, validateInput: boolean): Promise; } +export interface FindFilesOptions { + exclude?: string; + useDefaultExcludes?: boolean; + useDefaultSearchExcludes?: boolean; + maxResults?: number; + useIgnoreFiles?: boolean; + fuzzy?: boolean; +} + export interface WorkspaceMain { $pickWorkspaceFolder(options: WorkspaceFolderPickOptionsMain): Promise; - $startFileSearch(includePattern: string, includeFolder: string | undefined, excludePatternOrDisregardExcludes: string | false, - maxResults: number | undefined, token: theia.CancellationToken): PromiseLike; + $startFileSearch(includePattern: string, includeFolder: string | undefined, options: FindFilesOptions, token: theia.CancellationToken): PromiseLike; $findTextInFiles(query: theia.TextSearchQuery, options: theia.FindTextInFilesOptions, searchRequestId: number, token?: theia.CancellationToken): Promise $registerTextDocumentContentProvider(scheme: string): Promise; diff --git a/packages/plugin-ext/src/main/browser/workspace-main.ts b/packages/plugin-ext/src/main/browser/workspace-main.ts index f6fe0a9e73b9b..41d027ba6bde6 100644 --- a/packages/plugin-ext/src/main/browser/workspace-main.ts +++ b/packages/plugin-ext/src/main/browser/workspace-main.ts @@ -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'; @@ -169,8 +169,7 @@ export class WorkspaceMainImpl implements WorkspaceMain, Disposable { }); } - async $startFileSearch(includePattern: string, includeFolderUri: string | undefined, excludePatternOrDisregardExcludes?: string | false, - maxResults?: number): Promise { + async $startFileSearch(includePattern: string, includeFolderUri: string | undefined, options: FindFilesOptions): Promise { const roots: FileSearchService.RootOptions = {}; const rootUris = includeFolderUri ? [includeFolderUri] : this.roots; for (const rootUri of rootUris) { @@ -178,15 +177,16 @@ export class WorkspaceMainImpl implements WorkspaceMain, Disposable { } 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) { @@ -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)); diff --git a/packages/plugin-ext/src/plugin/workspace.ts b/packages/plugin-ext/src/plugin/workspace.ts index 9f8a1d812193d..2645f30e4f84b 100644 --- a/packages/plugin-ext/src/plugin/workspace.ts +++ b/packages/plugin-ext/src/plugin/workspace.ts @@ -188,8 +188,7 @@ export class WorkspaceExtImpl implements WorkspaceExt { }); } - findFiles(include: theia.GlobPattern, exclude?: theia.GlobPattern | null, maxResults?: number, - token: CancellationToken = CancellationToken.None): PromiseLike { + findFiles(include: theia.GlobPattern, exclude?: theia.GlobPattern | null, maxResults?: number, token: CancellationToken = CancellationToken.None): PromiseLike { let includePattern: string; let includeFolderUri: string | undefined; if (include) { @@ -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),