fannheyward / coc-rust-analyzer

rust-analyzer extension for coc.nvim
MIT License
1.13k stars 40 forks source link

Add documentation for setting up debugging #1050

Open danielrainer opened 2 years ago

danielrainer commented 2 years ago

Hi, thank you for this project!

I recently tried to get debugging to work with Vimspector. It works well now that I found out how to do it, but finding out how to set it up was quite difficult. I only managed to do it after looking into the code of this project to see how Vimspector is called when calling :CocCommand rust-analyzer.debug. It would be really nice if this project had some documentation and examples how to set up a debugger.

For reference, and because I have no better place to put it, here is how I got it to work:

relevant settings in coc-settings.json (:CocConfig):

{
  "rust-analyzer.debug.runtime": "vimspector"
}

With this setup, :CocCommand rust-analyzer.debug calls Vimspector with a dictionary containing the three keys configuration, Executable, and Args. By default configuration is set to launch (configurable with rust-analyzer.debug.vimspector.configuration.name). Executable is the file path of the Rust binary and Args the arguments passed to it.

The Vimspector plugin obviously needs to be installed. In addition, run :VimspectorInstall CodeLLDB.

Vimspector needs to be configured with a config file. It can either be in the Rust project root and called .vimspector.json or a global config file (see https://puremourning.github.io/vimspector/configuration.html#project-and-global-configurations). The config file should look like this:

{
  "$schema": "https://puremourning.github.io/vimspector/schema/vimspector.schema.json",
  "configurations": {
    "launch": {
      "adapter": "CodeLLDB",
      "configuration": {
        "request": "launch",
        "program": "${Executable}",
        "args": [ "*${Args}" ]
      }
    }
  }
}

The key launch must be the same as rust-analyzer.debug.vimspector.configuration.name. The values "${Executable}" and [ "*${Args}" ] are automatically replaced by the values passed in by coc-rust-analyzer.

At this point, it should be possible to run Rust executables and tests with :CocCommand rust-analyzer.debug.

timsu92 commented 1 year ago

Wow! Thanks a lot both of you!

SeniorMars commented 1 year ago

I made a video on this some time ago: https://www.youtube.com/watch?v=U3uvbdgFMRE

Though it would be nice if documentation was provided in the readme. I've also been waiting for dap support in coc.

timsu92 commented 1 year ago

I would suggest you try Vimspector.

fannheyward commented 1 year ago

Thank you guys, to be honest I didn't use debugging in vim/nvim. You're welcome to submit a PR for setting up debugging.

SeniorMars commented 1 year ago

Honestly, that's interesting! I'd like to know if you could tell us what your debugging setup looks like.