Skip to content

Commit e49df0a

Browse files
committed
Add restart and showLogs commands
1 parent ec3dbce commit e49df0a

File tree

2 files changed

+55
-13
lines changed

2 files changed

+55
-13
lines changed

package.json

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,30 @@
1616
"contributes": {
1717
"commands": [
1818
{
19-
"command": "zk-vscode.helloWorld",
20-
"title": "Hello World"
19+
"command": "zk.restart",
20+
"title": "zk: Restart"
21+
},
22+
{
23+
"command": "zk.showLogs",
24+
"title": "zk: Show Logs"
25+
}
26+
],
27+
"configuration": {
28+
"title": "zk",
29+
"properties": {
30+
"zk.trace.server": {
31+
"type": "string",
32+
"enum": [
33+
"off",
34+
"messages",
35+
"verbose"
36+
],
37+
"default": "messages",
38+
"description": "Level of verbosity in zk's log output.",
39+
"scope": "window"
40+
}
2141
}
22-
]
42+
}
2343
},
2444
"scripts": {
2545
"vscode:prepublish": "npm run compile",

src/extension.ts

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,34 @@ import {
77
ServerOptions
88
} from 'vscode-languageclient/node';
99

10+
const clientName = "zk"
11+
const clientId = "zk"
1012
let 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

Comments
 (0)