-
-
Notifications
You must be signed in to change notification settings - Fork 779
/
index.ts
55 lines (44 loc) · 1.69 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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) {
log.appendLine(`⚪️ UnoCSS for VS Code v${version}\n`)
const projectPath = workspace.workspaceFolders?.[0].uri.fsPath
if (!projectPath) {
log.appendLine('➖ No active workspace found, UnoCSS is disabled')
return
}
const config = workspace.getConfiguration('unocss')
const disabled = config.get<boolean>('disable', false)
if (disabled) {
log.appendLine('➖ Disabled by configuration')
return
}
const root = config.get<string>('root')
const cwd = root ? path.resolve(projectPath, root) : projectPath
const contextLoader = new ContextLoader(cwd)
ext.subscriptions.push(
commands.registerCommand('unocss.reload', async () => {
log.appendLine('🔁 Reloading...')
await contextLoader.reload()
log.appendLine('✅ Reloaded.')
}),
)
await contextLoader.ready
const hasConfig = await contextLoader.loadContextInDirectory(cwd)
// TODO: improve this to re-enable after configuration created
if (!hasConfig) {
log.appendLine('➖ No config found, UnoCSS is disabled')
return
}
const status = window.createStatusBarItem(StatusBarAlignment.Right, 200)
status.text = 'UnoCSS'
registerAutoComplete(cwd, contextLoader, ext)
registerAnnotations(cwd, contextLoader, status, ext)
}
export function deactivate() {}