Fix handling of editorPaths (#656)

This commit is contained in:
David Kincaid
2024-06-20 02:00:55 -07:00
committed by GitHub
parent df445b8390
commit f55d36e86c
5 changed files with 56 additions and 46 deletions

View File

@@ -8,7 +8,7 @@ import { RawObject } from "./variables/variants";
import { GodotStackFrame, GodotStackVars } from "../debug_runtime"; import { GodotStackFrame, GodotStackVars } from "../debug_runtime";
import { GodotDebugSession } from "./debug_session"; import { GodotDebugSession } from "./debug_session";
import { parse_next_scene_node, split_buffers, build_sub_values } from "./helpers"; import { parse_next_scene_node, split_buffers, build_sub_values } from "./helpers";
import { get_configuration, get_free_port, createLogger, verify_godot_version, get_project_version, clean_godot_path } from "../../utils"; import { get_configuration, get_free_port, createLogger, verify_godot_version, get_project_version } from "../../utils";
import { prompt_for_godot_executable } from "../../utils/prompts"; import { prompt_for_godot_executable } from "../../utils/prompts";
import { subProcess, killSubProcesses } from "../../utils/subspawn"; import { subProcess, killSubProcesses } from "../../utils/subspawn";
import { LaunchRequestArguments, AttachRequestArguments, pinnedScene } from "../debugger"; import { LaunchRequestArguments, AttachRequestArguments, pinnedScene } from "../debugger";
@@ -107,12 +107,11 @@ export class ServerController {
if (args.editor_path) { if (args.editor_path) {
log.info("Using 'editor_path' variable from launch.json"); log.info("Using 'editor_path' variable from launch.json");
godotPath = clean_godot_path(args.editor_path); log.info(`Verifying version of '${args.editor_path}'`);
result = verify_godot_version(args.editor_path, "3");
log.info(`Verifying version of '${godotPath}'`); godotPath = result.godotPath;
result = verify_godot_version(godotPath, "3");
log.info(`Verification result: ${result.status}, version: "${result.version}"`); log.info(`Verification result: ${result.status}, version: "${result.version}"`);
switch (result.status) { switch (result.status) {
case "WRONG_VERSION": { case "WRONG_VERSION": {
const projectVersion = await get_project_version(); const projectVersion = await get_project_version();
@@ -129,16 +128,19 @@ export class ServerController {
this.abort(); this.abort();
return; return;
} }
default: {
break;
}
} }
} else { } else {
log.info("Using 'editorPath.godot3' from settings"); log.info("Using 'editorPath.godot3' from settings");
const settingName = "editorPath.godot3"; const settingName = "editorPath.godot3";
godotPath = clean_godot_path(get_configuration(settingName)); godotPath = get_configuration(settingName);
log.info(`Verifying version of '${godotPath}'`); log.info(`Verifying version of '${godotPath}'`);
result = verify_godot_version(godotPath, "3"); result = verify_godot_version(godotPath, "3");
godotPath = result.godotPath;
log.info(`Verification result: ${result.status}, version: "${result.version}"`); log.info(`Verification result: ${result.status}, version: "${result.version}"`);
switch (result.status) { switch (result.status) {

View File

@@ -8,7 +8,7 @@ import { RawObject } from "./variables/variants";
import { GodotStackFrame, GodotVariable, GodotStackVars } from "../debug_runtime"; import { GodotStackFrame, GodotVariable, GodotStackVars } from "../debug_runtime";
import { GodotDebugSession } from "./debug_session"; import { GodotDebugSession } from "./debug_session";
import { parse_next_scene_node, split_buffers, build_sub_values } from "./helpers"; import { parse_next_scene_node, split_buffers, build_sub_values } from "./helpers";
import { get_configuration, get_free_port, createLogger, verify_godot_version, get_project_version, clean_godot_path } from "../../utils"; import { get_configuration, get_free_port, createLogger, verify_godot_version, get_project_version } from "../../utils";
import { prompt_for_godot_executable } from "../../utils/prompts"; import { prompt_for_godot_executable } from "../../utils/prompts";
import { subProcess, killSubProcesses } from "../../utils/subspawn"; import { subProcess, killSubProcesses } from "../../utils/subspawn";
import { LaunchRequestArguments, AttachRequestArguments, pinnedScene } from "../debugger"; import { LaunchRequestArguments, AttachRequestArguments, pinnedScene } from "../debugger";
@@ -108,12 +108,11 @@ export class ServerController {
if (args.editor_path) { if (args.editor_path) {
log.info("Using 'editor_path' variable from launch.json"); log.info("Using 'editor_path' variable from launch.json");
godotPath = clean_godot_path(args.editor_path); log.info(`Verifying version of '${args.editor_path}'`);
result = verify_godot_version(args.editor_path, "4");
log.info(`Verifying version of '${godotPath}'`); godotPath = result.godotPath;
result = verify_godot_version(godotPath, "4");
log.info(`Verification result: ${result.status}, version: "${result.version}"`); log.info(`Verification result: ${result.status}, version: "${result.version}"`);
switch (result.status) { switch (result.status) {
case "WRONG_VERSION": { case "WRONG_VERSION": {
const projectVersion = await get_project_version(); const projectVersion = await get_project_version();
@@ -130,16 +129,19 @@ export class ServerController {
this.abort(); this.abort();
return; return;
} }
default: {
break;
}
} }
} else { } else {
log.info("Using 'editorPath.godot4' from settings"); log.info("Using 'editorPath.godot4' from settings");
const settingName = "editorPath.godot4"; const settingName = "editorPath.godot4";
godotPath = clean_godot_path(get_configuration(settingName)); godotPath = get_configuration(settingName);
log.info(`Verifying version of '${godotPath}'`); log.info(`Verifying version of '${godotPath}'`);
result = verify_godot_version(godotPath, "4"); result = verify_godot_version(godotPath, "4");
godotPath = result.godotPath;
log.info(`Verification result: ${result.status}, version: "${result.version}"`); log.info(`Verification result: ${result.status}, version: "${result.version}"`);
switch (result.status) { switch (result.status) {

View File

@@ -82,8 +82,8 @@ export function activate(context: vscode.ExtensionContext) {
async function initial_setup() { async function initial_setup() {
const projectVersion = await get_project_version(); const projectVersion = await get_project_version();
const settingName = `editorPath.godot${projectVersion[0]}`; const settingName = `editorPath.godot${projectVersion[0]}`;
const godotPath = clean_godot_path(get_configuration(settingName)); const result = verify_godot_version(get_configuration(settingName), projectVersion[0]);
const result = verify_godot_version(godotPath, projectVersion[0]); const godotPath = result.godotPath;
switch (result.status) { switch (result.status) {
case "SUCCESS": { case "SUCCESS": {
@@ -153,8 +153,8 @@ async function open_workspace_with_editor() {
const projectVersion = await get_project_version(); const projectVersion = await get_project_version();
const settingName = `editorPath.godot${projectVersion[0]}`; const settingName = `editorPath.godot${projectVersion[0]}`;
const godotPath = clean_godot_path(get_configuration(settingName)); const result = verify_godot_version(get_configuration(settingName), projectVersion[0]);
const result = verify_godot_version(godotPath, projectVersion[0]); const godotPath = result.godotPath;
switch (result.status) { switch (result.status) {
case "SUCCESS": { case "SUCCESS": {

View File

@@ -10,7 +10,6 @@ import {
set_configuration, set_configuration,
createLogger, createLogger,
verify_godot_version, verify_godot_version,
clean_godot_path,
} from "../utils"; } from "../utils";
import { prompt_for_godot_executable, prompt_for_reload, select_godot_executable } from "../utils/prompts"; import { prompt_for_godot_executable, prompt_for_reload, select_godot_executable } from "../utils/prompts";
import { subProcess, killSubProcesses } from "../utils/subspawn"; import { subProcess, killSubProcesses } from "../utils/subspawn";
@@ -106,9 +105,11 @@ export class ClientConnectionManager {
targetVersion = "4.2"; targetVersion = "4.2";
} }
const settingName = `editorPath.godot${projectVersion[0]}`; const settingName = `editorPath.godot${projectVersion[0]}`;
const godotPath = clean_godot_path(get_configuration(settingName)); let godotPath = get_configuration(settingName);
const result = verify_godot_version(godotPath, projectVersion[0]); const result = verify_godot_version(godotPath, projectVersion[0]);
godotPath = result.godotPath;
switch (result.status) { switch (result.status) {
case "WRONG_VERSION": { case "WRONG_VERSION": {
const message = `Cannot launch headless LSP: The current project uses Godot v${projectVersion}, but the specified Godot executable is v${result.version}`; const message = `Cannot launch headless LSP: The current project uses Godot v${projectVersion}, but the specified Godot executable is v${result.version}`;

View File

@@ -3,7 +3,6 @@ import * as path from "path";
import * as fs from "fs"; import * as fs from "fs";
import * as os from "os"; import * as os from "os";
import { execSync } from "child_process"; import { execSync } from "child_process";
import { get_configuration } from "./vscode_utils";
let projectDir: string | undefined = undefined; let projectDir: string | undefined = undefined;
let projectFile: string | undefined = undefined; let projectFile: string | undefined = undefined;
@@ -105,40 +104,46 @@ export async function convert_resource_path_to_uri(resPath: string): Promise<vsc
type VERIFY_STATUS = "SUCCESS" | "WRONG_VERSION" | "INVALID_EXE"; type VERIFY_STATUS = "SUCCESS" | "WRONG_VERSION" | "INVALID_EXE";
type VERIFY_RESULT = { type VERIFY_RESULT = {
status: VERIFY_STATUS; status: VERIFY_STATUS;
godotPath: string;
version?: string; version?: string;
}; };
export function verify_godot_version(godotPath: string, expectedVersion: "3" | "4" | string): VERIFY_RESULT { export function verify_godot_version(godotPath: string, expectedVersion: "3" | "4" | string): VERIFY_RESULT {
let target = clean_godot_path(godotPath);
let output = "";
try { try {
if (os.platform() === 'darwin' && godotPath.endsWith('.app')) { output = execSync(`"${target}" --version`).toString().trim();
godotPath = path.join(godotPath, 'Contents', 'MacOS', 'Godot'); } catch {
if (path.isAbsolute(target)) {
return { status: "INVALID_EXE", godotPath: target };
}
const workspacePath = vscode.workspace.workspaceFolders[0].uri.fsPath;
target = path.resolve(workspacePath, target);
try {
output = execSync(`"${target}" --version`).toString().trim();
} catch {
return { status: "INVALID_EXE", godotPath: target };
}
} }
const output = execSync(`"${godotPath}" --version`).toString().trim();
const pattern = /^(([34])\.([0-9]+)(?:\.[0-9]+)?)/m; const pattern = /^(([34])\.([0-9]+)(?:\.[0-9]+)?)/m;
const match = output.match(pattern); const match = output.match(pattern);
if (!match) { if (!match) {
return { status: "INVALID_EXE" }; return { status: "INVALID_EXE", godotPath: target };
} }
if (match[2] !== expectedVersion) { if (match[2] !== expectedVersion) {
return { status: "WRONG_VERSION", version: match[1] }; return { status: "WRONG_VERSION", godotPath: target, version: match[1] };
}
return { status: "SUCCESS", version: match[1] };
} catch {
return { status: "INVALID_EXE" };
} }
return { status: "SUCCESS", godotPath: target, version: match[1] };
} }
export function clean_godot_path(godotPath: string): string { export function clean_godot_path(godotPath: string): string {
const cleanPath = godotPath.replace(/^"/, "").replace(/"$/, ""); let target = godotPath.replace(/^"/, "").replace(/"$/, "");
const resolvedPath = resolve_workspace_relative_path(cleanPath);
return resolvedPath;
}
function resolve_workspace_relative_path(target: string) { if (os.platform() === "darwin" && target.endsWith(".app")) {
if (!fs.existsSync(target)) { target = path.join(target, "Contents", "MacOS", "Godot");
const workspacePath = vscode.workspace.workspaceFolders[0].uri.fsPath;
return path.resolve(workspacePath, target);
} }
return target; return target;
} }