@@ -8,18 +8,7 @@ import throttle from 'lodash.throttle'
8
8
import { PostfixCompletion , TriggerCharacterCommand } from '../typescript/src/ipcTypes'
9
9
import { Configuration } from './configurationType'
10
10
11
- export const activate = async ( ) => {
12
- const tsExtension = vscode . extensions . getExtension ( 'vscode.typescript-language-features' )
13
- if ( ! tsExtension ) return
14
-
15
- await tsExtension . activate ( )
16
-
17
- if ( ! tsExtension . exports || ! tsExtension . exports . getAPI ) return
18
-
19
- // Get the API from the TS extension
20
- const api = tsExtension . exports . getAPI ( 0 )
21
- if ( ! api ) return
22
-
11
+ export const activateTsPlugin = ( tsApi : { configurePlugin ; onCompletionAccepted } ) => {
23
12
const syncConfig = ( ) => {
24
13
console . log ( 'sending configure request for typescript-essential-plugins' )
25
14
const config = vscode . workspace . getConfiguration ( ) . get ( process . env . IDS_PREFIX ! )
@@ -32,7 +21,7 @@ export const activate = async () => {
32
21
)
33
22
}
34
23
35
- api . configurePlugin ( 'typescript-essential-plugins' , config )
24
+ tsApi . configurePlugin ( 'typescript-essential-plugins' , config )
36
25
}
37
26
38
27
vscode . workspace . onDidChangeConfiguration ( async ( { affectsConfiguration } ) => {
@@ -46,7 +35,7 @@ export const activate = async () => {
46
35
} )
47
36
syncConfig ( )
48
37
49
- api . onCompletionAccepted ( ( item : vscode . CompletionItem & { document : vscode . TextDocument } ) => {
38
+ tsApi . onCompletionAccepted ( ( item : vscode . CompletionItem & { document : vscode . TextDocument } ) => {
50
39
const enableMethodSnippets = vscode . workspace . getConfiguration ( process . env . IDS_PREFIX , item . document ) . get ( 'enableMethodSnippets' )
51
40
const { documentation = '' } = item
52
41
const documentationString = documentation instanceof vscode . MarkdownString ? documentation . value : documentation
@@ -216,3 +205,28 @@ export const activate = async () => {
216
205
)
217
206
}
218
207
}
208
+
209
+ export const activate = async ( ) => {
210
+ const possiblyActivateTsPlugin = async ( ) => {
211
+ const tsExtension = vscode . extensions . getExtension ( 'vscode.typescript-language-features' )
212
+ if ( ! tsExtension ) return
213
+
214
+ await tsExtension . activate ( )
215
+
216
+ if ( ! tsExtension . exports || ! tsExtension . exports . getAPI ) return
217
+
218
+ // Get the API from the TS extension
219
+ const api = tsExtension . exports . getAPI ( 0 )
220
+ if ( ! api ) return
221
+ activateTsPlugin ( api )
222
+ return true
223
+ }
224
+
225
+ const isActivated = ( await possiblyActivateTsPlugin ( ) ) ?? false
226
+ if ( ! isActivated ) {
227
+ // can be also used in future, for now only when activating TS extension manually
228
+ const { dispose } = vscode . extensions . onDidChange ( async ( ) => {
229
+ if ( await possiblyActivateTsPlugin ( ) ) dispose ( )
230
+ } )
231
+ }
232
+ }
0 commit comments