Skip to content

Commit ec3dbce

Browse files
committed
Minimal LSP client
1 parent 66dc301 commit ec3dbce

File tree

3 files changed

+109
-40
lines changed

3 files changed

+109
-40
lines changed

package-lock.json

Lines changed: 73 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"Other"
1111
],
1212
"activationEvents": [
13-
"onCommand:zk-vscode.helloWorld"
13+
"workspaceContains:.zk"
1414
],
1515
"main": "./out/extension.js",
1616
"contributes": {
@@ -41,5 +41,8 @@
4141
"mocha": "^8.2.1",
4242
"typescript": "^4.1.3",
4343
"vscode-test": "^1.5.0"
44+
},
45+
"dependencies": {
46+
"vscode-languageclient": "^7.0.0"
4447
}
4548
}

src/extension.ts

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,40 @@
1-
// The module 'vscode' contains the VS Code extensibility API
2-
// Import the module and reference it with the alias vscode in your code below
31
import * as vscode from 'vscode';
2+
import { workspace, ExtensionContext } from 'vscode';
43

5-
// this method is called when your extension is activated
6-
// your extension is activated the very first time the command is executed
7-
export function activate(context: vscode.ExtensionContext) {
4+
import {
5+
LanguageClient,
6+
LanguageClientOptions,
7+
ServerOptions
8+
} from 'vscode-languageclient/node';
89

9-
// Use the console to output diagnostic information (console.log) and errors (console.error)
10-
// This line of code will only be executed once when your extension is activated
11-
console.log('Congratulations, your extension "zk-vscode" is now active!');
10+
let client: LanguageClient;
1211

13-
// The command has been defined in the package.json file
14-
// Now provide the implementation of the command with registerCommand
15-
// The commandId parameter must match the command field in package.json
16-
let disposable = vscode.commands.registerCommand('zk-vscode.helloWorld', () => {
17-
// The code you place here will be executed every time your command is executed
12+
export function activate(context: ExtensionContext) {
13+
const clientName = "zk"
14+
const clientId = "zk"
1815

19-
// Display a message box to the user
20-
vscode.window.showInformationMessage('Hello World from zk-vscode!');
21-
});
16+
// If the extension is launched in debug mode then the debug server options are used
17+
// Otherwise the run options are used
18+
let serverOptions: ServerOptions = {
19+
run: { command: "zk", args: ["lsp"] },
20+
debug: { command: "zk", args: ["lsp", "--log", "/tmp/zk-lsp.log"] }
21+
};
2222

23-
context.subscriptions.push(disposable);
23+
let clientOptions: LanguageClientOptions = {
24+
// Register the server for Markdown documents.
25+
documentSelector: [{ scheme: 'file', language: 'markdown' }],
26+
};
27+
28+
client = new LanguageClient(clientId, clientName, serverOptions, clientOptions);
29+
30+
31+
// Start the client. This will also launch the server.
32+
client.start();
2433
}
2534

26-
// this method is called when your extension is deactivated
27-
export function deactivate() {}
35+
export function deactivate(): Thenable<void> | undefined {
36+
if (!client) {
37+
return undefined;
38+
}
39+
return client.stop();
40+
}

0 commit comments

Comments
 (0)