From dc1df6acbd36bb44e54187b6d0557dc5971368dd Mon Sep 17 00:00:00 2001 From: Misode Date: Fri, 3 Jan 2025 23:01:35 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Reuse=20matcher?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/service/Project.ts | 10 ++++++---- packages/core/src/service/fileUtil.ts | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/core/src/service/Project.ts b/packages/core/src/service/Project.ts index 4f3b1442c..afbb0e7c1 100644 --- a/packages/core/src/service/Project.ts +++ b/packages/core/src/service/Project.ts @@ -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) @@ -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() @@ -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) diff --git a/packages/core/src/service/fileUtil.ts b/packages/core/src/service/fileUtil.ts index 1527c7718..968d00306 100644 --- a/packages/core/src/service/fileUtil.ts +++ b/packages/core/src/service/fileUtil.ts @@ -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) } /**