Sfoglia il codice sorgente

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 <[email protected]>
Alexander Peck 15 ore fa
parent
commit
bf5fcea38c

+ 2 - 2
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",

+ 2 - 1
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<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], {

+ 15 - 1
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");
 	}