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" ;
6
9
import { setupVersionStatusItem } from "./versionStatusItem" ;
7
10
8
11
export async function activate ( context : vscode . ExtensionContext ) {
9
12
await vscode . commands . executeCommand ( "setContext" , "typescript.native-preview.serverRunning" , false ) ;
10
-
13
+ registerEnablementCommands ( context ) ;
11
14
const output = vscode . window . createOutputChannel ( "typescript-native-preview" , "log" ) ;
12
15
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 ) ;
15
17
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 => {
17
24
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 ) ;
24
40
}
25
- } , 100 ) ;
41
+ else {
42
+ disposeLanguageFeatures ?. dispose ( ) ;
43
+ disposeLanguageFeatures = undefined ;
44
+ }
45
+ }
26
46
}
27
47
} ) ) ;
28
48
@@ -41,10 +61,17 @@ export async function activate(context: vscode.ExtensionContext) {
41
61
}
42
62
}
43
63
44
- await client . initialize ( context ) ;
45
- setupStatusBar ( context ) ;
46
- setupVersionStatusItem ( context , client ) ;
64
+ disposeLanguageFeatures = await activateLanguageFeatures ( context , output , traceOutput ) ;
65
+ context . subscriptions . push ( disposeLanguageFeatures ) ;
47
66
}
48
67
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 ) ;
50
77
}
0 commit comments