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

Commit 731fd9c

Browse files
authored
Merge pull request #5 from xeger/config
Allow users to configure the extension
2 parents be6dfc3 + 33022b3 commit 731fd9c

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,30 @@
4949
"title": "Syntax Tree: Visualize"
5050
}
5151
],
52+
"configuration": {
53+
"type": "object",
54+
"title": "Syntax Tree",
55+
"properties": {
56+
"syntaxTree.singleQuotes": {
57+
"default": false,
58+
"markdownDescription": "Uses single-quoted strings when possible.",
59+
"type": "boolean"
60+
},
61+
"syntaxTree.trailingComma": {
62+
"default": false,
63+
"markdownDescription": "Adds an extra comma after the last item of arrays, hashes and parameters.",
64+
"type": "boolean"
65+
},
66+
"syntaxTree.additionalPlugins": {
67+
"default": [],
68+
"markdownDescription": "Registers [extra behaviors](https://github.com/ruby-syntax-tree/syntax_tree#plugins) with the language server.",
69+
"items": {
70+
"type": "string"
71+
},
72+
"type": "array"
73+
}
74+
}
75+
},
5276
"colors": [
5377
{
5478
"id": "syntaxTree.inlayHints",

src/extension.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22

3-
import { ExtensionContext, commands, window, workspace } from "vscode";
3+
import { ConfigurationChangeEvent, ExtensionContext, commands, window, workspace } from "vscode";
44
import { LanguageClient, ServerOptions } from "vscode-languageclient/node";
55
import { promisify } from "util";
66
import { exec } from "child_process";
@@ -16,19 +16,42 @@ export function activate(context: ExtensionContext) {
1616
let visualizer: Visualize | null = null;
1717

1818
context.subscriptions.push(
19+
outputChannel,
1920
commands.registerCommand("syntaxTree.start", startLanguageServer),
2021
commands.registerCommand("syntaxTree.stop", stopLanguageServer),
2122
commands.registerCommand("syntaxTree.restart", restartLanguageServer),
2223
commands.registerCommand("syntaxTree.visualize", () => visualizer?.visualize()),
2324
commands.registerCommand("syntaxTree.showOutputChannel", () => outputChannel.show()),
24-
outputChannel
25+
workspace.onDidChangeConfiguration(event =>
26+
event.affectsConfiguration("syntaxTree") &&
27+
restartLanguageServer())
2528
);
2629

2730
return startLanguageServer();
2831

2932
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 };
3255

3356
if (workspace.workspaceFolders) {
3457
const cwd = workspace.workspaceFolders![0].uri.fsPath;

0 commit comments

Comments
 (0)