Skip to content

Commit c3e665a

Browse files
committed
feat(vscode): Add debug options to override the server path
1 parent 0517c3a commit c3e665a

File tree

5 files changed

+90
-16
lines changed

5 files changed

+90
-16
lines changed

vscode-extension/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@
8484
"verbose"
8585
],
8686
"description": "Enables tracing of the underlying LSP requests and responses. This results in highly verbose logs (especially the document sync messages) and is not recommended for use outside development and troubleshooting contexts."
87+
},
88+
"gdshader.danger.serverPathOverride": {
89+
"type": "string",
90+
"default": "",
91+
"description": "Intended for debugging only. The path to the GDShader language server executable."
92+
},
93+
"gdshader.danger.disableSafetyCheck": {
94+
"type": "boolean",
95+
"default": false,
96+
"description": "Intended for debugging only. Disables the validation of the GDShader language server executable."
8797
}
8898
}
8999
},

vscode-extension/src/config.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* MIT License
3+
*
4+
* Copyright (c) 2025 Adam Snyder
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
const vscode = require("vscode");
25+
26+
/**
27+
* @typedef Configuration
28+
* @property {string} serverPathOverride
29+
* @property {boolean} disableSafetyCheck
30+
*/
31+
32+
/** @returns {Configuration} */
33+
function getConfiguration() {
34+
const config = vscode.workspace.getConfiguration("gdshader.danger");
35+
return {
36+
serverPathOverride: config.get("serverPathOverride") ?? "",
37+
disableSafetyCheck: config.get("disableSafetyCheck") ?? false,
38+
};
39+
}
40+
41+
module.exports = {
42+
getConfiguration,
43+
};

vscode-extension/src/server/load.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ const { downloadAndExtractServerArchive } = require("./download");
4444

4545
/** @param {import('vscode').ExtensionContext} context @returns {Promise<boolean>} */
4646
async function hasRequiredFiles(context) {
47-
if (!(await fileExists(getBinPath(context)))) {
47+
if (!(await fileExists(await getBinPath(context)))) {
4848
return false;
4949
}
5050
if (shouldValidateBinarySignature()) {
51-
return await fileExists(getSignaturePath(context));
51+
return await fileExists(await getSignaturePath(context));
5252
}
5353
return true;
5454
}

vscode-extension/src/server/storage.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,11 @@
2222
* SOFTWARE.
2323
*/
2424
const { logger } = require("../log");
25+
const { getConfiguration } = require("../config");
2526
const { join } = require("node:path");
2627
const { platform } = require("node:os");
2728
const { rm, stat } = require("node:fs/promises");
2829

29-
function getBinName() {
30-
return `gdshader-language-server${platform() === "win32" ? ".exe" : ""}`;
31-
}
32-
3330
/** @param {import('vscode').ExtensionContext} context @returns {string} */
3431
function getBinCacheDir(context) {
3532
return join(context.globalStorageUri.fsPath, "bin");
@@ -40,14 +37,29 @@ function getBinDir(context) {
4037
return join(getBinCacheDir(context), context.extension.packageJSON.version);
4138
}
4239

43-
/** @param {import('vscode').ExtensionContext} context @returns {string} */
44-
function getBinPath(context) {
45-
return join(getBinDir(context), getBinName());
40+
/** @param {import('vscode').ExtensionContext} context @returns {Promise<string>} */
41+
async function getBinPath(context) {
42+
const { serverPathOverride } = getConfiguration();
43+
44+
if (serverPathOverride) {
45+
if (!(await fileExists(serverPathOverride))) {
46+
throw new Error(
47+
`Server path override does not exist: ${serverPathOverride}`,
48+
);
49+
}
50+
logger().warn(`Using server path override: ${serverPathOverride}`);
51+
return serverPathOverride;
52+
}
53+
54+
return join(
55+
getBinDir(context),
56+
`gdshader-language-server${platform() === "win32" ? ".exe" : ""}`,
57+
);
4658
}
4759

48-
/** @param {import('vscode').ExtensionContext} context @returns {string} */
49-
function getSignaturePath(context) {
50-
return getBinPath(context) + ".sig";
60+
/** @param {import('vscode').ExtensionContext} context @returns {Promise<string>} */
61+
async function getSignaturePath(context) {
62+
return (await getBinPath(context)) + ".sig";
5163
}
5264

5365
/** @param {import('vscode').ExtensionContext} context @returns {Promise<void>} */
@@ -72,7 +84,6 @@ async function fileExists(path) {
7284
}
7385

7486
module.exports = {
75-
getBinName,
7687
getBinCacheDir,
7788
getBinDir,
7889
getBinPath,

vscode-extension/src/server/validate.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,20 @@ const { platform } = require("node:os");
2727
const { join } = require("node:path");
2828
const { createVerify } = require("node:crypto");
2929
const { getBinPath, getSignaturePath } = require("./storage");
30+
const { getConfiguration } = require("../config");
31+
const { logger } = require("../log");
3032

3133
function shouldValidateBinarySignature() {
3234
// MacOS has validation built-in with Gatekeeper, and the MacOS archives do
3335
// not include signature files.
34-
return platform() !== "darwin";
36+
if (platform() === "darwin") {
37+
return false;
38+
}
39+
if (getConfiguration().disableSafetyCheck) {
40+
logger().warn("Safety check is disabled. This is not recommended.");
41+
return false;
42+
}
43+
return true;
3544
}
3645

3746
/** @param {import('vscode').ExtensionContext} context @returns {Promise<void>} */
@@ -40,14 +49,15 @@ async function validateBinarySignature(context) {
4049
const pubKey = await readFile(publicKeyPath, "utf8");
4150

4251
const signature = Buffer.from(
43-
(await readFile(getSignaturePath(context), "utf8")).trim(),
52+
(await readFile(await getSignaturePath(context), "utf8")).trim(),
4453
"base64",
4554
);
4655

4756
const verify = createVerify("sha256");
57+
const binPath = await getBinPath(context);
4858

4959
await new Promise((/** @type {(_?: void) => void} */ resolve, reject) => {
50-
const stream = createReadStream(getBinPath(context));
60+
const stream = createReadStream(binPath);
5161
stream.on("data", (chunk) => verify.update(chunk));
5262
stream.on("error", reject);
5363
stream.on("end", () => {

0 commit comments

Comments
 (0)