Skip to content

Commit

Permalink
fix(dap): improve reliability of debuggable auto loading (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb authored Jan 17, 2024
1 parent a65bfa4 commit ea10533
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.16.1] - 2024-01-17

### Fixed

- DAP: Improve reliability of loading Rust debug configurations on LSP attach.
- DAP: Assign `lldb` and `codelldb` configurations found in `launch.json`
to `dap.configurations.rust`.

## [3.16.0] - 2024-01-15

### Added
Expand Down
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,17 @@ vim.keymap.set(
vim.cmd.RustLsp {'debuggables', 'last' --[[ optional ]] }
```

> [!NOTE]
>
> By default, this plugin will silently attempt to autoload `nvim-dap`
> configurations when the LSP client attaches.
> You can call them with `require('dap').continue()` once
> they have been loaded. The feature can be disabled by setting
> `vim.g.rustaceanvim.dap.autoload_configurations = false`.
By default, this plugin will silently attempt to autoload `nvim-dap`
configurations when the LSP client attaches.
You can call them with `require('dap').continue()` once
they have been loaded. The feature can be disabled by setting
`vim.g.rustaceanvim.dap.autoload_configurations = false`.

- `:RustLsp debuggables` will only load debug configurations
created by `rust-analyzer`.
- `require('dap').continue()` will load all Rust debug configurations,
including those specified in a `.vscode/launch.json`
(see [`:h dap-launch.json`](https://github.com/mfussenegger/nvim-dap/blob/9adbfdca13afbe646d09a8d7a86d5d031fb9c5a5/doc/dap.txt#L316)).

![](https://github.com/mrcjkb/rustaceanvim/assets/12857160/ce17d228-ae0a-416a-8159-fe095a85dcb7)

Expand Down
2 changes: 1 addition & 1 deletion lua/rustaceanvim/config/internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ local RustaceanDefaultConfig = {
-- It is necessary to check for changes in the `dap.configurations` table, as
-- `load_launchjs` does not return anything, it loads directly into `dap.configurations`.
local pre_launch = vim.deepcopy(dap.configurations) or {}
require('dap.ext.vscode').load_launchjs()
require('dap.ext.vscode').load_launchjs(nil, { lldb = { 'rust' }, codelldb = { 'rust' } })
for k, v in pairs(dap.configurations) do
if pre_launch[k] == nil or not vim.deep_equal(pre_launch[k], v) then
-- `configurations` are tables of `configuration` entries
Expand Down
6 changes: 3 additions & 3 deletions lua/rustaceanvim/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,12 @@ M.start = function(bufnr)

local old_on_attach = lsp_start_opts.on_attach
lsp_start_opts.on_attach = function(...)
if config.dap.autoload_configurations then
require('rustaceanvim.commands.debuggables').add_dap_debuggables()
end
if type(old_on_attach) == 'function' then
old_on_attach(...)
end
if config.dap.autoload_configurations then
require('rustaceanvim.commands.debuggables').add_dap_debuggables()
end
end

local old_on_exit = lsp_start_opts.on_exit
Expand Down
3 changes: 3 additions & 0 deletions lua/rustaceanvim/server_status.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ function M.handler(_, result, ctx, _)
if config.tools.on_initialized then
config.tools.on_initialized(result)
end
if config.dap.autoload_configurations then
require('rustaceanvim.commands.debuggables').add_dap_debuggables()
end
_ran_once[ctx.client_id] = true
end

Expand Down

0 comments on commit ea10533

Please sign in to comment.