1
1
"use strict" ;
2
2
3
- import { ExtensionContext , commands , window , workspace } from "vscode" ;
3
+ import { ConfigurationChangeEvent , ExtensionContext , commands , window , workspace } from "vscode" ;
4
4
import { LanguageClient , ServerOptions } from "vscode-languageclient/node" ;
5
5
import { promisify } from "util" ;
6
6
import { exec } from "child_process" ;
@@ -16,19 +16,42 @@ export function activate(context: ExtensionContext) {
16
16
let visualizer : Visualize | null = null ;
17
17
18
18
context . subscriptions . push (
19
+ outputChannel ,
19
20
commands . registerCommand ( "syntaxTree.start" , startLanguageServer ) ,
20
21
commands . registerCommand ( "syntaxTree.stop" , stopLanguageServer ) ,
21
22
commands . registerCommand ( "syntaxTree.restart" , restartLanguageServer ) ,
22
23
commands . registerCommand ( "syntaxTree.visualize" , ( ) => visualizer ?. visualize ( ) ) ,
23
24
commands . registerCommand ( "syntaxTree.showOutputChannel" , ( ) => outputChannel . show ( ) ) ,
24
- outputChannel
25
+ workspace . onDidChangeConfiguration ( event =>
26
+ event . affectsConfiguration ( "syntaxTree" ) &&
27
+ restartLanguageServer ( ) )
25
28
) ;
26
29
27
30
return startLanguageServer ( ) ;
28
31
29
32
async function startLanguageServer ( ) {
30
- outputChannel . appendLine ( "Starting language server..." ) ;
31
- let run : ServerOptions = { command : "stree" , args : [ "lsp" ] } ;
33
+ const config = workspace . getConfiguration ( "syntaxTree" ) ;
34
+ const addlPlugins = config . get < string [ ] > ( "additionalPlugins" ) || [ ] ;
35
+ const singleQuotes = config . get < boolean > ( "singleQuotes" ) ;
36
+ const trailingComma = config . get < boolean > ( "trailingComma" ) ;
37
+
38
+ const args = [ "lsp" ] ;
39
+
40
+ const plugins = new Set < string > ( ) ;
41
+ if ( singleQuotes ) {
42
+ plugins . add ( "plugin/single_quotes" ) ;
43
+ }
44
+ if ( trailingComma ) {
45
+ plugins . add ( "plugin/trailing_comma" ) ;
46
+ }
47
+ addlPlugins . forEach ( plugins . add ) ;
48
+
49
+ if ( plugins . size ) {
50
+ args . push ( `--plugins=${ Array . from ( plugins ) . join ( "," ) } ` ) ;
51
+ }
52
+
53
+ outputChannel . appendLine ( `Starting language server with ${ plugins . size } plugin(s)...` ) ;
54
+ let run : ServerOptions = { command : "stree" , args } ;
32
55
33
56
if ( workspace . workspaceFolders ) {
34
57
const cwd = workspace . workspaceFolders ! [ 0 ] . uri . fsPath ;
0 commit comments