tomblind / local-lua-debugger-vscode

Local Lua Debugger for VSCode
MIT License
107 stars 26 forks source link

Breakpoints don't work when program.file is set to relative parent path #62

Open rewqazxv opened 2 years ago

rewqazxv commented 2 years ago

Example file structure:

test/
  main.lua

All breakpoints work when I set program.file to ./main.lua, but when I change program.file to ../test/main.lua, the lua interpreter runs to the end without breaking.

My environments: vscode version 1.68.0, local lua debugger version 0.3.3

s6mike commented 2 years ago

@rewqazxv within the launch.json the following structure has worked for me:

"program": {
                "lua": "lua5.3",
                "file": "${workspaceFolder}/test/main.lua",
            },

Perhaps worth trying?

rewqazxv commented 2 years ago

@s6mike it works, but the problem is that the file path cannot contain .. I put a realpath command in the path field to solve it:

"program": {
    "lua": "lua",
    "file": "`realpath ../test/main.lua`",
},
rewqazxv commented 2 years ago

I found the getAbsolute function in debugger/path.ts to be too simplistic for Windows paths, which could be a potential problem.

For example:

Ref: https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats

ogsadmin commented 1 year ago

@rewqazxv: Thanks for the hints and the code in your #71 pull request. However it did not fully fix it for me (under Windows). It seems like #57 (file name case) is also relevant, so I changed the comparePaths(a,b) function in lldebugger.lua to make the compare lowercase:

    local function comparePaths(a, b)
    return Path.getAbsolute(a):lower() == Path.getAbsolute(b):lower();
    end

For Windows, the Path.getCwd() function did not work for me (popen seems to be missing, I am using a custom lua build), so I replaced it using lfs.currentdir() as follows:

    function Path.getCwd()
        if not cwd then
            local lfs = require('lfs')
            cwd = lfs.currentdir()
        end
        return cwd
    end

As I have no idea on how to do my own local-lua-debugger build, I've simply changed the code shown above directly in the VSCode extension folder location at %USERPROFILE%\.vscode\extensions\tomblind.local-lua-debugger-vscode-0.3.3\debugger\lldebugger.lua (knowing my changes will likely get overwritten with the next extension update). Anyway, maybe it helps others using this very nice extension (a big thank you to @tomblind) on Windows.

Final note: The issue (missed breakpoints) did not occur consistently between multiple machines (same project/file/folder structure, on some machines it worked on others not). After applying the fixes, it worked for all machines (however, as I've also cleaned up the VSCode workspace folder (as suggested in #55), I am not a 100% sure, if the lldebugger.lua changes described above fix all cases or if a cleanup of the VSCode workspace is additionally needed).