Skip to content

Commit

Permalink
feat(quick-edit): add "search.exclude" support to quick editor (#6546)
Browse files Browse the repository at this point in the history
  • Loading branch information
edmundhung committed Sep 9, 2024
1 parent 5936282 commit addb210
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/thin-lies-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudflare/quick-edit": minor
---

feat: hide wrangler.toml and package.json with `search.exclude` support added
23 changes: 19 additions & 4 deletions packages/quick-edit-extension/src/cfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,19 +527,34 @@ declare module "*.bin" {
_options: FileSearchOptions,
_token: CancellationToken
): ProviderResult<Uri[]> {
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[] = [];

const pattern = query
? 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);
}
}
Expand All @@ -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));
Expand Down
2 changes: 2 additions & 0 deletions packages/quick-edit/functions/_middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit addb210

Please sign in to comment.