1
1
/* eslint-disable @typescript-eslint/no-require-imports */
2
2
import * as vscode from 'vscode'
3
3
import { defaultJsSupersetLangs } from '@zardoy/vscode-utils/build/langs'
4
- import { extensionCtx , getExtensionSettingId } from 'vscode-framework'
4
+ import { extensionCtx , getExtensionSetting , getExtensionSettingId } from 'vscode-framework'
5
5
import { pickObj } from '@zardoy/utils'
6
+ import { watchExtensionSettings } from '@zardoy/vscode-utils/build/settings'
6
7
import { Configuration } from './configurationType'
7
8
import webImports from './webImports'
8
9
import { sendCommand } from './sendCommand'
@@ -15,10 +16,16 @@ import specialCommands from './specialCommands'
15
16
import vueVolarSupport from './vueVolarSupport'
16
17
import moreCompletions from './moreCompletions'
17
18
18
- export const activateTsPlugin = ( tsApi : { configurePlugin ; onCompletionAccepted } ) => {
19
+ let isActivated = false
20
+ // let erroredStatusBarItem: vscode.StatusBarItem | undefined
21
+
22
+ export const activateTsPlugin = ( tsApi : { configurePlugin ; onCompletionAccepted } | undefined ) => {
23
+ if ( isActivated ) return
24
+ isActivated = true
19
25
let webWaitingForConfigSync = false
20
26
21
27
const syncConfig = ( ) => {
28
+ if ( ! tsApi ) return
22
29
console . log ( 'sending configure request for typescript-essential-plugins' )
23
30
const config = vscode . workspace . getConfiguration ( ) . get ( process . env . IDS_PREFIX ! )
24
31
@@ -48,7 +55,7 @@ export const activateTsPlugin = (tsApi: { configurePlugin; onCompletionAccepted
48
55
} )
49
56
syncConfig ( )
50
57
51
- onCompletionAccepted ( tsApi )
58
+ if ( tsApi ) onCompletionAccepted ( tsApi )
52
59
53
60
if ( process . env . PLATFORM === 'web' ) {
54
61
const possiblySyncConfig = async ( ) => {
@@ -79,24 +86,47 @@ export const activate = async () => {
79
86
80
87
const possiblyActivateTsPlugin = async ( ) => {
81
88
const tsExtension = vscode . extensions . getExtension ( 'vscode.typescript-language-features' )
82
- if ( ! tsExtension ) return
89
+ if ( tsExtension ) {
90
+ await tsExtension . activate ( )
91
+
92
+ if ( ! tsExtension . exports || ! tsExtension . exports . getAPI ) {
93
+ throw new Error ( "TS extension doesn't export API" )
94
+ }
95
+
96
+ // Get the API from the TS extension
97
+ const api = tsExtension . exports . getAPI ( 0 )
98
+ if ( ! api ) {
99
+ throw new Error ( "TS extension doesn't have API" )
100
+ }
83
101
84
- await tsExtension . activate ( )
102
+ activateTsPlugin ( api )
103
+ return true
104
+ }
85
105
86
- if ( ! tsExtension . exports || ! tsExtension . exports . getAPI ) return
106
+ if ( vscode . extensions . getExtension ( 'Vue.volar' ) && getExtensionSetting ( 'enableVueSupport' ) ) {
107
+ activateTsPlugin ( undefined )
108
+ return true
109
+ }
87
110
88
- // Get the API from the TS extension
89
- const api = tsExtension . exports . getAPI ( 0 )
90
- if ( ! api ) return
91
- activateTsPlugin ( api )
92
- return true
111
+ return false
93
112
}
94
113
95
114
const isActivated = ( await possiblyActivateTsPlugin ( ) ) ?? false
96
115
if ( ! isActivated ) {
97
- // can be also used in future, for now only when activating TS extension manually
98
- const { dispose } = vscode . extensions . onDidChange ( async ( ) => {
99
- if ( await possiblyActivateTsPlugin ( ) ) dispose ( )
116
+ // can be also used in future, for now only when activating TS or Volar extension manually
117
+ const disposables = [ ]
118
+ const { dispose } = vscode . extensions . onDidChange (
119
+ async ( ) => {
120
+ if ( await possiblyActivateTsPlugin ( ) ) dispose ( )
121
+ } ,
122
+ undefined ,
123
+ disposables ,
124
+ )
125
+ watchExtensionSettings ( [ 'enableVueSupport' ] , async ( ) => {
126
+ if ( await possiblyActivateTsPlugin ( ) ) {
127
+ // todo
128
+ // disposables.forEach(d => d.dispose())
129
+ }
100
130
} )
101
131
}
102
132
}
0 commit comments