tomblind / local-lua-debugger-vscode

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

Allow skipping specific paths #44

Closed redsigma closed 2 years ago

redsigma commented 2 years ago

I am using this addon with busted framework and each time im running the debugger i need to cycle through a lot of busted internal files. It was ok at first but now It would be nice if there is an option to skip specific paths

For example a path such as /usr/local/share/lua/5.1/busted/environment.lua could be skipped by ignoring all paths that start with /usr/local/share/ or just /usr

Maybe this might be helpful but i'm using the following launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Busted - Lua Interpreter",
            "type": "lua-local",
            "request": "launch",
            "program": {
                "command": "busted"
            },
            "args": [
                "-o ./lua/test/glua_test.lua",
                "-m ./lua/?.lua",
                "--helper lua/test/init.lua",

                // unit testing
                "lua/test/setup.lua",
                "lua/test/file.lua"
            ],
        }
    ]
}
redsigma commented 2 years ago

I managed to find the part of code that allows me to skip files. I slightly edited debugBreak function in the following lua file extensions\tomblind.local-lua-debugger-vscode-0.2.3\debugger\lldebugger.lua. I will stick to this workaround until the feature will be implemented. Maybe the skipped files can be added as a list in settings.json

I'll update this comment in case i encounter any bugs with this workaround.

local function debugBreak(activeThread, stackOffset)
        stackOffset = stackOffset + 1
        local activeStack = getStack(stackOffset)
        local activeThreadFrameOffset = stackOffset
        breakAtDepth = -1
        breakInThread = nil
        local frameOffset = activeThreadFrameOffset
        local frame = 0
        local currentThread = activeThread
        local currentStack = activeStack
        local info = luaAssert(currentStack[frame + 1])
        local source = Path.format(
            luaAssert(info.source)
        )
        local sourceMap = SourceMap.get(source)

----
        local can_skip_file = false
        local skipped_paths = {
          "^/usr",
          "^/usr2"
        }
        for _, path in pairs(skipped_paths) do
          if source:find(path) ~= nil then
            can_skip_file = true
            break
          end
        end
        while true do
            local inp = ""
            if can_skip_file then
              inp = "stepin"
            else
              inp = getInput()
            end
----

            if (not inp) or (inp == "quit") then
                os.exit(0)
tomblind commented 2 years ago

Maybe the skipped files can be added as a list in settings.json

This was what I was thinking as well.

tomblind commented 2 years ago

@redsigma I want to clarify what it is you're looking for here. Is the issue that you have to go through busted internal files when stepping through the code? Are you not able to step over or step out in these cases?

redsigma commented 2 years ago

@redsigma I want to clarify what it is you're looking for here. Is the issue that you have to go through busted internal files when stepping through the code? Are you not able to step over or step out in these cases?

I am able to step out but only from specific files. For example if i step into one busted file and then i step out then it completely exists but if i step into 2 busted files and then step out then it stops at the correct file outside busted. Also if step into 3 busted files and i step out then it goes to another busted internal and if i step out it might go to another busted internal or to the correct file outside busted.

So it's more of a guess when it's the right moment to step out.

tomblind commented 2 years ago

Sorry, but I'm not sure I follow entirely, and I want to make sure any fix I try does what you're looking for. Can you provide a stripped down example of the scenario you're encountering?

redsigma commented 2 years ago

I managed to make a simple example of this problem

Below is a simple project called lua_test. lua_test.zip

I included the busted executable and installation files so it's easier to install, but you can also just run:

sudo apt update
sudo apt install lua-busted

The problem is the following. If you put a breakpoint on any call of asd() and step in, it will go inside the busted internal files, instead of entering the asd() function.

A workaround is to step in multiple times until you reach the asd() function or add a breakpoint inside the the asd() function and instead of step in, you jump directly to next breakpoint.

Now inside the asd() function there is another function called asd_inner(). If you want to step in this function as well , it will go again in the busted internal files. So the solution is to find this asd_inner() function and put a breakpoint inside it and then jump to this breakpoint. This approach is very hard to use because it requires to manually add a breakpoint inside each function in order to skip the internal busted files.

I hope i explained it a bit better this time.

tomblind commented 2 years ago

Thanks for the complete example. I see the issue now: busted implements extensive hooks which are quite annoying to step through. I've added an ignorePatterns option to launch.json to allow skipping over these files.

tomblind commented 2 years ago

Version 0.3.2 is now released and has this feature.

redsigma commented 2 years ago

Version 0.3.2 is now released and has this feature.

Tested and works as expected. Thanks again for adding this feature.