From c9c5e33186b8c4c1e94cdbad4d496b2411af8381 Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Thu, 11 Jul 2024 21:04:44 +0200 Subject: [PATCH] fix: runspec for dir/file did not properly detect go package (#110) --- lua/neotest-golang/runspec_dir.lua | 8 ++++++-- lua/neotest-golang/runspec_file.lua | 7 ++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lua/neotest-golang/runspec_dir.lua b/lua/neotest-golang/runspec_dir.lua index dd0c56c2..bd262320 100644 --- a/lua/neotest-golang/runspec_dir.lua +++ b/lua/neotest-golang/runspec_dir.lua @@ -29,8 +29,12 @@ function M.build(pos) local package_name = "./..." for _, golist_item in ipairs(golist_data) do if pos.path == golist_item.Dir then - package_name = golist_item.ImportPath - break + if golist_item.Name == "main" then + -- do nothing, keep ./... + else + package_name = golist_item.ImportPath + break + end end end diff --git a/lua/neotest-golang/runspec_file.lua b/lua/neotest-golang/runspec_file.lua index 2baf95d3..39e07462 100644 --- a/lua/neotest-golang/runspec_file.lua +++ b/lua/neotest-golang/runspec_file.lua @@ -28,9 +28,14 @@ function M.build(pos, tree) -- find the go package that corresponds to the pos.path local package_name = "./..." local pos_path_filename = vim.fn.fnamemodify(pos.path, ":t") + local pos_path_foldername = vim.fn.fnamemodify(pos.path, ":h") + for _, golist_item in ipairs(golist_data) do if golist_item.TestGoFiles ~= nil then - if vim.tbl_contains(golist_item.TestGoFiles, pos_path_filename) then + if + pos_path_foldername == golist_item.Dir + and vim.tbl_contains(golist_item.TestGoFiles, pos_path_filename) + then package_name = golist_item.ImportPath break end