@@ -8,18 +8,7 @@ import throttle from 'lodash.throttle'
88import { PostfixCompletion , TriggerCharacterCommand } from '../typescript/src/ipcTypes'
99import { Configuration } from './configurationType'
1010
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 } ) => {
2312 const syncConfig = ( ) => {
2413 console . log ( 'sending configure request for typescript-essential-plugins' )
2514 const config = vscode . workspace . getConfiguration ( ) . get ( process . env . IDS_PREFIX ! )
@@ -32,7 +21,7 @@ export const activate = async () => {
3221 )
3322 }
3423
35- api . configurePlugin ( 'typescript-essential-plugins' , config )
24+ tsApi . configurePlugin ( 'typescript-essential-plugins' , config )
3625 }
3726
3827 vscode . workspace . onDidChangeConfiguration ( async ( { affectsConfiguration } ) => {
@@ -46,7 +35,7 @@ export const activate = async () => {
4635 } )
4736 syncConfig ( )
4837
49- api . onCompletionAccepted ( ( item : vscode . CompletionItem & { document : vscode . TextDocument } ) => {
38+ tsApi . onCompletionAccepted ( ( item : vscode . CompletionItem & { document : vscode . TextDocument } ) => {
5039 const enableMethodSnippets = vscode . workspace . getConfiguration ( process . env . IDS_PREFIX , item . document ) . get ( 'enableMethodSnippets' )
5140 const { documentation = '' } = item
5241 const documentationString = documentation instanceof vscode . MarkdownString ? documentation . value : documentation
@@ -216,3 +205,28 @@ export const activate = async () => {
216205 )
217206 }
218207}
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