Skip to content

Commit

Permalink
fix(vscode): repeat registration on reload (#3005)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
  • Loading branch information
Jannchie and antfu committed Aug 19, 2023
1 parent 8df256a commit abacd5b
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions packages/vscode/src/index.ts
Expand Up @@ -15,7 +15,6 @@ async function registerRoot(ext: ExtensionContext, status: StatusBarItem, cwd: s
await contextLoader.ready

const hasConfig = await contextLoader.loadContextInDirectory(cwd)
// TODO: improve this to re-enable after configuration created
if (hasConfig) {
registerAutoComplete(cwd, contextLoader, ext)
registerAnnotations(cwd, contextLoader, status, ext)
Expand Down Expand Up @@ -77,19 +76,23 @@ export async function activate(ext: ExtensionContext) {
? path.resolve(projectPath, root)
: projectPath

try {
ext.subscriptions.push(
commands.registerCommand('unocss.reload', async () => {
const contextLoader = await registerRoot(ext, status, cwd)
log.appendLine('🔁 Reloading...')
await contextLoader.reload()
log.appendLine('✅ Reloaded.')
}),
)
}
catch (e: any) {
log.appendLine(String(e.stack ?? e))
}
const contextLoader = await registerRoot(ext, status, cwd)
ext.subscriptions.push(
commands.registerCommand('unocss.reload', async () => {
log.appendLine('🔁 Reloading...')
if (contextLoader.contextsMap.get(cwd) === null) {
contextLoader.contextsMap.delete(cwd)
const hasConfig = await contextLoader.loadContextInDirectory(cwd)
if (hasConfig) {
registerAutoComplete(cwd, contextLoader, ext)
registerAnnotations(cwd, contextLoader, status, ext)
registerSelectionStyle(cwd, contextLoader)
}
}
contextLoader.reload()
log.appendLine('✅ Reloaded.')
}),
)
}

export function deactivate() {}

0 comments on commit abacd5b

Please sign in to comment.