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>
This commit is contained in:
Alexander Peck
2025-07-26 22:39:49 +02:00
committed by GitHub
parent 45db62bfa3
commit bf5fcea38c
3 changed files with 19 additions and 4 deletions

View File

@@ -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<string>("editorPath.godot4");
var godot4_path = clean_godot_path(config.get<string>("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], {

View File

@@ -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");
}