Skip to content

Commit

Permalink
feat: Specify full path for umbrella projects (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfpedroza authored Nov 26, 2023
1 parent 412e553 commit 3117ca5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
15 changes: 14 additions & 1 deletion lua/neotest-elixir/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,21 @@ local Path = require("plenary.path")

local M = {}

function M.mix_root(file_path)
local root = lib.files.match_root_pattern("mix.exs")(file_path)

-- If the path found is inside an umbrella, return the root of the umbrella
if root ~= nil and root:match("/apps/[%w_]+$") then
local new_root = lib.files.match_root_pattern("mix.exs")(root:gsub("/apps/[%w_]+$", ""))

return new_root or root
end

return root
end

local function relative_to_cwd(path)
local root = lib.files.match_root_pattern("mix.exs")(path)
local root = M.mix_root(path)
return Path:new(path):make_relative(root)
end

Expand Down
8 changes: 2 additions & 6 deletions lua/neotest-elixir/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,8 @@ local function post_process_command(cmd)
return cmd
end

local function mix_root(file_path)
return lib.files.match_root_pattern("mix.exs")(file_path)
end

local function get_relative_path(file_path)
local mix_root_path = mix_root(file_path)
local mix_root_path = core.mix_root(file_path)
local root_elems = vim.split(mix_root_path, Path.path.sep)
local elems = vim.split(file_path, Path.path.sep)
return table.concat({ unpack(elems, (#root_elems + 1), #elems) }, Path.path.sep)
Expand All @@ -70,7 +66,7 @@ function ElixirNeotestAdapter._generate_id(position, parents)
end
end

ElixirNeotestAdapter.root = lib.files.match_root_pattern("mix.exs")
ElixirNeotestAdapter.root = core.mix_root

function ElixirNeotestAdapter.filter_dir(_, rel_path, _)
return rel_path == "test"
Expand Down

0 comments on commit 3117ca5

Please sign in to comment.