diff --git a/package.json b/package.json index 6c2fec6..e1536d2 100644 --- a/package.json +++ b/package.json @@ -272,12 +272,12 @@ "godotTools.editorPath.godot3": { "type": "string", "default": "godot3", - "description": "Path to the Godot 3 editor executable" + "description": "Path to the Godot 3 editor executable. Supports environment variables using '${env:VAR_NAME}'." }, "godotTools.editorPath.godot4": { "type": "string", "default": "godot", - "description": "Path to the Godot 4 editor executable" + "description": "Path to the Godot 4 editor executable. Supports environment variables using '${env:VAR_NAME}'." }, "godotTools.editor.verbose": { "type": "boolean", diff --git a/src/debugger/godot4/variables/debugger_variables.test.ts b/src/debugger/godot4/variables/debugger_variables.test.ts index da4ffa0..b16fd62 100644 --- a/src/debugger/godot4/variables/debugger_variables.test.ts +++ b/src/debugger/godot4/variables/debugger_variables.test.ts @@ -13,6 +13,7 @@ chaiAsPromised.then((module) => { import { promisify } from "util"; import { execFile } from "child_process"; +import { clean_godot_path } from "../../../utils"; const execFileAsync = promisify(execFile); chai.use(chaiSubset); @@ -225,7 +226,7 @@ suite("DAP Integration Tests - Variable Scopes", () => { // init the godot project by importing it in godot engine: const config = vscode.workspace.getConfiguration("godotTools"); // config.update("editorPath.godot4", "godot4", vscode.ConfigurationTarget.Workspace); - var godot4_path = config.get("editorPath.godot4"); + var godot4_path = clean_godot_path(config.get("editorPath.godot4")); // get the path for currently opened project in vscode test instance: console.log("Executing", [godot4_path, "--headless", "--import", workspaceFolder]); const exec_res = await execFileAsync(godot4_path, ["--headless", "--import", workspaceFolder], { diff --git a/src/utils/godot_utils.ts b/src/utils/godot_utils.ts index 05b2065..9dd7b7a 100644 --- a/src/utils/godot_utils.ts +++ b/src/utils/godot_utils.ts @@ -228,8 +228,22 @@ export function verify_godot_version(godotPath: string, expectedVersion: "3" | " } export function clean_godot_path(godotPath: string): string { - let target = godotPath.replace(/^"/, "").replace(/"$/, ""); + let pathToClean = godotPath; + // check for environment variable syntax + // looking for: ${env:FOOBAR} + // extracts "FOOBAR" + const pattern = /\$\{env:(.+?)\}/; + const match = godotPath.match(pattern); + + if (match && match.length >= 2) { + pathToClean = process.env[match[1]]; + } + + // strip leading and trailing quotes + let target = pathToClean.replace(/^"/, "").replace(/"$/, ""); + + // try to fix macos paths if (os.platform() === "darwin" && target.endsWith(".app")) { target = path.join(target, "Contents", "MacOS", "Godot"); }