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

How to use with larger projects #7

Closed
TC72 opened this issue Sep 17, 2021 · 8 comments
Closed

How to use with larger projects #7

TC72 opened this issue Sep 17, 2021 · 8 comments

Comments

@TC72
Copy link

TC72 commented Sep 17, 2021

I followed your example and I can get dap to stop at breakpoints. (not always, sometimes it doesn't work with the simple example.)

I wanted to ask how I can use dam with larger projects? I'd like to debug Telescope to help me writing an extension.
I've added a breakpoint which should stop when I open my Telescope picker but it never stops.
In this case I don't use `luafile myscript.lua' as that's not how the function would be called.

@TC72 TC72 changed the title Only works sometimes How to use with larger projects Sep 18, 2021
@jbyuki
Copy link
Owner

jbyuki commented Sep 18, 2021

I wanted to ask how I can use dam with larger projects? I'd like to debug Telescope to help me writing an extension.
I've added a breakpoint which should stop when I open my Telescope picker but it never stops.
In this case I don't use `luafile myscript.lua' as that's not how the function would be called.

Are you using packer.nvim to manage your plugin extension? There is a catch explained here.

Basically you need to open the source file located in the nvim-data directory (echo stdpath('data')) and not your local plugin source files. You must first close nvim to make sure it opens the right file and not the symlinked file.

If that's not the problem, please describe how you are starting the debugging session so that I can reproduce it.

@jbyuki
Copy link
Owner

jbyuki commented Sep 18, 2021

I followed your example and I can get dap to stop at breakpoints. (not always, sometimes it doesn't work with the simple example.)

That's strange, not sure what could be the issue. But in the case of debugging, I would say it's okay if it only works once.

You can try to use the test script located in test/test.lua which automatically starts a debugging session and test if the breakpoint hits. You just need to put test/input.lua in your home directory. Then execute the script using luafile. See if it breaks consistently.

@jbyuki jbyuki closed this as completed Sep 20, 2021
@TC72
Copy link
Author

TC72 commented Sep 21, 2021

Running the test.lua works, I see the output on my screen which looks good and result.txt says OK.

I'll explain exactly what I'm trying to do.
I am using vim-plug to manage my plugins.

  1. (A) In a terminal I open neovim with nvim empty, this is (A).
  2. (A) in neovim I use :lua require"osv".launch() and get the port number.
  3. (B) I open another neovim with the file I want to debug nvim ~/.config/nvim/plugged/telescope.nvim/lua/telescope/builtin/internal.lua, this is (B).
  4. (B) I add a breakpoint on line 38:local title = "Telescope Builtin"
    This is inside the function internal.builtin = function(opts)
  5. (B) I run :lua require"dap".continue()
  6. (A) I run the function internal.builtin using :Telescope

Telescope runs normally without being stopped at the breakpoint.
Should I be able to debug something like this?

After doing this I ran through using your quickstart example and it worked fine, stops on the breakpoint I set.

@jbyuki
Copy link
Owner

jbyuki commented Sep 22, 2021

I just tested it on my machine and it seems to work. The issue might just be a misconfigured dap configuration or something.

Here is my debugging session in action:

2021-09-22.21-40-43.mov

Hopefully the commands are visible in the video.

The dap config I use is:

local dap = require"dap"
dap.configurations.lua = { 
  { 
    type = 'nlua', 
    request = 'attach',
    name = "Attach to running Neovim instance",
  }
}

dap.adapters.nlua = function(callback, config)
  callback({ type = 'server', host = config.host or "127.0.0.1", port = config.port or 8086 })
end

vim.api.nvim_set_keymap('n', '<F8>', [[:lua require"dap".toggle_breakpoint()<CR>]], { noremap = true })
vim.api.nvim_set_keymap('n', '<F9>', [[:lua require"dap".continue()<CR>]], { noremap = true })
vim.api.nvim_set_keymap('n', '<F10>', [[:lua require"dap".step_over()<CR>]], { noremap = true })
vim.api.nvim_set_keymap('n', '<S-F10>', [[:lua require"dap".step_into()<CR>]], { noremap = true })
vim.api.nvim_set_keymap('n', '<F12>', [[:lua require"dap.ui.variables".hover()<CR>]], { noremap = true })
vim.api.nvim_set_keymap('n', '<F5>', [[:lua require"osv".launch({port = 8086})<CR>]], { noremap = true })
vim.api.nvim_set_keymap('n', '<F6>', [[:lua require"osv".run_this()<CR>]], { noremap = true })

@TC72
Copy link
Author

TC72 commented Sep 23, 2021

Thanks so much for taking the time to test this. The problem is with my set-up.

I use Dropbox to share my dotfiles between computers, my ~/.config/nvim is a link to a Dropbox folder.
I duplicated that folder so my ~/.config/nvim was no longer a link and the debugger works.

I know I should be able to use links as your help files show how to do this for debugging plugins if you use packer.nvim.
Before removing the link I did try the debugger using the Dropbox path but it didn't work.

The problem isn't Dropbox, it's using links in general on my machine.
I renamed the new local ~/.config/nvim to ~/.config/nvim-local. Then I created a new link nvim to that nvim-local folder.
Again with this link the debugger doesn't work, I've tried opening the intenral.lua file in lots of different ways but none of them work.

I know this isn't a problem with your plugin, it's my set-up, I'll just move to using the local folder.
Again thanks for checking this out and sorry for wasting your time with an issue with my set-up.

@jbyuki
Copy link
Owner

jbyuki commented Sep 23, 2021

Well, it seems you tried a lot of things so you probably wasted more time than I did.

Just as a small help maybe you can see which files is executed in neovim (which internal.lua) using debug.sethook. This is essentially what osv is using. Set a hook for each line then try to catch if there is internal.lua which is executed on calling telescope. debug.getinfo(2).source will return the source path.

If you give me the complete path, it's possible it's just a string formatting error which I can then fix. Otherwise if on local it works for you then nevermind.

@TC72
Copy link
Author

TC72 commented Sep 23, 2021

I couldn't follow exactly what you asked but I was able to get something out by using my own logfile function, mylog.debug and adding this line of code inside internal.builtin:

mylog.debug(debug.getinfo(2))

The output for source was:

source = "@/Users/tc72/.config/nvim/plugged/telescope.nvim/lua/telescope/builtin/internal.lua"

I then set a breakpoint using dap.toggle_breakpoint() and sent the list of breakpoints to the quickfix window with dap.list_breakpoints()

It showed this:

Dropbox/dotfiles/vim/plugged/telescope.nvim/lua/telescope/builtin/internal.lua|38| local title = "Telescope Builtin"

Does that show it's not working because the paths don't match?

If I use :cd ~/.config/nvim inside neovim when I call :pwd it shows the Dropbox path:

/Users/tc72/Dropbox/dotfiles/vim

@jbyuki
Copy link
Owner

jbyuki commented Sep 25, 2021

This seems to be more than an simple path formatting issue. Maybe changing the vim-plug working directory to the dropbox path could solve the problem. But there might be other consequences which raises other problems.

You're welcome to submit a PR. I will assist you if you need any help.

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

2 participants