From a13e311d449034b49d0144a411e0c8be3d5354cd Mon Sep 17 00:00:00 2001 From: Marc Jakobi Date: Mon, 18 Dec 2023 20:00:18 +0100 Subject: [PATCH] fix(dap): only add sourceMap and lldb commands if the files exist (#102) --- CHANGELOG.md | 3 ++- lua/rustaceanvim/commands/crate_graph.lua | 2 +- lua/rustaceanvim/dap.lua | 21 +++++++++++++++++---- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ed9bf0e..603424cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,10 +6,11 @@ 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). -## [Unreleased] +## [3.10.2] - 2023-12-18 ### Fixed +- DAP: Only add sourceMap and lldb commands if the files exist. - DAP (Windows): Fixed .exe extension in mason.nvim codelldb detection. Thanks [@svermeulen](https://github.com/svermeulen)! diff --git a/lua/rustaceanvim/commands/crate_graph.lua b/lua/rustaceanvim/commands/crate_graph.lua index de31be96..86d784ef 100644 --- a/lua/rustaceanvim/commands/crate_graph.lua +++ b/lua/rustaceanvim/commands/crate_graph.lua @@ -39,7 +39,7 @@ local function handler_factory(backend, output, pipe) end graph = string.gsub(graph, '\n', '') - print('rust-tools: Processing crate graph. This may take a while...') + vim.notify('rustaceanvim: Processing crate graph. This may take a while...') local cmd = 'dot -T' .. backend if pipe ~= nil then -- optionally pipe to `pipe` diff --git a/lua/rustaceanvim/dap.lua b/lua/rustaceanvim/dap.lua index f01dcc82..07e38bca 100644 --- a/lua/rustaceanvim/dap.lua +++ b/lua/rustaceanvim/dap.lua @@ -112,9 +112,20 @@ local source_maps = {} local function generate_source_map(workspace_root) get_rustc_commit_hash(function(commit_hash) get_rustc_sysroot(function(rustc_sysroot) + local src_path + for _, src_dir in pairs { 'src', 'rustc-src' } do + src_path = compat.joinpath(rustc_sysroot, 'lib', 'rustlib', src_dir, 'rust') + if compat.uv.fs_stat(src_path) then + break + end + src_path = nil + end + if not src_path then + return + end ---@type DapSourceMap local new_map = { - [compat.joinpath('/rustc', commit_hash)] = compat.joinpath(rustc_sysroot, 'lib', 'rustlib', 'src', 'rust'), + [compat.joinpath('/rustc', commit_hash)] = src_path, } source_maps[workspace_root] = vim.tbl_extend('force', source_maps[workspace_root] or {}, new_map) end) @@ -126,9 +137,11 @@ local init_commands = {} local function get_lldb_commands(workspace_root) get_rustc_sysroot(function(rustc_sysroot) - local script_import = 'command script import "' - .. compat.joinpath(rustc_sysroot, 'lib', 'rustlib', 'etc', 'lldb_lookup.py') - .. '"' + local script = compat.joinpath(rustc_sysroot, 'lib', 'rustlib', 'etc', 'lldb_lookup.py') + if not compat.uv.fs_stat(script) then + return + end + local script_import = 'command script import "' .. script .. '"' local commands_file = compat.joinpath(rustc_sysroot, 'lib', 'rustlib', 'etc', 'lldb_commands') local file = io.open(commands_file, 'r') local workspace_root_cmds = {}