@@ -10,14 +10,18 @@ import Visualize from "./Visualize";
10
10
11
11
const promiseExec = promisify ( exec ) ;
12
12
13
- // This is the expected top-level export that is called by VSCode.
14
- export function activate ( context : ExtensionContext ) {
13
+ // This object will get initialized once the language client is ready. It will
14
+ // get set back to null when the extension is deactivated.
15
+ let languageClient : LanguageClient | null = null ;
16
+
17
+ // This is the expected top-level export that is called by VSCode when the
18
+ // extension is activated.
19
+ export async function activate ( context : ExtensionContext ) {
15
20
// This output channel is going to contain all of our informational messages.
16
21
// It's not really meant for the end-user, it's more for debugging.
17
22
const outputChannel = window . createOutputChannel ( "Syntax Tree" ) ;
18
23
19
- // These objects will get initialized once the language client is ready.
20
- let languageClient : LanguageClient | null = null ;
24
+ // This object will get initialized once the language client is ready.
21
25
let visualizer : Visualize | null = null ;
22
26
23
27
// This is the list of objects that implement the Disposable interface. They
@@ -46,7 +50,7 @@ export function activate(context: ExtensionContext) {
46
50
47
51
// We're returning a Promise from this function that will start the Ruby
48
52
// subprocess.
49
- return startLanguageServer ( ) ;
53
+ await startLanguageServer ( ) ;
50
54
51
55
// This function is called when the extension is activated or when the
52
56
// language server is restarted.
@@ -110,8 +114,7 @@ export function activate(context: ExtensionContext) {
110
114
} ) ;
111
115
112
116
// Here we're going to wait for the language server to start.
113
- context . subscriptions . push ( languageClient . start ( ) ) ;
114
- await languageClient . onReady ( ) ;
117
+ await languageClient . start ( ) ;
115
118
116
119
// Finally, now that the language server has been properly started, we can
117
120
// add the various features to the extension. Each of them in turn
@@ -142,3 +145,10 @@ export function activate(context: ExtensionContext) {
142
145
await startLanguageServer ( ) ;
143
146
}
144
147
}
148
+
149
+ // This is the expected top-level export that is called by VSCode when the
150
+ // extension is deactivated.
151
+ export async function deactivate ( ) {
152
+ await languageClient ?. stop ( ) ;
153
+ languageClient = null ;
154
+ }
0 commit comments