Problem: all three built-in error parsers were broken against real compiler output. Typst set source to the relative file path, overriding the provider name. LaTeX errors go to stdout but the parser only received stderr. Pandoc's pattern matched "Error at" but not the real "Error parsing YAML metadata at" format, and single-line parsing missed multiline messages. Solution: pass combined stdout+stderr to error_parser so LaTeX stdout errors are visible. Remove source = file from the Typst parser so diagnostic.lua defaults it to the provider name. Rewrite the Pandoc parser with line-based lookahead: match (line N, column N) regardless of prefix text, skip YAML parse exception lines when looking ahead for the human-readable message. Rename stderr param to output throughout diagnostic.lua, presets.lua, and init.lua annotations.
40 lines
1 KiB
Lua
40 lines
1 KiB
Lua
local M = {}
|
|
|
|
local log = require('preview.log')
|
|
|
|
local ns = vim.api.nvim_create_namespace('preview')
|
|
|
|
---@param bufnr integer
|
|
function M.clear(bufnr)
|
|
vim.diagnostic.set(ns, bufnr, {})
|
|
log.dbg('cleared diagnostics for buffer %d', bufnr)
|
|
end
|
|
|
|
---@param bufnr integer
|
|
---@param name string
|
|
---@param error_parser fun(output: string, ctx: preview.Context): preview.Diagnostic[]
|
|
---@param output string
|
|
---@param ctx preview.Context
|
|
function M.set(bufnr, name, error_parser, output, ctx)
|
|
local ok, diagnostics = pcall(error_parser, output, ctx)
|
|
if not ok then
|
|
log.dbg('error_parser for "%s" failed: %s', name, diagnostics)
|
|
return
|
|
end
|
|
if not diagnostics or #diagnostics == 0 then
|
|
log.dbg('error_parser for "%s" returned no diagnostics', name)
|
|
return
|
|
end
|
|
for _, d in ipairs(diagnostics) do
|
|
d.source = d.source or name
|
|
end
|
|
vim.diagnostic.set(ns, bufnr, diagnostics)
|
|
log.dbg('set %d diagnostics for buffer %d from provider "%s"', #diagnostics, bufnr, name)
|
|
end
|
|
|
|
---@return integer
|
|
function M.get_namespace()
|
|
return ns
|
|
end
|
|
|
|
return M
|