Skip to content

Commit

Permalink
fix(dap): nil saftety in standalone files. (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb authored Jan 25, 2024
1 parent 2f473a3 commit bc8c4b8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ 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.17.3] - 2024-01-25

### Fixed

- DAP: `nil` safety in standalone files [[#182](https://github.com/mrcjkb/rustaceanvim/issues/182)].

## [3.17.2] - 2024-01-22

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion lua/rustaceanvim/commands/debuggables.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ local _dap_configuration_added = {}
---@field cargoArgs string[]
---@field cargoExtraArgs string[]
---@field executableArgs string[]
---@field workspaceRoot string
---@field workspaceRoot string | nil

---@param args RADebuggableArgs
---@return string
Expand Down
21 changes: 12 additions & 9 deletions lua/rustaceanvim/dap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ end
local source_maps = {}

---See https://github.com/vadimcn/codelldb/issues/204
---@param workspace_root string
---@param workspace_root? string
local function generate_source_map(workspace_root)
if source_maps[workspace_root] then
if not workspace_root or source_maps[workspace_root] then
return
end
get_rustc_commit_hash(function(commit_hash)
Expand All @@ -137,8 +137,9 @@ end
---@type {[string]: string[]}
local init_commands = {}

---@param workspace_root? string
local function get_lldb_commands(workspace_root)
if init_commands[workspace_root] then
if not workspace_root or init_commands[workspace_root] then
return
end
get_rustc_sysroot(function(rustc_sysroot)
Expand Down Expand Up @@ -182,9 +183,9 @@ local environments = {}

-- Most succinct description: https://github.com/bevyengine/bevy/issues/2589#issuecomment-1753413600
---@param adapter DapExecutableConfig | DapServerConfig
---@param workspace_root string
---@param workspace_root string | nil
local function add_dynamic_library_paths(adapter, workspace_root)
if environments[workspace_root] then
if not workspace_root or environments[workspace_root] then
return
end
compat.system({ 'rustc', '--print', 'target-libdir' }, nil, function(sc)
Expand Down Expand Up @@ -345,19 +346,21 @@ function M.start(args, verbose, callback)
final_config.cwd = args.workspaceRoot
final_config.program = executables[1]
final_config.args = args.executableArgs or {}
local environment = environments[args.workspaceRoot]
local environment = args.workspaceRoot and environments[args.workspaceRoot]
final_config = next(environment or {}) ~= nil
and vim.tbl_deep_extend('force', final_config, { env = environment })
or final_config

if string.find(final_config.type, 'lldb') ~= nil then
-- lldb specific entries
final_config = next(init_commands or {}) ~= nil
final_config = args.workspaceRoot
and next(init_commands or {}) ~= nil
and vim.tbl_deep_extend('force', final_config, { initCommands = init_commands[args.workspaceRoot] })
or final_config

local source_map = source_maps[args.workspaceRoot]
final_config = next(source_map or {}) ~= nil
local source_map = args.workspaceRoot and source_maps[args.workspaceRoot]
final_config = source_map
and next(source_map or {}) ~= nil
and vim.tbl_deep_extend('force', final_config, { sourceMap = format_source_map(adapter, source_map) })
or final_config
elseif string.find(final_config.type, 'probe%-rs') ~= nil then
Expand Down

0 comments on commit bc8c4b8

Please sign in to comment.