@@ -2,6 +2,7 @@ local lib = require("neotest.lib")
22local async = require (" neotest.async" )
33local xml = require (" neotest.lib.xml" )
44local util = require (" neotest-swift-testing.util" )
5+ local parser = require (" neotest-swift-testing.parser" )
56local Path = require (" plenary.path" )
67local logger = require (" neotest-swift-testing.logging" )
78local filetype = require (" plenary.filetype" )
@@ -54,10 +55,6 @@ local treesitter_query = [[
5455
5556]]
5657
57- M .discover_positions = function (file_path )
58- return lib .treesitter .parse_positions (file_path , treesitter_query , { nested_tests = true , require_namespaces = true })
59- end
60-
6158--- @async
6259--- @param cmd string[]
6360--- @return string | nil
@@ -70,6 +67,63 @@ local function shell(cmd)
7067 return result .stdout
7168end
7269
70+ --- @param kind SwiftTesting.TestType
71+ --- @return neotest.PositionType
72+ local function position_type (kind )
73+ if kind == " suite" then
74+ return " namespace"
75+ else
76+ return " test"
77+ end
78+ end
79+
80+ --- @param record SwiftTesting.TestRecord
81+ --- @return neotest.Position | nil
82+ local function position_from_record (record )
83+ if record .kind == " test" and record .payload ~= nil then
84+ --- @type neotest.Position
85+ local pos = {
86+ id = record .payload .id ,
87+ name = record .payload .name ,
88+ path = record .payload .sourceLocation ._filePath ,
89+ type = position_type (record .payload .kind ),
90+ range = {
91+ record .payload .sourceLocation .line ,
92+ record .payload .sourceLocation .column ,
93+ record .payload .sourceLocation .line ,
94+ record .payload .sourceLocation .column ,
95+ },
96+ }
97+ return pos
98+ end
99+ return nil
100+ end
101+
102+ --- @async
103+ --- @param file_path string
104+ --- @return neotest.Tree
105+ M .discover_positions = function (file_path )
106+ -- local output = async.fn.tempname() .. "test-events.jsonl"
107+ -- shell({ "swift", "test", "list", "--enable-swift-testing", "--event-stream-output-path", output })
108+ -- local lines = lib.files.read_lines(output)
109+ --
110+ -- ---@type neotest.Position[]
111+ -- local positions = {}
112+ -- for _, line in ipairs(lines) do
113+ -- local parsed = parser.parse(line)
114+ -- if parsed ~= nil and parsed.kind == "test" then
115+ -- local pos = position_from_record(parsed)
116+ -- if pos ~= nil then
117+ -- table.insert(positions, pos)
118+ -- end
119+ -- end
120+ -- end
121+ -- local Tree = require("neotest.types").Tree
122+ -- logger.debug("Discovered positions: " .. vim.inspect(positions))
123+ -- return Tree.from_list(positions, function(p)
124+ return lib .treesitter .parse_positions (file_path , treesitter_query , { nested_tests = true , require_namespaces = true })
125+ end
126+
73127--- Removes new line characters
74128--- @param str string
75129--- @return string
0 commit comments