-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip(diagnostics): csharp diagnostics
- Loading branch information
Showing
3 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
local documentstore = require("rzls.documentstore") | ||
local razor = require("rzls.razor") | ||
local Log = require("rzls.log") | ||
local after_shave_diag_ns = vim.api.nvim_create_namespace("after_shave_diag_ns") | ||
|
||
---@param params lsp.DocumentDiagnosticParams | ||
return function(params) | ||
local razor_bufnr = vim.uri_to_bufnr(params.textDocument.uri) | ||
local razor_docname = vim.api.nvim_buf_get_name(razor_bufnr) | ||
|
||
local vd = documentstore.get_virtual_document(razor_docname, 0, razor.language_kinds.csharp) | ||
if not vd then | ||
Log.rzlsnvim = "aftershave didnt find virtual document when publish diagnostics" | ||
return | ||
end | ||
|
||
local diags = vim.diagnostic.get(vd.buf, { severity = 1 }) | ||
|
||
local csharp_lines = vim.split(vd.content, "\n", { trimempty = false }) | ||
|
||
---@type vim.Diagnostic[] | ||
local mapped_diags = {} | ||
|
||
for _, diag in ipairs(diags) do | ||
local orig_line = diag.lnum | ||
local offset = -1 | ||
-- walk up from the current line looking for the #line marker | ||
-- if we find it, we can map the diagnostic to the razor file | ||
|
||
for i = orig_line, 1, -1 do | ||
local cur_line = csharp_lines[i] | ||
-- #line 58 "/home/tris/code/blazort/BlazorApp/Components/Pages/Movies.razor" | ||
if cur_line:match("#line") then | ||
local _, _, line, file = cur_line:find('#line (%d+) "(.+)"') | ||
if line and file == razor_docname then | ||
---@type vim.Diagnostic | ||
local new_diag = { | ||
bufnr = razor_bufnr, | ||
code = diag.code, | ||
col = diag.col, | ||
end_col = diag.end_col, | ||
lnum = line + offset, | ||
end_lnum = line + offset + (diag.lnum - diag.end_lnum), | ||
message = diag.message, | ||
severity = diag.severity, | ||
namespace = after_shave_diag_ns, | ||
_tags = diag._tags, | ||
} | ||
table.insert(mapped_diags, new_diag) | ||
break | ||
end | ||
end | ||
offset = offset + 1 | ||
end | ||
end | ||
|
||
vim.diagnostic.set(after_shave_diag_ns, razor_bufnr, mapped_diags, {}) | ||
end |