Skip to content

Commit

Permalink
⚡️ Switch to picomatch to improve exclude performance
Browse files Browse the repository at this point in the history
  • Loading branch information
misode committed Jan 3, 2025
1 parent da865cd commit 468a27f
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 48 deletions.
70 changes: 35 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"chokidar": "^3.5.2",
"decompress": "^4.2.1",
"follow-redirects": "^1.14.8",
"micromatch": "^4.0.8",
"picomatch": "^4.0.2",
"pako": "^2.0.4",
"rfdc": "^1.3.0",
"vscode-languageserver-textdocument": "^1.0.4",
Expand All @@ -28,7 +28,7 @@
"devDependencies": {
"@types/decompress": "^4.2.3",
"@types/follow-redirects": "^1.14.1",
"@types/micromatch": "^4.0.9",
"@types/picomatch": "^3.0.1",
"@types/pako": "^2.0.0",
"@types/whatwg-url": "^11.0.4"
},
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/service/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,11 @@ export const VanillaConfig: Config = {
env: {
dataSource: 'GitHub',
dependencies: ['@vanilla-datapack', '@vanilla-resourcepack', '@vanilla-mcdoc'],
exclude: ['.*/**'],
exclude: [
'/.*/',
'/node_modules/',
'/__pycache__/',
],
customResources: {},
feature: {
codeActions: true,
Expand Down
11 changes: 1 addition & 10 deletions packages/core/src/service/Project.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as micromatch from 'micromatch'
import type { TextDocumentContentChangeEvent } from 'vscode-languageserver-textdocument'
import { TextDocument } from 'vscode-languageserver-textdocument'
import type { ExternalEventEmitter, Externals, FsWatcher, IntervalId } from '../common/index.js'
Expand Down Expand Up @@ -968,15 +967,7 @@ export class Project implements ExternalEventEmitter {
}

public shouldExclude(uri: string): boolean {
if (this.config.env.exclude.length === 0) {
return false
}
for (const rel of fileUtil.getRels(uri, this.projectRoots)) {
if (micromatch.any(rel, this.config.env.exclude)) {
return true
}
}
return false
return fileUtil.match(this.config.env.exclude, uri)
}

private tryClearingCache(uri: string): void {
Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/service/fileUtil.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import picomatch from 'picomatch'
import type { Externals, FsLocation } from '../common/index.js'
import { bufferToString, Uri } from '../common/index.js'

Expand Down Expand Up @@ -109,6 +110,15 @@ export namespace fileUtil {
return uri.startsWith('file:')
}

export function match(patterns: string[], uri: string) {
const options: picomatch.PicomatchOptions = {
contains: true,
dot: true,
posixSlashes: false,
}
return picomatch(patterns, options)(uri)
}

/**
* @returns The part from the last `.` to the end of the URI, or `undefined` if no dots exist. No special treatment for leading dots.
*/
Expand Down

0 comments on commit 468a27f

Please sign in to comment.