From 43985f1a536e0f62358039bb34ef2c1918bead46 Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Sun, 8 Sep 2024 22:19:55 +0200 Subject: [PATCH] refactor: use tree:data().type for position type --- lua/neotest-golang/init.lua | 12 +++++++----- lua/neotest-golang/process.lua | 14 -------------- lua/neotest-golang/runspec/dir.lua | 1 - lua/neotest-golang/runspec/file.lua | 2 -- lua/neotest-golang/runspec/namespace.lua | 1 - lua/neotest-golang/runspec/test.lua | 1 - 6 files changed, 7 insertions(+), 24 deletions(-) diff --git a/lua/neotest-golang/init.lua b/lua/neotest-golang/init.lua index bc024375..fae98ed5 100644 --- a/lua/neotest-golang/init.lua +++ b/lua/neotest-golang/init.lua @@ -135,25 +135,27 @@ end --- @param tree neotest.Tree --- @return table | nil function M.Adapter.results(spec, result, tree) - if spec.context.pos_type == "dir" then + local pos = tree:data() + + if pos.type == "dir" then -- A test command executed a directory of tests and the output/status must -- now be processed. local results = process.test_results(spec, result, tree) M.workaround_neotest_issue_391(result) return results - elseif spec.context.pos_type == "file" then + elseif pos.type == "file" then -- A test command executed a file of tests and the output/status must -- now be processed. local results = process.test_results(spec, result, tree) M.workaround_neotest_issue_391(result) return results - elseif spec.context.pos_type == "namespace" then + elseif pos.type == "namespace" then -- A test command executed a namespace and the output/status must now be -- processed. local results = process.test_results(spec, result, tree) M.workaround_neotest_issue_391(result) return results - elseif spec.context.pos_type == "test" then + elseif pos.type == "test" then -- A test command executed a single test and the output/status must now be -- processed. local results = process.test_results(spec, result, tree) @@ -163,7 +165,7 @@ function M.Adapter.results(spec, result, tree) logger.error( "Cannot process test results due to unknown Neotest position type:" - .. spec.context.pos_type + .. pos.type ) end diff --git a/lua/neotest-golang/process.lua b/lua/neotest-golang/process.lua index 99822209..f81d8954 100644 --- a/lua/neotest-golang/process.lua +++ b/lua/neotest-golang/process.lua @@ -7,12 +7,8 @@ local logger = require("neotest-golang.logging") local options = require("neotest-golang.options") local lib = require("neotest-golang.lib") --- TODO: remove pos_type when properly supporting all position types. --- and instead get this from the pos.type field. - --- @class RunspecContext --- @field pos_id string Neotest tree position id. ---- @field pos_type neotest.PositionType Neotest tree position type. --- @field golist_data table Filepath to 'go list' JSON data (lua table). -- TODO: rename to golist_data --- @field golist_error? string Error message from 'go list' command. --- @field parse_test_results boolean If true, parsing of test output will occur. @@ -78,16 +74,6 @@ function M.test_results(spec, result, tree) --- @type neotest.Position local pos = tree:data() - -- Sanity check - -- TODO: refactor so that we use pos.type and pos.id instead of passing them separately on the context - if options.get().dev_notifications == true then - if pos.id ~= context.pos_id then - logger.error( - "Neotest position id mismatch: " .. pos.id .. " vs " .. context.pos_id - ) - end - end - --- The runner to use for running tests. --- @type string local runner = options.get().runner diff --git a/lua/neotest-golang/runspec/dir.lua b/lua/neotest-golang/runspec/dir.lua index 8a6cc28c..05ceb54b 100644 --- a/lua/neotest-golang/runspec/dir.lua +++ b/lua/neotest-golang/runspec/dir.lua @@ -44,7 +44,6 @@ function M.build(pos) --- @type RunspecContext local context = { pos_id = pos.id, - pos_type = "dir", golist_data = golist_data, golist_error = golist_error, parse_test_results = true, diff --git a/lua/neotest-golang/runspec/file.lua b/lua/neotest-golang/runspec/file.lua index 1ab5cb2b..76a8ad95 100644 --- a/lua/neotest-golang/runspec/file.lua +++ b/lua/neotest-golang/runspec/file.lua @@ -58,7 +58,6 @@ function M.build(pos, tree) --- @type RunspecContext local context = { pos_id = pos.id, - pos_type = "file", golist_data = golist_data, golist_error = golist_error, parse_test_results = true, @@ -80,7 +79,6 @@ function M.return_skipped(pos) --- @type RunspecContext local context = { pos_id = pos.id, - pos_type = "file", golist_data = {}, -- no golist output parse_test_results = false, } diff --git a/lua/neotest-golang/runspec/namespace.lua b/lua/neotest-golang/runspec/namespace.lua index 2ca490b6..a5af79ac 100644 --- a/lua/neotest-golang/runspec/namespace.lua +++ b/lua/neotest-golang/runspec/namespace.lua @@ -26,7 +26,6 @@ function M.build(pos) --- @type RunspecContext local context = { pos_id = pos.id, - pos_type = "namespace", golist_data = golist_data, golist_error = golist_error, parse_test_results = true, diff --git a/lua/neotest-golang/runspec/test.lua b/lua/neotest-golang/runspec/test.lua index c8d1838b..0ce74fcd 100644 --- a/lua/neotest-golang/runspec/test.lua +++ b/lua/neotest-golang/runspec/test.lua @@ -37,7 +37,6 @@ function M.build(pos, strategy) --- @type RunspecContext local context = { pos_id = pos.id, - pos_type = "test", golist_data = golist_data, golist_error = golist_error, parse_test_results = true,