Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breakpoint does not work if working directory path contains symbolic link #74

Open
shu-bc opened this issue Mar 20, 2024 · 2 comments
Open

Comments

@shu-bc
Copy link

shu-bc commented Mar 20, 2024

I found that if current working directory path contains symbolic link, running require('dap-go').debug_test() will ignore breakpoint.


It is like following:

  • create directory ~/workspace/gotest
  • create directory & files like this
スクリーンショット 2024-03-20 17 16 11
  • create symbolic link in home directory, by run ln -s gotest ~/workspace/gotest
  • change directory through symblic link, cd gotest

Then set arbitrary breakpoint, and run require('dap-go').debug_test().

This will not happen by running require('dap').cotinue() and select 1 to debug main.go, even working directory path contains symbolic link. So I suppose it is caused by debug_test function.

@leoluz
Copy link
Owner

leoluz commented Mar 25, 2024

It seems that this is the problem:
https://github.com/leoluz/nvim-dap-go/blob/36abe1d320cb61bfdf094d4e0fe815ef58f2302a/lua/dap-go-ts.lua#L137C27-L137C59
I didn't initially found a filename modifier to work with symlinks:
https://neovim.io/doc/user/cmdline.html#filename-modifiers

Maybe consider using real files instead of symlinks?

@marcsc13
Copy link

marcsc13 commented Sep 8, 2024

jTo be upfront, there is probably a better way of solving this. I have a workaround which is described below.

I open my projects in /home/marc/dev which is a symlink to /mnt/Data/dev on an additional SSD mounted to /mnt/Data during startup. You might need to change the paths.

I solved it with overwriting the config which is passed to dap when calling nvim-dap-go.debug_test():

{
    "leoluz/nvim-dap-go",
    event = "VeryLazy",
    ft = "go",
    dependencies = { "nvim-dap", "rcarriga/nvim-dap-ui" },
    config = function(_, opts)
      local dap, dapui = require "dap", require "dapui"
      local dapgo = require "dap-go"
      dapgo.setup(opts)
      dapui.setup()
      map("n", "<leader>dgt", function()
        local function debug_test(testname, testpath, build_flags, extra_args)
          local config = {
            type = "go",
            name = testname,
            request = "launch",
            mode = "test",
            program = testpath,
            args = { "-test.run", "^" .. testname .. "$" },
            buildFlags = build_flags,
            substitutePath = {
              { from = "/mnt/Data/dev", to = "/home/marc/dev" },
            },
          }

          if not vim.tbl_isempty(extra_args) then
            table.move(extra_args, 1, #extra_args, #config.args + 1, config.args)
          end

          dap.run(config)
        end
        local dapgots = require "dap-go-ts"
        local test = dapgots.closest_test()

        if test.name == "" or test.name == nil then
          vim.notify "no test found"
          return false
        end

        dapgo.last_testname = test.name
        dapgo.last_testpath = test.package

        local msg = string.format("starting debug session '%s : %s'...", test.package, test.name)
        vim.notify(msg)

        local extra_args = {}
        debug_test(test.name, test.package, dapgo.test_buildflags, extra_args)
        dapui.open()
      end, { desc = "Debug go test" })
    end,
  },

No other methods were overwritten. test.package returns the correct path for me.

delve or dap (don't know to be honest) provide a way of substituting paths when symlinks are used. https://go.googlesource.com/vscode-go/+/c3516da303907ca11ee51e64f961cf2a4ac5339a/docs/dlv-dap.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants