Skip to content

Commit

Permalink
fix(dap): only load .vscode/launch.json configs that don't conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Mar 26, 2024
1 parent 76da238 commit d6fd0b7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 27 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Neotest: Correctly mark passed and skipped tests when running a
whole test file or module [[#321](https://github.com/mrcjkb/rustaceanvim/issues/321)].
- DAP: Only load `.vscode/launch.json` configurations that don't conflict
with the configured adapter type.

## [4.16.0] - 2024-03-24

Expand Down
62 changes: 35 additions & 27 deletions lua/rustaceanvim/config/internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,40 @@ local function is_lldb_adapter(adapter)
return adapter.type == 'executable'
end

---@param type string
---@return DapClientConfig
local function load_dap_configuration(type)
-- default
---@type DapClientConfig
local dap_config = {
name = 'Rust debug client',
type = type,
request = 'launch',
stopOnEntry = false,
}
---@diagnostic disable-next-line: different-requires
local dap = require('dap')
-- Load configurations from a `launch.json`.
-- 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(nil, { lldb = { 'rust' }, codelldb = { 'rust' } })
for name, configuration_entries in pairs(dap.configurations) do
if pre_launch[name] == nil or not vim.deep_equal(pre_launch[name], configuration_entries) then
-- `configurations` are tables of `configuration` entries
-- use the first `configuration` that matches
for _, entry in pairs(configuration_entries) do
---@cast entry DapClientConfig
if entry.type == type then
dap_config = entry
break
end
end
end
end
return dap_config
end

---@return RustaceanExecutor
local function get_crate_test_executor()
if vim.fn.has('nvim-0.10.0') == 1 then
Expand Down Expand Up @@ -351,40 +385,14 @@ local RustaceanDefaultConfig = {
if not ok then
return false
end

local adapter = types.evaluate(RustaceanConfig.dap.adapter)
---@cast adapter DapExecutableConfig | DapServerConfig | disable
if adapter == false then
return false
end
---@cast adapter DapExecutableConfig | DapServerConfig
local type = is_codelldb_adapter(adapter) and 'codelldb' or 'lldb'

-- default
---@type DapClientConfig
local dap_config = {
name = 'Rust debug client',
type = type,
request = 'launch',
stopOnEntry = false,
}

---@diagnostic disable-next-line: different-requires
local dap = require('dap')
-- Load configurations from a `launch.json`.
-- 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(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
-- use the first `configuration`
dap_config = v[1]
break
end
end
return dap_config
return load_dap_configuration(type)
end,
},
-- debug info
Expand Down

0 comments on commit d6fd0b7

Please sign in to comment.