@@ -7,12 +7,34 @@ import {
77 ServerOptions
88} from 'vscode-languageclient/node' ;
99
10+ const clientName = "zk"
11+ const clientId = "zk"
1012let client : LanguageClient ;
1113
12- export function activate ( context : ExtensionContext ) {
13- const clientName = "zk"
14- const clientId = "zk"
14+ export async function activate ( context : ExtensionContext ) {
15+ let restartCmd = vscode . commands . registerCommand ( `${ clientId } .restart` , async ( ) => {
16+ await stopClient ( ) ;
17+ startClient ( context ) ;
18+ } ) ;
1519
20+ let showLogsCmd = vscode . commands . registerCommand ( `${ clientId } .showLogs` , ( ) => {
21+ if ( ! client ) return
22+ client . outputChannel . show ( true ) ;
23+ } ) ;
24+
25+ context . subscriptions . push (
26+ restartCmd ,
27+ showLogsCmd ,
28+ ) ;
29+
30+ startClient ( context )
31+ }
32+
33+ export async function deactivate ( ) {
34+ await stopClient ( )
35+ }
36+
37+ function startClient ( context : ExtensionContext ) {
1638 // If the extension is launched in debug mode then the debug server options are used
1739 // Otherwise the run options are used
1840 let serverOptions : ServerOptions = {
@@ -27,14 +49,14 @@ export function activate(context: ExtensionContext) {
2749
2850 client = new LanguageClient ( clientId , clientName , serverOptions , clientOptions ) ;
2951
30-
3152 // Start the client. This will also launch the server.
32- client . start ( ) ;
53+ context . subscriptions . push ( client . start ( ) ) ;
3354}
3455
35- export function deactivate ( ) : Thenable < void > | undefined {
36- if ( ! client ) {
37- return undefined ;
38- }
39- return client . stop ( ) ;
56+ async function stopClient ( ) {
57+ if ( ! client ) return
58+
59+ await client . stop ( ) ;
60+ client . outputChannel . dispose ( ) ;
61+ client . traceOutputChannel . dispose ( ) ;
4062}
0 commit comments