forked from unocss/unocss
/
index.ts
41 lines (31 loc) · 1.3 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import path from 'path'
import type { ExtensionContext } from 'vscode'
import { StatusBarAlignment, commands, window, workspace } from 'vscode'
import { version } from '../package.json'
import { log } from './log'
import { registerAnnotations } from './annotation'
import { registerAutoComplete } from './autocomplete'
import { ContextLoader } from './contextLoader'
export async function activate(ext: ExtensionContext) {
const projectPath = workspace.workspaceFolders?.[0].uri.fsPath
if (!projectPath)
return
const config = workspace.getConfiguration('unocss')
const root = config.get<string>('root')
const cwd = root ? path.resolve(projectPath, root) : projectPath
log.appendLine(`UnoCSS for VS Code v${version} ${process.cwd()}`)
const contextLoader = new ContextLoader(cwd)
const hasConfig = await contextLoader.loadContextInDirectory(cwd)
if (!hasConfig)
return
await contextLoader.ready
const status = window.createStatusBarItem(StatusBarAlignment.Right, 200)
status.text = 'UnoCSS'
registerAutoComplete(cwd, contextLoader, ext)
registerAnnotations(cwd, contextLoader, status, ext)
ext.subscriptions.push(commands.registerCommand('unocss.reload', async () => {
await contextLoader.reload()
log.appendLine('[info] UnoCSS reloaded.')
}))
}
export function deactivate() {}