From 5e9ea75cc59ea60d712b2f32a3fc4c5909160690 Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Wed, 12 Jun 2024 10:32:46 +0200 Subject: [PATCH] feat: delegate non-Go project folder to next strategy --- lua/neotest-golang/init.lua | 2 -- lua/neotest-golang/runspec_dir.lua | 11 +++++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lua/neotest-golang/init.lua b/lua/neotest-golang/init.lua index d0aba9c9..4e2ceac3 100644 --- a/lua/neotest-golang/init.lua +++ b/lua/neotest-golang/init.lua @@ -104,8 +104,6 @@ function M.Adapter.build_spec(args) -- to compile. This approach is too brittle, and therefore this mode is not -- supported. Instead, the tests of a file are run as if pos.typ == "test". - vim.notify("Would've executed a file: " .. pos.path) - return -- delegate test execution to per-test execution end elseif pos.type == "test" then diff --git a/lua/neotest-golang/runspec_dir.lua b/lua/neotest-golang/runspec_dir.lua index 401d7b30..4c5ecc35 100644 --- a/lua/neotest-golang/runspec_dir.lua +++ b/lua/neotest-golang/runspec_dir.lua @@ -6,14 +6,21 @@ local M = {} --- Build runspec for a directory. ---@param pos neotest.Position ----@return neotest.RunSpec +---@return neotest.RunSpec | nil function M.build(pos) -- Strategy: -- 1. Find the go.mod file from pos.path. -- 2. Run `go test` from the directory containing the go.mod file. -- 3. Use the relative path from the go.mod file to pos.path as the test pattern. - local go_mod_filepath = M.find_file_upwards("go.mod", pos.path) + if go_mod_filepath == nil then + vim.notify( + "The selected folder is not a Go project, attempting different strategy.", + vim.log.levels.WARN + ) + return nil -- Deletgates away from the dir strategy + end + local go_mod_folderpath = vim.fn.fnamemodify(go_mod_filepath, ":h") local cwd = go_mod_folderpath