-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.ts
More file actions
54 lines (45 loc) · 1.82 KB
/
index.ts
File metadata and controls
54 lines (45 loc) · 1.82 KB
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
import { VERSION_TRIGGER_CHARACTERS } from '#constants'
import { defineExtension, useCommands, watchEffect } from 'reactive-vscode'
import { Disposable, languages } from 'vscode'
import { useInternalCommands } from './commands/internal'
import { openFileInNpmx } from './commands/open-file-in-npmx'
import { openInBrowser } from './commands/open-in-browser'
import { extractorEntries } from './extractors'
import { commands, displayName, version } from './generated-meta'
import { useCodeActions } from './providers/code-actions'
import { useCodeLens } from './providers/code-lens'
import { VersionCompletionItemProvider } from './providers/completion-item/version'
import { useDiagnostics } from './providers/diagnostics'
import { NpmxHoverProvider } from './providers/hover/npmx'
import { config, logger } from './state'
export const { activate, deactivate } = defineExtension(() => {
logger.info(`${displayName} Activated, v${version}`)
watchEffect((onCleanup) => {
if (!config.hover.enabled)
return
const disposables = extractorEntries.map(({ pattern, extractor }) =>
languages.registerHoverProvider({ pattern }, new NpmxHoverProvider(extractor)),
)
onCleanup(() => Disposable.from(...disposables).dispose())
})
watchEffect((onCleanup) => {
if (config.completion.version === 'off')
return
const disposables = extractorEntries.map(({ pattern, extractor }) =>
languages.registerCompletionItemProvider(
{ pattern },
new VersionCompletionItemProvider(extractor),
...VERSION_TRIGGER_CHARACTERS,
),
)
onCleanup(() => Disposable.from(...disposables).dispose())
})
useInternalCommands()
useDiagnostics()
useCodeActions()
useCodeLens()
useCommands({
[commands.openInBrowser]: openInBrowser,
[commands.openFileInNpmx]: openFileInNpmx,
})
})