Skip to content

Commit

Permalink
Fix mod path when both mod file and mod dir exist
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Frederick888 committed Jan 2, 2024
1 parent 48c1e14 commit 735985e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lua/neotest-rust/dap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,18 @@ end
-- Determine if mod is in <mod_name>.rs or <mod_name>/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
Expand Down

0 comments on commit 735985e

Please sign in to comment.