Skip to content

Commit 5365577

Browse files
author
Marc Jakobi
committed
fix(dap): nil saftety in standalone files.
1 parent 2f473a3 commit 5365577

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ All notable changes to this project will be documented in this file.
66
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
77
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
88

9+
## [3.17.3] - 2024-01-25
10+
11+
### Fixed
12+
13+
- DAP: `nil` safety in standalone files [[#182](https://github.com/mrcjkb/rustaceanvim/issues/182)].
14+
915
## [3.17.2] - 2024-01-22
1016

1117
### Fixed

lua/rustaceanvim/commands/debuggables.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ local _dap_configuration_added = {}
1515
---@field cargoArgs string[]
1616
---@field cargoExtraArgs string[]
1717
---@field executableArgs string[]
18-
---@field workspaceRoot string
18+
---@field workspaceRoot string | nil
1919

2020
---@param args RADebuggableArgs
2121
---@return string

lua/rustaceanvim/dap.lua

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ end
108108
local source_maps = {}
109109

110110
---See https://github.com/vadimcn/codelldb/issues/204
111-
---@param workspace_root string
111+
---@param workspace_root? string
112112
local function generate_source_map(workspace_root)
113-
if source_maps[workspace_root] then
113+
if not workspace_root or source_maps[workspace_root] then
114114
return
115115
end
116116
get_rustc_commit_hash(function(commit_hash)
@@ -137,8 +137,9 @@ end
137137
---@type {[string]: string[]}
138138
local init_commands = {}
139139

140+
---@param workspace_root? string
140141
local function get_lldb_commands(workspace_root)
141-
if init_commands[workspace_root] then
142+
if not workspace_root or init_commands[workspace_root] then
142143
return
143144
end
144145
get_rustc_sysroot(function(rustc_sysroot)
@@ -182,9 +183,9 @@ local environments = {}
182183

183184
-- Most succinct description: https://github.com/bevyengine/bevy/issues/2589#issuecomment-1753413600
184185
---@param adapter DapExecutableConfig | DapServerConfig
185-
---@param workspace_root string
186+
---@param workspace_root string | nil
186187
local function add_dynamic_library_paths(adapter, workspace_root)
187-
if environments[workspace_root] then
188+
if not workspace_root or environments[workspace_root] then
188189
return
189190
end
190191
compat.system({ 'rustc', '--print', 'target-libdir' }, nil, function(sc)
@@ -345,19 +346,21 @@ function M.start(args, verbose, callback)
345346
final_config.cwd = args.workspaceRoot
346347
final_config.program = executables[1]
347348
final_config.args = args.executableArgs or {}
348-
local environment = environments[args.workspaceRoot]
349+
local environment = args.workspaceRoot and environments[args.workspaceRoot]
349350
final_config = next(environment or {}) ~= nil
350351
and vim.tbl_deep_extend('force', final_config, { env = environment })
351352
or final_config
352353

353354
if string.find(final_config.type, 'lldb') ~= nil then
354355
-- lldb specific entries
355-
final_config = next(init_commands or {}) ~= nil
356+
final_config = args.workspaceRoot
357+
and next(init_commands or {}) ~= nil
356358
and vim.tbl_deep_extend('force', final_config, { initCommands = init_commands[args.workspaceRoot] })
357359
or final_config
358360

359-
local source_map = source_maps[args.workspaceRoot]
360-
final_config = next(source_map or {}) ~= nil
361+
local source_map = args.workspaceRoot and source_maps[args.workspaceRoot]
362+
final_config = source_map
363+
and next(source_map or {}) ~= nil
361364
and vim.tbl_deep_extend('force', final_config, { sourceMap = format_source_map(adapter, source_map) })
362365
or final_config
363366
elseif string.find(final_config.type, 'probe%-rs') ~= nil then

0 commit comments

Comments
 (0)