Skip to content

Commit

Permalink
⚡️ Reuse matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
misode committed Jan 3, 2025
1 parent 468a27f commit dc1df6a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions packages/core/src/service/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ export class Project implements ExternalEventEmitter {
return this.#cacheRoot
}

#excludeMatcher: (uri: string) => boolean = () => false
get shouldExclude() {
return this.#excludeMatcher
}

private updateRoots(): void {
const rawRoots = [...this.#dependencyRoots ?? [], ...this.projectRoots]
const ans = new Set(rawRoots)
Expand Down Expand Up @@ -425,6 +430,7 @@ export class Project implements ExternalEventEmitter {
__profiler.task('Load Cache')

this.config = await this.#configService.load()
this.#excludeMatcher = fileUtil.createMatcher(this.config.env.exclude)
__profiler.task('Load Config')

await callIntializers()
Expand Down Expand Up @@ -966,10 +972,6 @@ export class Project implements ExternalEventEmitter {
}
}

public shouldExclude(uri: string): boolean {
return fileUtil.match(this.config.env.exclude, uri)
}

private tryClearingCache(uri: string): void {
if (this.shouldRemove(uri)) {
this.removeCachedTextDocument(uri)
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/service/fileUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ export namespace fileUtil {
return uri.startsWith('file:')
}

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

/**
Expand Down

0 comments on commit dc1df6a

Please sign in to comment.