Skip to content

Commit

Permalink
fix(diagnostic): handle buf closing (#279)
Browse files Browse the repository at this point in the history
After closing the buf, the `mark[1]` becomes `nil`, so we can't just `mark[1] + 1`
  • Loading branch information
scottming authored Sep 10, 2023
1 parent ee98945 commit a11ceb2
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions lua/neotest/consumers/diagnostic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,20 @@ local function init(client)
self.tracking_marks[pos_id][error_i],
{}
)
local mark_code = api.nvim_buf_get_lines(bufnr, mark[1], mark[1] + 1, false)[1]

if mark_code == self.error_code_lines[pos_id][error_i] then
diagnostics[#diagnostics + 1] = {
lnum = mark[1],
col = mark_code:find("%S") - 1,
message = error.message,
source = "neotest",
severity = config.diagnostic.severity,
}

-- After closing the buf, the mark[1] becomes nil
if mark and #mark > 0 then
local mark_code = api.nvim_buf_get_lines(bufnr, mark[1], mark[1] + 1, false)[1]

if mark_code == self.error_code_lines[pos_id][error_i] then
diagnostics[#diagnostics + 1] = {
lnum = mark[1],
col = mark_code:find("%S") - 1,
message = error.message,
source = "neotest",
severity = config.diagnostic.severity,
}
end
end
end
end
Expand Down

0 comments on commit a11ceb2

Please sign in to comment.