@@ -10,14 +10,18 @@ import Visualize from "./Visualize";
1010
1111const promiseExec = promisify ( exec ) ;
1212
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 ) {
1520 // This output channel is going to contain all of our informational messages.
1621 // It's not really meant for the end-user, it's more for debugging.
1722 const outputChannel = window . createOutputChannel ( "Syntax Tree" ) ;
1823
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.
2125 let visualizer : Visualize | null = null ;
2226
2327 // This is the list of objects that implement the Disposable interface. They
@@ -46,7 +50,7 @@ export function activate(context: ExtensionContext) {
4650
4751 // We're returning a Promise from this function that will start the Ruby
4852 // subprocess.
49- return startLanguageServer ( ) ;
53+ await startLanguageServer ( ) ;
5054
5155 // This function is called when the extension is activated or when the
5256 // language server is restarted.
@@ -110,8 +114,7 @@ export function activate(context: ExtensionContext) {
110114 } ) ;
111115
112116 // 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 ( ) ;
115118
116119 // Finally, now that the language server has been properly started, we can
117120 // add the various features to the extension. Each of them in turn
@@ -142,3 +145,10 @@ export function activate(context: ExtensionContext) {
142145 await startLanguageServer ( ) ;
143146 }
144147}
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