Fix relative godotPath values not resolving correctly (#655)

This commit is contained in:
David Kincaid
2024-04-29 13:24:52 -07:00
committed by GitHub
parent 2e6eedb196
commit 6b009ea123
5 changed files with 32 additions and 18 deletions

View File

@@ -8,7 +8,7 @@ import { RawObject } from "./variables/variants";
import { GodotStackFrame, GodotStackVars } from "../debug_runtime";
import { GodotDebugSession } from "./debug_session";
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 } from "../../utils";
import { get_configuration, get_free_port, createLogger, verify_godot_version, get_project_version, clean_godot_path } from "../../utils";
import { prompt_for_godot_executable } from "../../utils/prompts";
import { subProcess, killSubProcesses } from "../../utils/subspawn";
import { LaunchRequestArguments, AttachRequestArguments, pinnedScene } from "../debugger";
@@ -107,7 +107,7 @@ export class ServerController {
if (args.editor_path) {
log.info("Using 'editor_path' variable from launch.json");
godotPath = args.editor_path.replace(/^"/, "").replace(/"$/, "");
godotPath = clean_godot_path(args.editor_path);
log.info(`Verifying version of '${godotPath}'`);
result = verify_godot_version(godotPath, "3");
@@ -134,7 +134,7 @@ export class ServerController {
log.info("Using 'editorPath.godot3' from settings");
const settingName = "editorPath.godot3";
godotPath = get_configuration(settingName).replace(/^"/, "").replace(/"$/, "");
godotPath = clean_godot_path(get_configuration(settingName));
log.info(`Verifying version of '${godotPath}'`);
result = verify_godot_version(godotPath, "3");

View File

@@ -8,7 +8,7 @@ import { RawObject } from "./variables/variants";
import { GodotStackFrame, GodotVariable, GodotStackVars } from "../debug_runtime";
import { GodotDebugSession } from "./debug_session";
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 } from "../../utils";
import { get_configuration, get_free_port, createLogger, verify_godot_version, get_project_version, clean_godot_path } from "../../utils";
import { prompt_for_godot_executable } from "../../utils/prompts";
import { subProcess, killSubProcesses } from "../../utils/subspawn";
import { LaunchRequestArguments, AttachRequestArguments, pinnedScene } from "../debugger";
@@ -108,7 +108,7 @@ export class ServerController {
if (args.editor_path) {
log.info("Using 'editor_path' variable from launch.json");
godotPath = args.editor_path.replace(/^"/, "").replace(/"$/, "");
godotPath = clean_godot_path(args.editor_path);
log.info(`Verifying version of '${godotPath}'`);
result = verify_godot_version(godotPath, "4");
@@ -135,7 +135,7 @@ export class ServerController {
log.info("Using 'editorPath.godot4' from settings");
const settingName = "editorPath.godot4";
godotPath = get_configuration(settingName).replace(/^"/, "").replace(/"$/, "");
godotPath = clean_godot_path(get_configuration(settingName));
log.info(`Verifying version of '${godotPath}'`);
result = verify_godot_version(godotPath, "4");

View File

@@ -1,6 +1,6 @@
import * as path from "path";
import * as vscode from "vscode";
import { attemptSettingsUpdate, get_extension_uri } from "./utils";
import { attemptSettingsUpdate, get_extension_uri, clean_godot_path } from "./utils";
import {
GDInlayHintsProvider,
GDHoverProvider,
@@ -82,7 +82,7 @@ export function activate(context: vscode.ExtensionContext) {
async function initial_setup() {
const projectVersion = await get_project_version();
const settingName = `editorPath.godot${projectVersion[0]}`;
const godotPath = get_configuration(settingName);
const godotPath = clean_godot_path(get_configuration(settingName));
const result = verify_godot_version(godotPath, projectVersion[0]);
switch (result.status) {
@@ -153,7 +153,7 @@ async function open_workspace_with_editor() {
const projectVersion = await get_project_version();
const settingName = `editorPath.godot${projectVersion[0]}`;
const godotPath = get_configuration(settingName).replace(/^"/, "").replace(/"$/, "");
const godotPath = clean_godot_path(get_configuration(settingName));
const result = verify_godot_version(godotPath, projectVersion[0]);
switch (result.status) {
@@ -204,9 +204,7 @@ async function get_godot_path(): Promise<string|undefined> {
return undefined;
}
const settingName = `editorPath.godot${projectVersion[0]}`;
// Cleans up any surrounding quotes the user might put into the path.
const godotPath : string = get_configuration(settingName).replace(/^"/, "").replace(/"$/, "");
return godotPath;
return clean_godot_path(get_configuration(settingName));
}
class GodotEditorTerminal implements vscode.Pseudoterminal {

View File

@@ -10,6 +10,7 @@ import {
set_configuration,
createLogger,
verify_godot_version,
clean_godot_path,
} from "../utils";
import { prompt_for_godot_executable, prompt_for_reload, select_godot_executable } from "../utils/prompts";
import { subProcess, killSubProcesses } from "../utils/subspawn";
@@ -105,7 +106,7 @@ export class ClientConnectionManager {
targetVersion = "4.2";
}
const settingName = `editorPath.godot${projectVersion[0]}`;
const godotPath = get_configuration(settingName).replace(/^"/, "").replace(/"$/, "");
const godotPath = clean_godot_path(get_configuration(settingName));
const result = verify_godot_version(godotPath, projectVersion[0]);
switch (result.status) {

View File

@@ -2,6 +2,7 @@ import * as vscode from "vscode";
import * as path from "path";
import * as fs from "fs";
import { execSync } from "child_process";
import { get_configuration } from "./vscode_utils";
let projectDir: string | undefined = undefined;
let projectFile: string | undefined = undefined;
@@ -21,7 +22,7 @@ export async function get_project_dir(): Promise<string | undefined> {
}
} else if (files.length > 1) {
// if multiple project files, pick the top-most one
const best = files.reduce((a, b) => a.fsPath.length <= b.fsPath.length ? a : b);
const best = files.reduce((a, b) => (a.fsPath.length <= b.fsPath.length ? a : b));
if (best) {
file = best.fsPath;
if (!fs.existsSync(file) || !fs.statSync(file).isFile()) {
@@ -70,7 +71,7 @@ export async function get_project_version(): Promise<string | undefined> {
return projectVersion;
}
export function find_project_file(start: string, depth: number = 20) {
export function find_project_file(start: string, depth = 20) {
// TODO: rename this, it's actually more like "find_parent_project_file"
// This function appears to be fast enough, but if speed is ever an issue,
// memoizing the result should be straightforward
@@ -102,9 +103,9 @@ export async function convert_resource_path_to_uri(resPath: string): Promise<vsc
type VERIFY_STATUS = "SUCCESS" | "WRONG_VERSION" | "INVALID_EXE";
type VERIFY_RESULT = {
status: VERIFY_STATUS,
version?: string,
}
status: VERIFY_STATUS;
version?: string;
};
export function verify_godot_version(godotPath: string, expectedVersion: "3" | "4" | string): VERIFY_RESULT {
try {
@@ -122,3 +123,17 @@ export function verify_godot_version(godotPath: string, expectedVersion: "3" | "
return { status: "INVALID_EXE" };
}
}
export function clean_godot_path(godotPath: string): string {
const cleanPath = godotPath.replace(/^"/, "").replace(/"$/, "");
const resolvedPath = resolve_workspace_relative_path(cleanPath);
return resolvedPath;
}
function resolve_workspace_relative_path(target: string) {
if (!fs.existsSync(target)) {
const workspacePath = vscode.workspace.workspaceFolders[0].uri.fsPath;
return path.resolve(workspacePath, target);
}
return target;
}