mirror of
https://github.com/NotAShelf/nvf.git
synced 2026-06-11 23:43:19 +00:00
diagnostics/presets: init
This commit is contained in:
parent
29f7eb8491
commit
0e5f966c38
52 changed files with 958 additions and 634 deletions
|
|
@ -10,9 +10,8 @@
|
|||
inherit (lib.modules) mkIf mkMerge;
|
||||
inherit (lib.meta) getExe;
|
||||
inherit (lib) genAttrs;
|
||||
inherit (lib.generators) mkLuaInline;
|
||||
inherit (lib.types) enum package str listOf;
|
||||
inherit (lib.nvim.types) mkGrammarOption diagnostics deprecatedSingleOrListOf mkPluginSetupOption;
|
||||
inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf mkPluginSetupOption;
|
||||
inherit (lib.nvim.dag) entryAfter;
|
||||
inherit (lib.nvim.attrsets) mapListToAttrs;
|
||||
|
||||
|
|
@ -44,107 +43,7 @@
|
|||
};
|
||||
|
||||
defaultDiagnosticsProvider = ["golangci-lint"];
|
||||
diagnosticsProviders = {
|
||||
golangci-lint = let
|
||||
pkg = pkgs.golangci-lint;
|
||||
in {
|
||||
package = pkg;
|
||||
config = {
|
||||
cmd = getExe pkg;
|
||||
args = [
|
||||
"run"
|
||||
"--output.json.path=stdout"
|
||||
"--issues-exit-code=0"
|
||||
"--show-stats=false"
|
||||
"--fix=false"
|
||||
"--path-mode=abs"
|
||||
# Overwrite values that could be configured and result in unwanted writes
|
||||
"--output.text.path="
|
||||
"--output.tab.path="
|
||||
"--output.html.path="
|
||||
"--output.checkstyle.path="
|
||||
"--output.code-climate.path="
|
||||
"--output.junit-xml.path="
|
||||
"--output.teamcity.path="
|
||||
"--output.sarif.path="
|
||||
(mkLuaInline ''
|
||||
-- Run on current file only if go.mod is missing
|
||||
function()
|
||||
local fnmod = ":p";
|
||||
local cmd = {"${getExe pkgs.go}", "env", "GOMOD"};
|
||||
local ok, gomod = pcall(vim.fn.system, cmd);
|
||||
gomod = gomod:gsub("%s+", "")
|
||||
if ok and gomod ~= "" and gomod ~= "/dev/null" then
|
||||
fnmod = ":h";
|
||||
end
|
||||
return vim.fn.fnamemodify(vim.api.nvim_buf_get_name(0), fnmod)
|
||||
end
|
||||
'')
|
||||
];
|
||||
append_fname = false;
|
||||
parser = mkLuaInline ''
|
||||
function(output, bufnr)
|
||||
local SOURCE = "golangci-lint";
|
||||
|
||||
local function display_tool_error(msg)
|
||||
return{
|
||||
{
|
||||
bufnr = bufnr,
|
||||
lnum = 0,
|
||||
col = 0,
|
||||
message = string.format("[%s] %s", SOURCE, msg),
|
||||
severity = vim.diagnostic.severity.ERROR,
|
||||
source = SOURCE,
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
if output == "" then
|
||||
return display_tool_error("no output provided")
|
||||
end
|
||||
|
||||
local ok, decoded = pcall(vim.json.decode, output)
|
||||
if not ok then
|
||||
return display_tool_error("failed to parse JSON output")
|
||||
end
|
||||
|
||||
if not decoded or not decoded.Issues then
|
||||
return display_tool_error("unexpected output format")
|
||||
end
|
||||
|
||||
local severity_map = {
|
||||
error = vim.diagnostic.severity.ERROR,
|
||||
warning = vim.diagnostic.severity.WARN,
|
||||
info = vim.diagnostic.severity.INFO,
|
||||
hint = vim.diagnostic.severity.HINT,
|
||||
}
|
||||
local diagnostics = {}
|
||||
for _, issue in ipairs(decoded.Issues) do
|
||||
local sev = vim.diagnostic.severity.ERROR
|
||||
if issue.Severity and issue.Severity ~= "" then
|
||||
local normalized = issue.Severity:lower()
|
||||
sev = severity_map[normalized] or vim.diagnostic.severity.ERROR
|
||||
end
|
||||
|
||||
local buffer = vim.fn.fnamemodify(vim.api.nvim_buf_get_name(bufnr), ":p")
|
||||
if vim.fs.normalize(buffer) == vim.fs.normalize(issue.Pos.Filename) then
|
||||
table.insert(diagnostics, {
|
||||
bufnr = bufnr,
|
||||
lnum = issue.Pos.Line - 1,
|
||||
col = issue.Pos.Column - 1,
|
||||
message = issue.Text,
|
||||
code = issue.FromLinter,
|
||||
severity = sev,
|
||||
source = SOURCE,
|
||||
})
|
||||
end
|
||||
end
|
||||
return diagnostics
|
||||
end
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
diagnosticsProviders = ["golangci-lint"];
|
||||
in {
|
||||
options.vim.languages.go = {
|
||||
enable = mkEnableOption "Go language support";
|
||||
|
|
@ -232,10 +131,10 @@ in {
|
|||
defaultText = literalExpression "config.vim.languages.enableExtraDiagnostic";
|
||||
};
|
||||
|
||||
types = diagnostics {
|
||||
langDesc = "Go";
|
||||
inherit diagnosticsProviders;
|
||||
inherit defaultDiagnosticsProvider;
|
||||
types = mkOption {
|
||||
type = listOf (enum diagnosticsProviders);
|
||||
default = defaultDiagnosticsProvider;
|
||||
description = "extra Go diagnostics providers";
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -357,12 +256,12 @@ in {
|
|||
})
|
||||
|
||||
(mkIf cfg.extraDiagnostics.enable {
|
||||
vim.diagnostics.nvim-lint = {
|
||||
enable = true;
|
||||
linters_by_ft.go = cfg.extraDiagnostics.types;
|
||||
linters =
|
||||
mkMerge (map (name: {${name} = diagnosticsProviders.${name}.config;})
|
||||
cfg.extraDiagnostics.types);
|
||||
vim.diagnostics = {
|
||||
presets = genAttrs cfg.extraDiagnostics.types (_: {enable = true;});
|
||||
nvim-lint = {
|
||||
enable = true;
|
||||
linters_by_ft.go = cfg.extraDiagnostics.types;
|
||||
};
|
||||
};
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue