Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a16cfc4

Browse files
committed
Clean up
1 parent d79acff commit a16cfc4

File tree

2 files changed

+30
-68
lines changed

2 files changed

+30
-68
lines changed

src/extension.ts

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
"use strict";
22

3-
import { ExtensionContext, commands, window } from "vscode";
4-
import { LanguageClient } from "vscode-languageclient/node";
3+
import { ExtensionContext, commands, window, workspace } from "vscode";
4+
import { LanguageClient, ServerOptions } from "vscode-languageclient/node";
5+
import { promisify } from "util";
6+
import { exec } from "child_process";
57

68
import Implicits from "./Implicits";
7-
import startLanguageClient from "./startLanguageClient";
89
import Visualize from "./Visualize";
910

11+
const promiseExec = promisify(exec);
12+
1013
export function activate(context: ExtensionContext) {
1114
let languageClient: LanguageClient | null = null;
1215
const outputChannel = window.createOutputChannel("Syntax Tree");
@@ -23,17 +26,33 @@ export function activate(context: ExtensionContext) {
2326

2427
async function startLanguageServer() {
2528
outputChannel.appendLine("Starting language server...");
26-
languageClient = await startLanguageClient(outputChannel);
29+
let run: ServerOptions = { command: "stree", args: ["lsp"] };
2730

28-
if (languageClient) {
29-
context.subscriptions.push(languageClient.start());
30-
await languageClient.onReady();
31+
if (workspace.workspaceFolders) {
32+
const cwd = workspace.workspaceFolders![0].uri.fsPath;
3133

32-
context.subscriptions.push(
33-
new Implicits(languageClient, outputChannel),
34-
new Visualize(languageClient, outputChannel)
35-
);
34+
try {
35+
await promiseExec("bundle show syntax_tree", { cwd });
36+
run = { command: "bundle", args: ["exec", "stree", "lsp"], options: { cwd } };
37+
} catch {
38+
outputChannel.appendLine("No bundled syntax_tree, running global stree.");
39+
}
3640
}
41+
42+
languageClient = new LanguageClient("Syntax Tree", { run, debug: run }, {
43+
documentSelector: [
44+
{ scheme: "file", language: "ruby" },
45+
],
46+
outputChannel
47+
});
48+
49+
context.subscriptions.push(languageClient.start());
50+
await languageClient.onReady();
51+
52+
context.subscriptions.push(
53+
new Implicits(languageClient, outputChannel),
54+
new Visualize(languageClient, outputChannel)
55+
);
3756
}
3857

3958
async function stopLanguageServer() {

src/startLanguageClient.ts

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)