Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show correct number of errors in diagnostics #20

Merged
merged 2 commits into from
May 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 1 addition & 24 deletions lua/neotest-golang/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -250,18 +250,10 @@ function M.Adapter.results(spec, result, tree)
---@type List<table>
local jsonlines = M.process_json(raw_output)

local panic_detected = false

for _, line in ipairs(jsonlines) do
if line.Action == "output" and line.Output ~= nil then
-- record output, prints to output panel
table.insert(test_result, line.Output)

-- register panic found
local panic_match = string.match(line.Output, "panic:")
if panic_match ~= nil then
panic_detected = true
end
end

if result.code ~= 0 and line.Output ~= nil then
Expand All @@ -270,12 +262,7 @@ function M.Adapter.results(spec, result, tree)
local matched_line_number =
string.match(line.Output, test_filename .. ":(%d+)")

if matched_line_number == nil or panic_detected then
-- log the error without a line number
---@type neotest.Error
local error = { message = line.Output }
table.insert(errors, error)
else
if matched_line_number ~= nil then
-- attempt to parse the line number...
---@type number | nil
local line_number = tonumber(matched_line_number)
Expand All @@ -293,16 +280,6 @@ function M.Adapter.results(spec, result, tree)
end
end

if panic_detected then
-- remove all line numbers, as neotest diagnostics will crash if they are present
local new_errors = {}
for _, error in ipairs(errors) do
local new_error = { message = error.message }
table.insert(new_errors, new_error)
end
errors = new_errors
end

-- write json_decoded to file
local parsed_output_path = vim.fs.normalize(async.fn.tempname())
async.fn.writefile(test_result, parsed_output_path)
Expand Down
Loading