From 035211276d999c29afe51b3f2be775a2de5f092d Mon Sep 17 00:00:00 2001 From: Eric Cosky Date: Sat, 22 Feb 2025 09:28:38 -0800 Subject: [PATCH] Fixes for attached debugging and related improvements. (#784) 'launch' and 'attach' modes are working with these changes. The root problems were related to the version of the attached project not being detected properly and file paths not being correctly calculated when attached. The networking code that had version-dependent behavior is now a bit more robust and won't break if minor versions were to ever exceed 1 digit. When using 'attach' mode, the version info wasn't available at all, causing most (all?) network messages to be ignored. --- src/debugger/debugger.ts | 2 +- src/debugger/godot4/debug_session.ts | 5 ++++- src/debugger/godot4/server_controller.ts | 17 +++++++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/debugger/debugger.ts b/src/debugger/debugger.ts index 1d6904a..85f1f07 100644 --- a/src/debugger/debugger.ts +++ b/src/debugger/debugger.ts @@ -109,7 +109,7 @@ export class GodotDebugger implements DebugAdapterDescriptorFactory, DebugConfig log.info(`Project version identified as ${projectVersion}`); if (projectVersion.startsWith("4")) { - this.session = new Godot4DebugSession(); + this.session = new Godot4DebugSession(projectVersion); } else { this.session = new Godot3DebugSession(); } diff --git a/src/debugger/godot4/debug_session.ts b/src/debugger/godot4/debug_session.ts index b1b7f94..b215c80 100644 --- a/src/debugger/godot4/debug_session.ts +++ b/src/debugger/godot4/debug_session.ts @@ -29,11 +29,13 @@ export class GodotDebugSession extends LoggingDebugSession { public variables_manager: VariablesManager; - public constructor() { + public constructor(projectVersion : string) { super(); this.setDebuggerLinesStartAt1(false); this.setDebuggerColumnsStartAt1(false); + + this.controller.setProjectVersion(projectVersion); } public dispose() { @@ -91,6 +93,7 @@ export class GodotDebugSession extends LoggingDebugSession { this.mode = "attach"; + this.debug_data.projectPath = args.project; this.exception = false; await this.controller.attach(args); diff --git a/src/debugger/godot4/server_controller.ts b/src/debugger/godot4/server_controller.ts index b131377..e9f1ec4 100644 --- a/src/debugger/godot4/server_controller.ts +++ b/src/debugger/godot4/server_controller.ts @@ -75,10 +75,19 @@ export class ServerController { private steppingOut = false; private didFirstOutput = false; private partialStackVars: GodotPartialStackVars; - private connectedVersion = ""; + private projectVersionMajor: number; + private projectVersionMinor : number; + private projectVersionPoint : number; public constructor(public session: GodotDebugSession) {} + public setProjectVersion(projectVersion: string) { + const versionParts = projectVersion.split('.').map(Number); + this.projectVersionMajor = versionParts[0] || 0; + this.projectVersionMinor = versionParts[1] || 0; + this.projectVersionPoint = versionParts[2] || 0; + } + public break() { this.send_command("break"); } @@ -204,7 +213,7 @@ export class ServerController { } } - this.connectedVersion = result.version; + this.setProjectVersion(result.version); let command = `"${godotPath}" --path "${args.project}"`; const address = args.address.replace("tcp://", ""); @@ -381,7 +390,7 @@ export class ServerController { const command = new Command(); let i = 0; command.command = dataset[i++]; - if (this.connectedVersion[2] >= "2") { + if (this.projectVersionMinor >= 2) { command.threadId = dataset[i++]; } command.parameters = dataset[i++]; @@ -691,7 +700,7 @@ export class ServerController { private send_command(command: string, parameters?: any[]) { const commandArray: any[] = [command]; - if (this.connectedVersion[2] >= "2") { + if (this.projectVersionMinor >= 2) { commandArray.push(this.threadId); } commandArray.push(parameters ?? []);