From 6b009ea123c3a4e1403322df3a8193960f163778 Mon Sep 17 00:00:00 2001 From: David Kincaid Date: Mon, 29 Apr 2024 13:24:52 -0700 Subject: [PATCH] Fix relative godotPath values not resolving correctly (#655) --- src/debugger/godot3/server_controller.ts | 6 +++--- src/debugger/godot4/server_controller.ts | 6 +++--- src/extension.ts | 10 ++++------ src/lsp/ClientConnectionManager.ts | 3 ++- src/utils/project_utils.ts | 25 +++++++++++++++++++----- 5 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/debugger/godot3/server_controller.ts b/src/debugger/godot3/server_controller.ts index 229113e..c57fccd 100644 --- a/src/debugger/godot3/server_controller.ts +++ b/src/debugger/godot3/server_controller.ts @@ -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"); diff --git a/src/debugger/godot4/server_controller.ts b/src/debugger/godot4/server_controller.ts index 38da6f4..737048d 100644 --- a/src/debugger/godot4/server_controller.ts +++ b/src/debugger/godot4/server_controller.ts @@ -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"); diff --git a/src/extension.ts b/src/extension.ts index e4d1313..91e04a1 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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 { 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 { diff --git a/src/lsp/ClientConnectionManager.ts b/src/lsp/ClientConnectionManager.ts index e95b075..35ded95 100644 --- a/src/lsp/ClientConnectionManager.ts +++ b/src/lsp/ClientConnectionManager.ts @@ -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) { diff --git a/src/utils/project_utils.ts b/src/utils/project_utils.ts index 54b6df6..3685553 100644 --- a/src/utils/project_utils.ts +++ b/src/utils/project_utils.ts @@ -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 { } } 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 { 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