11/* eslint-disable @typescript-eslint/no-require-imports */ 
22import  *  as  vscode  from  'vscode' 
33import  {  defaultJsSupersetLangs  }  from  '@zardoy/vscode-utils/build/langs' 
4- import  {  extensionCtx ,  getExtensionSettingId  }  from  'vscode-framework' 
4+ import  {  extensionCtx ,  getExtensionSetting ,   getExtensionSettingId  }  from  'vscode-framework' 
55import  {  pickObj  }  from  '@zardoy/utils' 
6+ import  {  watchExtensionSettings  }  from  '@zardoy/vscode-utils/build/settings' 
67import  {  Configuration  }  from  './configurationType' 
78import  webImports  from  './webImports' 
89import  {  sendCommand  }  from  './sendCommand' 
910import  {  registerEmmet  }  from  './emmet' 
10- import  experimentalPostfixes  from  './experimentalPostfixes' 
1111import  migrateSettings  from  './migrateSettings' 
1212import  figIntegration  from  './figIntegration' 
1313import  apiCommands  from  './apiCommands' 
@@ -16,13 +16,21 @@ import specialCommands from './specialCommands'
1616import  vueVolarSupport  from  './vueVolarSupport' 
1717import  moreCompletions  from  './moreCompletions' 
1818
19- 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 
2025    let  webWaitingForConfigSync  =  false 
2126
2227    const  syncConfig  =  ( )  =>  { 
28+         if  ( ! tsApi )  return 
2329        console . log ( 'sending configure request for typescript-essential-plugins' ) 
2430        const  config  =  vscode . workspace . getConfiguration ( ) . get ( process . env . IDS_PREFIX ! ) 
2531
32+         tsApi . configurePlugin ( 'typescript-essential-plugins' ,  config ) 
33+ 
2634        if  ( process . env . PLATFORM  ===  'node' )  { 
2735            // see comment in plugin 
2836            require ( 'fs' ) . writeFileSync ( 
@@ -31,8 +39,6 @@ export const activateTsPlugin = (tsApi: { configurePlugin; onCompletionAccepted
3139            ) 
3240        } 
3341
34-         tsApi . configurePlugin ( 'typescript-essential-plugins' ,  config ) 
35- 
3642        if  ( process . env . PLATFORM  ===  'web' )  { 
3743            webWaitingForConfigSync  =  true 
3844        } 
@@ -49,7 +55,7 @@ export const activateTsPlugin = (tsApi: { configurePlugin; onCompletionAccepted
4955    } ) 
5056    syncConfig ( ) 
5157
52-     onCompletionAccepted ( tsApi ) 
58+     if   ( tsApi )   onCompletionAccepted ( tsApi ) 
5359
5460    if  ( process . env . PLATFORM  ===  'web' )  { 
5561        const  possiblySyncConfig  =  async  ( )  =>  { 
@@ -65,7 +71,6 @@ export const activateTsPlugin = (tsApi: { configurePlugin; onCompletionAccepted
6571        void  possiblySyncConfig ( ) 
6672    } 
6773
68-     experimentalPostfixes ( ) 
6974    moreCompletions ( ) 
7075    void  registerEmmet ( ) 
7176    webImports ( ) 
@@ -81,24 +86,47 @@ export const activate = async () => {
8186
8287    const  possiblyActivateTsPlugin  =  async  ( )  =>  { 
8388        const  tsExtension  =  vscode . extensions . getExtension ( 'vscode.typescript-language-features' ) 
84-         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+             } 
85101
86-         await  tsExtension . activate ( ) 
102+             activateTsPlugin ( api ) 
103+             return  true 
104+         } 
87105
88-         if  ( ! tsExtension . exports  ||  ! tsExtension . exports . getAPI )  return 
106+         if  ( vscode . extensions . getExtension ( 'Vue.volar' )  &&  getExtensionSetting ( 'enableVueSupport' ) )  { 
107+             activateTsPlugin ( undefined ) 
108+             return  true 
109+         } 
89110
90-         // Get the API from the TS extension 
91-         const  api  =  tsExtension . exports . getAPI ( 0 ) 
92-         if  ( ! api )  return 
93-         activateTsPlugin ( api ) 
94-         return  true 
111+         return  false 
95112    } 
96113
97114    const  isActivated  =  ( await  possiblyActivateTsPlugin ( ) )  ??  false 
98115    if  ( ! isActivated )  { 
99-         // can be also used in future, for now only when activating TS extension manually 
100-         const  {  dispose }  =  vscode . extensions . onDidChange ( async  ( )  =>  { 
101-             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+             } 
102130        } ) 
103131    } 
104132} 
0 commit comments