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'
@@ -15,10 +16,16 @@ import specialCommands from './specialCommands'
1516import vueVolarSupport from './vueVolarSupport'
1617import moreCompletions from './moreCompletions'
1718
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
1925 let webWaitingForConfigSync = false
2026
2127 const syncConfig = ( ) => {
28+ if ( ! tsApi ) return
2229 console . log ( 'sending configure request for typescript-essential-plugins' )
2330 const config = vscode . workspace . getConfiguration ( ) . get ( process . env . IDS_PREFIX ! )
2431
@@ -48,7 +55,7 @@ export const activateTsPlugin = (tsApi: { configurePlugin; onCompletionAccepted
4855 } )
4956 syncConfig ( )
5057
51- onCompletionAccepted ( tsApi )
58+ if ( tsApi ) onCompletionAccepted ( tsApi )
5259
5360 if ( process . env . PLATFORM === 'web' ) {
5461 const possiblySyncConfig = async ( ) => {
@@ -79,24 +86,47 @@ export const activate = async () => {
7986
8087 const possiblyActivateTsPlugin = async ( ) => {
8188 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+ }
83101
84- await tsExtension . activate ( )
102+ activateTsPlugin ( api )
103+ return true
104+ }
85105
86- if ( ! tsExtension . exports || ! tsExtension . exports . getAPI ) return
106+ if ( vscode . extensions . getExtension ( 'Vue.volar' ) && getExtensionSetting ( 'enableVueSupport' ) ) {
107+ activateTsPlugin ( undefined )
108+ return true
109+ }
87110
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
93112 }
94113
95114 const isActivated = ( await possiblyActivateTsPlugin ( ) ) ?? false
96115 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+ }
100130 } )
101131 }
102132}
0 commit comments