From 735985e15f5209baddd939d667a3521411221fd8 Mon Sep 17 00:00:00 2001 From: Frederick Zhang Date: Wed, 3 Jan 2024 01:42:08 +1100 Subject: [PATCH] Fix mod path when both mod file and mod dir exist When both src/parent.rs and src/parent/ exist, construct_mod_path can be called with construct_mod_path('src/parent.rs', 'child'). In this case it should return src/parent/child.rs instead of nil. --- lua/neotest-rust/dap.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lua/neotest-rust/dap.lua b/lua/neotest-rust/dap.lua index 886ca96..174dce9 100644 --- a/lua/neotest-rust/dap.lua +++ b/lua/neotest-rust/dap.lua @@ -83,15 +83,18 @@ end -- Determine if mod is in .rs or /mod.rs local function construct_mod_path(src_path, mod_name) local match_str = "(.-)[^\\/]-%.?(%w+)%.?[^\\/]*$" - local abs_path, _ = string.match(src_path, match_str) + local abs_path, parent_mod = string.match(src_path, match_str) local mod_file = abs_path .. mod_name .. ".rs" local mod_dir = abs_path .. mod_name .. sep .. "mod.rs" + local child_mod = abs_path .. parent_mod .. sep .. mod_name .. ".rs" if util.file_exists(mod_file) then return mod_file elseif util.file_exists(mod_dir) then return mod_dir + elseif util.file_exists(child_mod) then + return child_mod end return nil