jbyuki/one-small-step-for-vimkind

Does this plugin work with vimspector?

medwatt opened this issue · 12 comments

The readme mentions that one of vimspector or nvim-dap can be used. There's no information how to configure this plugin to work with vimspector. Can you please provide one?

I could try to make one in the coming days. It should fairly similar to nvim-dap. To be honest, I never used vimspector because of how good nvim-dap already is. But it could be interesting to explore vimspector as well.

This should get you going.
I assume you know vimspector so you can fix my ugly config.

{
  "$schema": "https://puremourning.github.io/vimspector/schema/vimspector.schema.json#",
  "adapters": {
    "nlua": {
      "host": "127.0.0.1",
      "port": "8086"
    }
  },

  "configurations": {
    "osv": {
      "adapter": "nlua",
      "configuration": {
        "request": "attach"
      }
    }
  }
}

where the osv server is launched using :lua require"osv".launch({port=8086}).

Thanks for this. I ran this first lua require"osv".launch({port=8086} and tried to debug some lua code. I get the message Connecting to 127 ... attempt (1 of 10). After a while, it says Unable to set breakpoint: Timeout.

Here it is in action.
Maybe the lua file wasn't sourced in time.

2021-10-30.15-07-11.online-video-cutter.com.mp4

Thanks for the demo. Here's how things look on my end. Just to be clear, I simply have this plugin installed and I am using vimspector config you posted above. Do I need other plugins or possibly need to set up this configuration for this plugin?

I'm not 100% sure just by looking at the video and how the terminal is setup but do you launch the server in a different neovim instance? You can see in my demo that I'm switching tabs.

Normally, you don't need any configuration on osv's side.

I tried running the server in a different instance--that did not solve the issue. Why exactly did you run luafile hello.lua? Also, why didn't the result of the script get printed in the command window?

OK, let me try to explain it.

One thing that should be made clear is what exactly happens on vimspector#continue .

You hit vimspector#continue and then...

  • Vimspector reads the corresponding config. I'm guessing this because I'm not familiar with vimspector internals.
  • The config adapter is set on attach which means, vimspector will try to attach to a running process. The running process is actually another neovim instance in our case, the one where osv.launch was invoked. The client connects to the server. Using the provided host and port, it will try to connect to it using TCP. Note: A "launch" variant is also possible where vimspector launches the process by itself and attach to it. Currently osv does not support this out of the box, although it would be possible. But that would'nt make a lot of sense to debug interaction based plugins.
  • Once connected, it will send some packets back and forth for initialization, breakpoints, etc...

That's it. It won't run the lua file. That's why I'm manually sourcing it using luafile.

I suggest reading just the introduction part for the DAP protocol. There might be details that I didn't properly explain here.

Maybe using this explanations, you could see what's the problem. It should theortically work. I suspect just a wrong manipulation.

In my case, when I run luafile filename, the result get printed. I want to use nvim-dap, but it's too cumbersome to use compared to vimspector.

You could try to launch osv with logging. See :help osv on how to. The resulting log is located in nvim-data/osv.log (use echo stdpath('data') to locate nvim-data).

xbot commented

@jbyuki I got the same problem, and the log is as follows:

{
  arguments = {
    name = "test",
    request = "attach"
  },
  command = "attach",
  seq = 1,
  type = "request"
}
{
  arguments = {
    breakpoints = { {
        line = 10
      } },
    source = {
      name = "test.lua",
      path = "/Users/donie/Desktop/test.lua"
    },
    sourceModified = false
  },
  command = "setBreakpoints",
  seq = 2,
  type = "request"
}
{
  arguments = {
    filters = {}
  },
  command = "setExceptionBreakpoints",
  seq = 3,
  type = "request"
}
Could not handle setExceptionBreakpoints
{
  command = "threads",
  seq = 4,
  type = "request"
}

I use exactly the same configuration as yours, nvim-dap works great but vimspector does not.

Thank you for your log. It looks like this is caused because the setExceptionBreakpoints request is not handled by the server. I will take a quick look into it.