Skip to content

Commit de0b024

Browse files
committed
Added: Settings box for initally starting language server
1 parent 30a7da4 commit de0b024

File tree

2 files changed

+75
-5
lines changed

2 files changed

+75
-5
lines changed

client/src/extension.ts

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,36 @@ import {
1717
} from 'vscode-languageclient/node';
1818

1919
let client: LanguageClient;
20+
let languageServerRunning = false;
21+
const ZSconfig = vscode.workspace.getConfiguration('ZeroSyntax');
2022

2123
export function activate(context: vscode.ExtensionContext) {
2224

2325
// const command = "extension.formatDocument";
2426

2527
// context.subscriptions.push(vscode.commands.registerCommand(command, formatDocument));
2628

29+
let languageServerRunning = ZSconfig.get<boolean>('serverStartupSetting', false); // Default to 2 if not set
30+
2731
context.subscriptions.push(vscode.languages.registerDocumentFormattingEditProvider('ini', {
2832
provideDocumentFormattingEdits: (document: vscode.TextDocument): vscode.TextEdit[] => {
2933
return formatDocument(document);
3034
}
3135
}));
3236

37+
context.subscriptions.push(vscode.commands.registerCommand('ZeroSyntax.stopLanguageServer', () => {
38+
if(languageServerRunning) {
39+
client.stop();
40+
languageServerRunning = false;
41+
}
42+
}));
43+
context.subscriptions.push(vscode.commands.registerCommand('ZeroSyntax.startLanguageServer', () => {
44+
if(!languageServerRunning) {
45+
client.start();
46+
languageServerRunning = true;
47+
}
48+
}));
49+
3350
// The server is implemented in node
3451
const serverModule = context.asAbsolutePath(
3552
path.join('server', 'out', 'server.js')
@@ -66,15 +83,16 @@ export function activate(context: vscode.ExtensionContext) {
6683
);
6784

6885
// Start the client. This will also launch the server
69-
client.start();
86+
if(languageServerRunning) {
87+
client.start();
88+
}
7089
}
7190

7291
function formatDocument(document: vscode.TextDocument): vscode.TextEdit[] {
7392
const edits: vscode.TextEdit[] = [];
7493
let indentlevel = 0;
7594

76-
const config = vscode.workspace.getConfiguration('ZeroSyntax');
77-
const indentSize = config.get<number>('indentNumber', 2); // Default to 2 if not set
95+
const indentSize = ZSconfig.get<number>('indentNumber', 2); // Default to 2 if not set
7896

7997
let ObjectsRegex = ["^\\b([Oo]bject)\\s+[a-zA-Z0-9_]", "^\\b([Oo]bject[Rr]eskin)\\s+[a-zA-Z0-9_]", "^\\b([Aa]dd[Mm]odule)$", "^\\b([Rr]eplace[Mm]odule)$", "^\\b([Dd]efault[Cc]ondition[Ss]tate)$", "^\\b([Uu]nit[Ss]pecific[Ss]ounds)$", "^\\b([Pp]rerequisites)$", "^\\b([Aa]rmor[Ss]et)$", "^\\b([Ww]eapon[Ss]et)$", "^\\b([Dd]raw)\\s*=", "^\\b([Cc]ondition[Ss]tate)\\s*=", "^\\b([Tt]ransition[Ss]tate)\\s*=", "^\\b([Bb]ody)\\s*=", "^\\b([Bb]ehavior)\\s*=", "^\\b([Cc]lient[Uu]pdate)\\s*=", "^\\b(Turret)$"];
8098
let SimpleClassesRegex = ["^\\b([Mm]apped[Ii]mage)\\s+[a-zA-Z0-9_]", "^\\b([Pp]article[Ss]ystem)\\s+[a-zA-Z0-9_]", "^\\b([Ll]ocomotor)\\s+[a-zA-Z0-9_]", "^\\b([Aa]udio[Ee]vent)\\s+[a-zA-Z0-9_]", "^\\b([Dd]ialog[Ee]vent)\\s+[a-zA-Z0-9_]", "^\\b([Aa]rmor)\\s+[a-zA-Z0-9_]", "^\\b([Cc]ommand[Ss]et)\\s+[a-zA-Z0-9_]", "^\\b([Cc]ommand[Bb]utton)\\s+[a-zA-Z0-9_]", "^\\b([Ww]eapon)\\s+[a-zA-Z0-9_]", "^\\b([Dd]amage[Ff][Xx])\\s+[A-Za-z0-9_]", "^\\b([Uu]pgrade)\\s+[a-zA-Z0-9_]", "^\\b([Pp]layer[Tt]emplate)\\s+[a-zA-Z0-9_]", "^\\b(Rank)\\s+[1-8]$", "^\\b([Ii]n[Gg]ame[Uu][Ii])$", "^\\b(A10StrikeRadiusCursor)$", "^\\b(AmbushRadiusCursor)$", "^\\b(ClusterMinesRadiusCursor)$", "^\\b(AnthraxBombRadiusCursor)$"];
@@ -128,6 +146,23 @@ function checkLineWithRegex(line: string, regex: string) {
128146
return Regex.test(line);
129147
}
130148

149+
vscode.workspace.onDidChangeConfiguration((e) => {
150+
if(e.affectsConfiguration('ZeroSyntax.serverStartupSetting')) {
151+
languageServerRunning = ZSconfig.get<boolean>('serverStartupSetting', false);
152+
toggleLanguageServer();
153+
}
154+
});
155+
156+
function toggleLanguageServer() {
157+
if(languageServerRunning) {
158+
client.stop();
159+
languageServerRunning = false;
160+
} else {
161+
client.start();
162+
languageServerRunning = true;
163+
}
164+
}
165+
131166
export function deactivate(): Thenable<void> | undefined {
132167
if (!client) {
133168
return undefined;

package.json

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,34 @@
2929
],
3030
"main": "./client/out/extension",
3131
"contributes": {
32+
"viewsContainers": {
33+
"activitybar": [
34+
{
35+
"id": "zerosyntax",
36+
"title": "ZeroSyntax",
37+
"icon": "images/ZeroSyntaxLogo_bw.png"
38+
}
39+
]
40+
},
41+
"views": {
42+
"explorer": [
43+
{
44+
"id": "package-dependencies",
45+
"name": "Dependencies",
46+
"type": "tree"
47+
}
48+
]
49+
},
50+
"commands": [
51+
{
52+
"command": "ZeroSyntax.stopLanguageServer",
53+
"title": "ZeroSyntax: Turn Off Language Server"
54+
},
55+
{
56+
"command": "ZeroSyntax.startLanguageServer",
57+
"title": "ZeroSyntax: Turn On Language Server"
58+
}
59+
],
3260
"configuration": {
3361
"type": "object",
3462
"title": "ZeroSyntax Settings",
@@ -38,6 +66,11 @@
3866
"default": 2,
3967
"description": "Controls the indentation when using the INI formatter"
4068
},
69+
"ZeroSyntax.serverStartupSetting": {
70+
"type": "boolean",
71+
"default": false,
72+
"description": "Controls whether the server is started automatically after the extension is activated."
73+
},
4174
"languageServerExample.maxNumberOfProblems": {
4275
"scope": "resource",
4376
"type": "number",
@@ -64,7 +97,8 @@
6497
"watch": "tsc -b -w",
6598
"lint": "eslint ./client/src ./server/src --ext .ts,.tsx",
6699
"postinstall": "cd client && npm install && cd ../server && npm install && cd ..",
67-
"test": "sh ./scripts/e2e.sh"
100+
"test": " tsc -b && npm run antlr4ts",
101+
"antlr4ts": "antlr4ts -visitor ./server/src/antlr/GZHSyntax.g4 -o ./server/src/antlr/"
68102
},
69103
"devDependencies": {
70104
"@types/mocha": "^9.1.0",
@@ -76,6 +110,7 @@
76110
"typescript": "^5.3.2"
77111
},
78112
"dependencies": {
79-
"antlr4ts": "^0.5.0-alpha.4"
113+
"antlr4ts": "^0.5.0-alpha.4",
114+
"antlr4ts-cli": "^0.5.0-alpha.4"
80115
}
81116
}

0 commit comments

Comments
 (0)