Skip to content

Commit

Permalink
Update extension.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Jan 3, 2023
1 parent 51fb55c commit 24601e3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "vscode-erg",
"description": "Erg language support for Visual Studio Code",
"publisher": "erg-lang",
"version": "0.1.6",
"version": "0.1.7",
"engines": {
"vscode": "^1.70.0"
},
Expand Down
50 changes: 32 additions & 18 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,42 @@
// import { LanguageClientOptions } from "vscode-languageclient";
import { ExtensionContext, window } from "vscode";
import { LanguageClient, ServerOptions } from "vscode-languageclient/node";
import { spawnSync } from "child_process";

let client: LanguageClient | undefined;

export async function activate_els(context: ExtensionContext) {
let serverOptions;
let result = spawnSync("erg", ["--build-features"]);
if (result.stdout.toString().includes("els")) {
serverOptions = {
command: "erg",
args: ["--language-server"]
};
} else {
serverOptions = {
command: "els",
args: []
};
}
const clientOptions = {
documentSelector: [
{
scheme: "file",
language: "erg",
}
],
};
client = new LanguageClient("els", serverOptions, clientOptions);
context.subscriptions.push(client.start());
}

export async function activate(context: ExtensionContext) {
try {
const serverOptions = {
command: "els",
args: [],
}; // satisfies ServerOptions;
const clientOptions = {
documentSelector: [
{
scheme: "file",
language: "erg",
},
],
}; // satisfies LanguageClientOptions;
client = new LanguageClient("els", serverOptions, clientOptions);
context.subscriptions.push(client.start());
} catch (e) {
window.showErrorMessage("failed to start els.");
}
try {
activate_els(context);
} catch (e) {
window.showErrorMessage("Failed to start ELS (Erg Language Server). Please make sure you have erg (built with `els` feature) or els installed.");
}
}

export function deactivate() {
Expand Down

0 comments on commit 24601e3

Please sign in to comment.