Skip to content

Commit

Permalink
simplify how exclude are matched against each file
Browse files Browse the repository at this point in the history
  • Loading branch information
edmundhung committed Aug 23, 2024
1 parent 3128582 commit 35b63ae
Showing 1 changed file with 10 additions and 25 deletions.
35 changes: 10 additions & 25 deletions packages/quick-edit-extension/src/cfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,36 +539,21 @@ declare module "*.bin" {
: null;

// The memfs implementation does not support the `files.exclude` and `search.exclude` settings
// This implements a simple mechanism to filter out files by just matching the filename
// which does not take into account the full path of the file
const excludePatterns = excludes.reduce<Array<RegExp>>(
(patterns, exclude) => {
if (exclude) {
const lastSlashIndex = exclude.lastIndexOf("/");
// Excludes might include a glob pattern, e.g. `**/*.js`
// As we are only comparing the filename, we need to make sure the file path is stripped
// This makes the final RegExp /.*\.js/
const filenamePattern = new RegExp(
this._convertSimple2RegExpPattern(
lastSlashIndex !== -1
? exclude.substring(lastSlashIndex + 1)
: exclude
)
);

patterns.push(filenamePattern);
}
// 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 patterns;
},
[]
);
return new RegExp(this._convertSimple2RegExpPattern(exclude));
});

for (const file of files) {
if (
(!pattern || pattern.exec(file.name)) &&
// Ensure the file name is not excluded
excludePatterns.every((regex) => !regex.exec(file.name))
// Ensure the file is not excluded
!excludePatterns.some((regex) => regex?.exec(file.uri.path))
) {
result.push(file.uri);
}
Expand Down

0 comments on commit 35b63ae

Please sign in to comment.