11import * as vscode from "vscode" ;
22
33import { Client } from "./client" ;
4- import { registerCommands } from "./commands" ;
4+ import {
5+ registerEnablementCommands ,
6+ registerLanguageCommands ,
7+ } from "./commands" ;
58import { setupStatusBar } from "./statusBar" ;
69import { setupVersionStatusItem } from "./versionStatusItem" ;
710
811export async function activate ( context : vscode . ExtensionContext ) {
912 await vscode . commands . executeCommand ( "setContext" , "typescript.native-preview.serverRunning" , false ) ;
10-
13+ registerEnablementCommands ( context ) ;
1114 const output = vscode . window . createOutputChannel ( "typescript-native-preview" , "log" ) ;
1215 const traceOutput = vscode . window . createOutputChannel ( "typescript-native-preview (LSP)" ) ;
13- const client = new Client ( output , traceOutput ) ;
14- registerCommands ( context , client , output , traceOutput ) ;
16+ context . subscriptions . push ( output , traceOutput ) ;
1517
16- context . subscriptions . push ( vscode . workspace . onDidChangeConfiguration ( event => {
18+ const majorVersion = parseInt ( vscode . version . split ( "." ) [ 0 ] ) ;
19+ const minorVersion = parseInt ( vscode . version . split ( "." ) [ 1 ] ) ;
20+ const needsExtHostRestartOnChange = majorVersion <= 1 && minorVersion < 105 ;
21+ let disposeLanguageFeatures : vscode . Disposable | undefined ;
22+
23+ context . subscriptions . push ( vscode . workspace . onDidChangeConfiguration ( async event => {
1724 if ( event . affectsConfiguration ( "typescript.experimental.useTsgo" ) ) {
18- // Delay because the command to change the config setting will restart
19- // the extension host, so no need to show a message
20- setTimeout ( async ( ) => {
21- const selected = await vscode . window . showInformationMessage ( "TypeScript Native Preview setting has changed. Restart extensions to apply changes." , "Restart Extensions" ) ;
22- if ( selected ) {
23- vscode . commands . executeCommand ( "workbench.action.restartExtensionHost" ) ;
25+ if ( needsExtHostRestartOnChange ) {
26+ // Delay because the command to change the config setting will restart
27+ // the extension host, so no need to show a message
28+ setTimeout ( async ( ) => {
29+ const selected = await vscode . window . showInformationMessage ( "TypeScript Native Preview setting has changed. Restart extensions to apply changes." , "Restart Extensions" ) ;
30+ if ( selected ) {
31+ vscode . commands . executeCommand ( "workbench.action.restartExtensionHost" ) ;
32+ }
33+ } , 100 ) ;
34+ }
35+ else {
36+ const useTsgo = vscode . workspace . getConfiguration ( "typescript" ) . get < boolean > ( "experimental.useTsgo" ) ;
37+ if ( useTsgo ) {
38+ disposeLanguageFeatures = await activateLanguageFeatures ( context , output , traceOutput ) ;
39+ context . subscriptions . push ( disposeLanguageFeatures ) ;
2440 }
25- } , 100 ) ;
41+ else {
42+ disposeLanguageFeatures ?. dispose ( ) ;
43+ disposeLanguageFeatures = undefined ;
44+ }
45+ }
2646 }
2747 } ) ) ;
2848
@@ -41,10 +61,17 @@ export async function activate(context: vscode.ExtensionContext) {
4161 }
4262 }
4363
44- await client . initialize ( context ) ;
45- setupStatusBar ( context ) ;
46- setupVersionStatusItem ( context , client ) ;
64+ disposeLanguageFeatures = await activateLanguageFeatures ( context , output , traceOutput ) ;
65+ context . subscriptions . push ( disposeLanguageFeatures ) ;
4766}
4867
49- export async function deactivate ( ) : Promise < void > {
68+ async function activateLanguageFeatures ( context : vscode . ExtensionContext , output : vscode . OutputChannel , traceOutput : vscode . OutputChannel ) : Promise < vscode . Disposable > {
69+ const disposables : vscode . Disposable [ ] = [ ] ;
70+
71+ const client = new Client ( output , traceOutput ) ;
72+ disposables . push ( ...registerLanguageCommands ( context , client , output , traceOutput ) ) ;
73+ disposables . push ( await client . initialize ( context ) ) ;
74+ disposables . push ( setupStatusBar ( ) ) ;
75+ disposables . push ( ...setupVersionStatusItem ( client ) ) ;
76+ return vscode . Disposable . from ( ...disposables ) ;
5077}
0 commit comments