Skip to content

Commit bf5fcea

Browse files
Added ability to specify editorPath using environment variable (#807) (#856)
* Added ability to specify editorPath using environment variable * Fix indentation * Build the regex in the idiomatic way * Add env syntax to configuration descriptions * Add missing import --------- Co-authored-by: David Kincaid <daelonsuzuka@gmail.com>
1 parent 45db62b commit bf5fcea

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,12 @@
272272
"godotTools.editorPath.godot3": {
273273
"type": "string",
274274
"default": "godot3",
275-
"description": "Path to the Godot 3 editor executable"
275+
"description": "Path to the Godot 3 editor executable. Supports environment variables using '${env:VAR_NAME}'."
276276
},
277277
"godotTools.editorPath.godot4": {
278278
"type": "string",
279279
"default": "godot",
280-
"description": "Path to the Godot 4 editor executable"
280+
"description": "Path to the Godot 4 editor executable. Supports environment variables using '${env:VAR_NAME}'."
281281
},
282282
"godotTools.editor.verbose": {
283283
"type": "boolean",

src/debugger/godot4/variables/debugger_variables.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ chaiAsPromised.then((module) => {
1313

1414
import { promisify } from "util";
1515
import { execFile } from "child_process";
16+
import { clean_godot_path } from "../../../utils";
1617
const execFileAsync = promisify(execFile);
1718

1819
chai.use(chaiSubset);
@@ -225,7 +226,7 @@ suite("DAP Integration Tests - Variable Scopes", () => {
225226
// init the godot project by importing it in godot engine:
226227
const config = vscode.workspace.getConfiguration("godotTools");
227228
// config.update("editorPath.godot4", "godot4", vscode.ConfigurationTarget.Workspace);
228-
var godot4_path = config.get<string>("editorPath.godot4");
229+
var godot4_path = clean_godot_path(config.get<string>("editorPath.godot4"));
229230
// get the path for currently opened project in vscode test instance:
230231
console.log("Executing", [godot4_path, "--headless", "--import", workspaceFolder]);
231232
const exec_res = await execFileAsync(godot4_path, ["--headless", "--import", workspaceFolder], {

src/utils/godot_utils.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,22 @@ export function verify_godot_version(godotPath: string, expectedVersion: "3" | "
228228
}
229229

230230
export function clean_godot_path(godotPath: string): string {
231-
let target = godotPath.replace(/^"/, "").replace(/"$/, "");
231+
let pathToClean = godotPath;
232232

233+
// check for environment variable syntax
234+
// looking for: ${env:FOOBAR}
235+
// extracts "FOOBAR"
236+
const pattern = /\$\{env:(.+?)\}/;
237+
const match = godotPath.match(pattern);
238+
239+
if (match && match.length >= 2) {
240+
pathToClean = process.env[match[1]];
241+
}
242+
243+
// strip leading and trailing quotes
244+
let target = pathToClean.replace(/^"/, "").replace(/"$/, "");
245+
246+
// try to fix macos paths
233247
if (os.platform() === "darwin" && target.endsWith(".app")) {
234248
target = path.join(target, "Contents", "MacOS", "Godot");
235249
}

0 commit comments

Comments
 (0)