Skip to content

Commit

Permalink
perf(vscode): Maximize the hit cache and reduce the use of findup in …
Browse files Browse the repository at this point in the history
…registerUnocss (#3409)
  • Loading branch information
Simon-He95 committed Dec 2, 2023
1 parent a4fcf37 commit edb5d68
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions packages/vscode/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ async function rootRegister(

const cacheFileLookUp = new Set<string>()

const rootCache = new Set<string>()

const watcher = workspace.createFileSystemWatcher('**/{uno,unocss}.config.{js,ts}')

ext.subscriptions.push(watcher.onDidChange(async (uri) => {
Expand All @@ -75,7 +77,9 @@ async function rootRegister(
}))

ext.subscriptions.push(watcher.onDidDelete((uri) => {
ctx.unloadContext(dirname(uri.fsPath))
const dir = dirname(uri.fsPath)
rootCache.delete(dir)
ctx.unloadContext(dir)
cacheFileLookUp.clear()
}))

Expand All @@ -98,23 +102,22 @@ async function rootRegister(
return
}

const dir = path.dirname(url)
if (cacheFileLookUp.has(dir)) {
if ([...rootCache].some(root => url.startsWith(root))) {
// root has been created
cacheFileLookUp.add(url)
return
}

const configUrl = await findUp(configNames, { cwd: url })
if (!configUrl) {
cacheFileLookUp.add(url)

cacheFileLookUp.add(url)

if (!configUrl)
return
}

const cwd = path.dirname(configUrl)
if (cacheFileLookUp.has(cwd))
return
rootCache.add(cwd)

cacheFileLookUp.add(cwd)
await ctx.loadContextInDirectory(cwd)
}

Expand Down

0 comments on commit edb5d68

Please sign in to comment.