maziac / DeZog

Visual Studio Code Debugger for Z80/ZX Spectrum.
MIT License
210 stars 34 forks source link

rootFolder seems to be ignored #48

Closed bereal closed 3 years ago

bereal commented 3 years ago

Describe the bug DeZog can't seem to resolve workspace folder paths

To Reproduce

I have multiple projects in my VSCode workspace, one of them is a Z80 projects.

Here is my entire zx/.vscode/launch.json:

{
    "configurations": [
        {
            "rootFolder": "${workspaceFolder}",
            "type": "dezog",
            "request": "launch",
            "name": "DeZog",
            "remoteType": "zsim",
            "zsim": {
                "loadZxRom": true
            },
            "sjasmplus": [
                {
                    "path": "bin/out.list"
                }
            ],
            "startAutomatically": false,
            "history": {
                "reverseDebugInstructionCount": 10000,
                "codeCoverageEnabled": true
            },
            "commandsAfterLaunch": [
                //"-sprites",
                //"-patterns"
            ],
            "disassemblerArgs": {
                "numberOfLines": 20,
                "esxdosRst": true
            },
            "topOfStack": "0xffff",
            "loadObjs": [
                {
                    "path": "bin/out.bin",
                    "start": "0x6000"
                },
                {
                    "path": "bin/resources.bin",
                    "start": "0x8000"
                }
            ],
            "execAddress": "0x6000",
            "smallValuesMaximum": 513,
            "tmpDir": ".tmp"
        }
    ]
}

When I try running the project, the error message is like

'path': File /home/bereal/ws/other-folder/bin/out.list does not exist.

So it tries to find it in a wrong workspace folder. If I add prefix ${workspaceFolder}/ to all the paths, it launches, but immediately fails to find the source path, still looking for it in another project.

Version etc. (please complete the following information):

VSCode: 1.53.2 OS: Linux x64 5.10.7-3-MANJARO DeZog SW Version: v2.1.7 Remote: zsim

bereal commented 3 years ago

After debugging a bit, I found a solution by patching settings.ts as follows:

diff --git a/src/debugadapter.ts b/src/debugadapter.ts
index 1a71edf..a8e26ad 100755
--- a/src/debugadapter.ts
+++ b/src/debugadapter.ts
@@ -429,7 +429,10 @@ export class DebugSessionClass extends DebugSession {
                        Utility.setRootPath((vscode.workspace.workspaceFolders) ? vscode.workspace.workspaceFolders[0].uri.fsPath : '');

                        // Save args
-                   const rootFolder=(vscode.workspace.workspaceFolders)? vscode.workspace.workspaceFolders[0].uri.fsPath:'';
+                   const rootFolder = args.rootFolder || (
+                         (vscode.workspace.workspaceFolders) ? vscode.workspace.workspaceFolders[0].uri.fsPath : '');
+                   Utility.setRootPath(rootFolder);
+
                        Settings.Init(args, rootFolder);
                        Settings.CheckSettings();
                }

I'm not sure if this aligns with the project design, in particular, whether this is a proper place to set Utility.rootPath, but at least solved my problem. Let know if this helps, I can make a PR then.

maziac commented 3 years ago

Thanks for finding (and solving). Yes, this should be the solution. This root folder code in DeZog is rather old, even older than the workspace concept. But it doesn't make any sense to ignore the args.rootFolder.

No need to do a PR. I will include the change as:

            const rootFolder = args.rootFolder || vscode.workspace.workspaceFolders![0].uri.fsPath;
            Utility.setRootPath(rootFolder);

I.e. when there is a launch.json there always should also be a workspaceFolder, so I'm not checking this anymore.

Furthermore I think I have to change a few other location where I used it for the Z80 unit tests.