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

fix(dap): improve reliability of debuggable auto loading #167

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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