1
1
import * as vscode from "vscode" ;
2
2
3
3
import { Client } from "./client" ;
4
- import { registerCommands } from "./commands" ;
4
+ import {
5
+ registerEnablementCommands ,
6
+ registerLanguageCommands ,
7
+ } from "./commands" ;
5
8
import { setupStatusBar } from "./statusBar" ;
9
+ import { needsExtHostRestartOnChange } from "./util" ;
6
10
import { setupVersionStatusItem } from "./versionStatusItem" ;
7
11
8
12
export async function activate ( context : vscode . ExtensionContext ) {
9
13
await vscode . commands . executeCommand ( "setContext" , "typescript.native-preview.serverRunning" , false ) ;
10
-
14
+ registerEnablementCommands ( context ) ;
11
15
const output = vscode . window . createOutputChannel ( "typescript-native-preview" , "log" ) ;
12
16
const traceOutput = vscode . window . createOutputChannel ( "typescript-native-preview (LSP)" ) ;
13
- const client = new Client ( output , traceOutput ) ;
14
- registerCommands ( context , client , output , traceOutput ) ;
17
+ context . subscriptions . push ( output , traceOutput ) ;
15
18
16
- context . subscriptions . push ( vscode . workspace . onDidChangeConfiguration ( event => {
19
+ let disposeLanguageFeatures : vscode . Disposable | undefined ;
20
+
21
+ context . subscriptions . push ( vscode . workspace . onDidChangeConfiguration ( async event => {
17
22
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" ) ;
23
+ if ( needsExtHostRestartOnChange ( ) ) {
24
+ // Delay because the command to change the config setting will restart
25
+ // the extension host, so no need to show a message
26
+ setTimeout ( async ( ) => {
27
+ const selected = await vscode . window . showInformationMessage ( "TypeScript Native Preview setting has changed. Restart extensions to apply changes." , "Restart Extensions" ) ;
28
+ if ( selected ) {
29
+ vscode . commands . executeCommand ( "workbench.action.restartExtensionHost" ) ;
30
+ }
31
+ } , 100 ) ;
32
+ }
33
+ else {
34
+ const useTsgo = vscode . workspace . getConfiguration ( "typescript" ) . get < boolean > ( "experimental.useTsgo" ) ;
35
+ if ( useTsgo ) {
36
+ disposeLanguageFeatures = await activateLanguageFeatures ( context , output , traceOutput ) ;
37
+ context . subscriptions . push ( disposeLanguageFeatures ) ;
24
38
}
25
- } , 100 ) ;
39
+ else {
40
+ disposeLanguageFeatures ?. dispose ( ) ;
41
+ disposeLanguageFeatures = undefined ;
42
+ }
43
+ }
26
44
}
27
45
} ) ) ;
28
46
@@ -41,10 +59,17 @@ export async function activate(context: vscode.ExtensionContext) {
41
59
}
42
60
}
43
61
44
- await client . initialize ( context ) ;
45
- setupStatusBar ( context ) ;
46
- setupVersionStatusItem ( context , client ) ;
62
+ disposeLanguageFeatures = await activateLanguageFeatures ( context , output , traceOutput ) ;
63
+ context . subscriptions . push ( disposeLanguageFeatures ) ;
47
64
}
48
65
49
- export async function deactivate ( ) : Promise < void > {
66
+ async function activateLanguageFeatures ( context : vscode . ExtensionContext , output : vscode . OutputChannel , traceOutput : vscode . OutputChannel ) : Promise < vscode . Disposable > {
67
+ const disposables : vscode . Disposable [ ] = [ ] ;
68
+
69
+ const client = new Client ( output , traceOutput ) ;
70
+ disposables . push ( ...registerLanguageCommands ( context , client , output , traceOutput ) ) ;
71
+ disposables . push ( await client . initialize ( context ) ) ;
72
+ disposables . push ( setupStatusBar ( ) ) ;
73
+ disposables . push ( ...setupVersionStatusItem ( client ) ) ;
74
+ return vscode . Disposable . from ( ...disposables ) ;
50
75
}
0 commit comments