|
1 | 1 | // import { LanguageClientOptions } from "vscode-languageclient"; |
2 | 2 | import { ExtensionContext, window } from "vscode"; |
3 | 3 | import { LanguageClient, ServerOptions } from "vscode-languageclient/node"; |
| 4 | +import { spawnSync } from "child_process"; |
4 | 5 |
|
5 | 6 | let client: LanguageClient | undefined; |
6 | 7 |
|
| 8 | +export async function activate_els(context: ExtensionContext) { |
| 9 | + let serverOptions; |
| 10 | + let result = spawnSync("erg", ["--build-features"]); |
| 11 | + if (result.stdout.toString().includes("els")) { |
| 12 | + serverOptions = { |
| 13 | + command: "erg", |
| 14 | + args: ["--language-server"] |
| 15 | + }; |
| 16 | + } else { |
| 17 | + serverOptions = { |
| 18 | + command: "els", |
| 19 | + args: [] |
| 20 | + }; |
| 21 | + } |
| 22 | + const clientOptions = { |
| 23 | + documentSelector: [ |
| 24 | + { |
| 25 | + scheme: "file", |
| 26 | + language: "erg", |
| 27 | + } |
| 28 | + ], |
| 29 | + }; |
| 30 | + client = new LanguageClient("els", serverOptions, clientOptions); |
| 31 | + context.subscriptions.push(client.start()); |
| 32 | +} |
| 33 | + |
7 | 34 | export async function activate(context: ExtensionContext) { |
8 | | - try { |
9 | | - const serverOptions = { |
10 | | - command: "els", |
11 | | - args: [], |
12 | | - }; // satisfies ServerOptions; |
13 | | - const clientOptions = { |
14 | | - documentSelector: [ |
15 | | - { |
16 | | - scheme: "file", |
17 | | - language: "erg", |
18 | | - }, |
19 | | - ], |
20 | | - }; // satisfies LanguageClientOptions; |
21 | | - client = new LanguageClient("els", serverOptions, clientOptions); |
22 | | - context.subscriptions.push(client.start()); |
23 | | - } catch (e) { |
24 | | - window.showErrorMessage("failed to start els."); |
25 | | - } |
| 35 | + try { |
| 36 | + activate_els(context); |
| 37 | + } catch (e) { |
| 38 | + window.showErrorMessage("Failed to start ELS (Erg Language Server). Please make sure you have erg (built with `els` feature) or els installed."); |
| 39 | + } |
26 | 40 | } |
27 | 41 |
|
28 | 42 | export function deactivate() { |
|
0 commit comments