1
1
"use strict" ;
2
2
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" ;
5
7
6
8
import Implicits from "./Implicits" ;
7
- import startLanguageClient from "./startLanguageClient" ;
8
9
import Visualize from "./Visualize" ;
9
10
11
+ const promiseExec = promisify ( exec ) ;
12
+
10
13
export function activate ( context : ExtensionContext ) {
11
14
let languageClient : LanguageClient | null = null ;
12
15
const outputChannel = window . createOutputChannel ( "Syntax Tree" ) ;
@@ -23,17 +26,33 @@ export function activate(context: ExtensionContext) {
23
26
24
27
async function startLanguageServer ( ) {
25
28
outputChannel . appendLine ( "Starting language server..." ) ;
26
- languageClient = await startLanguageClient ( outputChannel ) ;
29
+ let run : ServerOptions = { command : "stree" , args : [ "lsp" ] } ;
27
30
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 ;
31
33
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
+ }
36
40
}
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
+ ) ;
37
56
}
38
57
39
58
async function stopLanguageServer ( ) {
0 commit comments