diff --git a/.changeset/thin-lies-sparkle.md b/.changeset/thin-lies-sparkle.md new file mode 100644 index 000000000000..42bfbd47255d --- /dev/null +++ b/.changeset/thin-lies-sparkle.md @@ -0,0 +1,5 @@ +--- +"@cloudflare/quick-edit": minor +--- + +feat: hide wrangler.toml and package.json with `search.exclude` support added diff --git a/packages/quick-edit-extension/src/cfs.ts b/packages/quick-edit-extension/src/cfs.ts index e4d7756bf775..85d9c5e707b6 100644 --- a/packages/quick-edit-extension/src/cfs.ts +++ b/packages/quick-edit-extension/src/cfs.ts @@ -527,10 +527,10 @@ declare module "*.bin" { _options: FileSearchOptions, _token: CancellationToken ): ProviderResult { - return this._findFiles(query.pattern); + return this._findFiles(query.pattern, _options.excludes); } - private _findFiles(query: string | undefined): Uri[] { + private _findFiles(query: string | undefined, excludes: string[]): Uri[] { const files = this._getFiles(); const result: Uri[] = []; @@ -538,8 +538,23 @@ declare module "*.bin" { ? new RegExp(this._convertSimple2RegExpPattern(query)) : null; + // The memfs implementation does not support the `files.exclude` and `search.exclude` settings + // This implements a simple mechanism to filter out files by matching against the file path + // e.g. Both `package.json` and `**/package.json` will exclude all files named `package.json` in any folder + const excludePatterns = excludes.map((exclude) => { + if (!exclude) { + return null; + } + + return new RegExp(this._convertSimple2RegExpPattern(exclude)); + }); + for (const file of files) { - if (!pattern || pattern.exec(file.name)) { + if ( + (!pattern || pattern.exec(file.name)) && + // Ensure the file is not excluded + !excludePatterns.some((regex) => regex?.exec(file.uri.path)) + ) { result.push(file.uri); } } @@ -557,7 +572,7 @@ declare module "*.bin" { ) { const result: TextSearchComplete = { limitHit: false }; - const files = this._findFiles(options.includes[0]); + const files = this._findFiles(options.includes[0], options.excludes); if (files) { for (const file of files) { const content = this._textDecoder.decode(await this.readFile(file)); diff --git a/packages/quick-edit/functions/_middleware.ts b/packages/quick-edit/functions/_middleware.ts index d1c87d2c5e89..984e1e598c22 100644 --- a/packages/quick-edit/functions/_middleware.ts +++ b/packages/quick-edit/functions/_middleware.ts @@ -20,6 +20,8 @@ export const onRequest = async ({ "files.exclude": { "*.d.ts": true, "jsconfig.json": true, + "package.json": true, + "wrangler.toml": true, }, "telemetry.telemetryLevel": "off", "window.menuBarVisibility": "hidden",