mirror of
https://github.com/NotAShelf/nvf.git
synced 2026-02-03 02:15:50 +00:00
language/go: add golangci-lint for extra diagnostics (#1376)
Some checks are pending
Set up binary cache / cachix (default) (push) Waiting to run
Set up binary cache / cachix (maximal) (push) Waiting to run
Set up binary cache / cachix (nix) (push) Waiting to run
Treewide Checks / Validate flake (push) Waiting to run
Treewide Checks / Check formatting (push) Waiting to run
Treewide Checks / Check source tree for typos (push) Waiting to run
Treewide Checks / Validate documentation builds (push) Waiting to run
Treewide Checks / Validate documentation builds-1 (push) Waiting to run
Treewide Checks / Validate documentation builds-2 (push) Waiting to run
Treewide Checks / Validate documentation builds-3 (push) Waiting to run
Treewide Checks / Validate hyperlinks in documentation sources (push) Waiting to run
Treewide Checks / Validate Editorconfig conformance (push) Waiting to run
Build and deploy documentation / Check latest commit (push) Waiting to run
Build and deploy documentation / publish (push) Blocked by required conditions
Some checks are pending
Set up binary cache / cachix (default) (push) Waiting to run
Set up binary cache / cachix (maximal) (push) Waiting to run
Set up binary cache / cachix (nix) (push) Waiting to run
Treewide Checks / Validate flake (push) Waiting to run
Treewide Checks / Check formatting (push) Waiting to run
Treewide Checks / Check source tree for typos (push) Waiting to run
Treewide Checks / Validate documentation builds (push) Waiting to run
Treewide Checks / Validate documentation builds-1 (push) Waiting to run
Treewide Checks / Validate documentation builds-2 (push) Waiting to run
Treewide Checks / Validate documentation builds-3 (push) Waiting to run
Treewide Checks / Validate hyperlinks in documentation sources (push) Waiting to run
Treewide Checks / Validate Editorconfig conformance (push) Waiting to run
Build and deploy documentation / Check latest commit (push) Waiting to run
Build and deploy documentation / publish (push) Blocked by required conditions
This commit is contained in:
parent
fde1338793
commit
8aae70026d
2 changed files with 106 additions and 1 deletions
|
|
@ -164,6 +164,8 @@
|
||||||
- Added [tera](https://keats.github.io/tera/) language support (syntax
|
- Added [tera](https://keats.github.io/tera/) language support (syntax
|
||||||
highlighting only).
|
highlighting only).
|
||||||
|
|
||||||
|
- Added [`golangci-lint`](https://golangci-lint.run/) for more diagnostics.
|
||||||
|
|
||||||
[vagahbond](https://github.com/vagahbond): [codewindow.nvim]:
|
[vagahbond](https://github.com/vagahbond): [codewindow.nvim]:
|
||||||
https://github.com/gorbit99/codewindow.nvim
|
https://github.com/gorbit99/codewindow.nvim
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
inherit (lib.meta) getExe;
|
inherit (lib.meta) getExe;
|
||||||
inherit (lib.generators) mkLuaInline;
|
inherit (lib.generators) mkLuaInline;
|
||||||
inherit (lib.types) bool enum package;
|
inherit (lib.types) bool enum package;
|
||||||
inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf;
|
inherit (lib.nvim.types) mkGrammarOption diagnostics deprecatedSingleOrListOf;
|
||||||
inherit (lib.nvim.dag) entryAfter;
|
inherit (lib.nvim.dag) entryAfter;
|
||||||
inherit (lib.nvim.attrsets) mapListToAttrs;
|
inherit (lib.nvim.attrsets) mapListToAttrs;
|
||||||
|
|
||||||
|
|
@ -78,6 +78,91 @@
|
||||||
package = pkgs.delve;
|
package = pkgs.delve;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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="
|
||||||
|
];
|
||||||
|
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
|
||||||
|
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
|
||||||
|
return diagnostics
|
||||||
|
end
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
in {
|
in {
|
||||||
options.vim.languages.go = {
|
options.vim.languages.go = {
|
||||||
enable = mkEnableOption "Go language support";
|
enable = mkEnableOption "Go language support";
|
||||||
|
|
@ -134,6 +219,14 @@ in {
|
||||||
default = debuggers.${cfg.dap.debugger}.package;
|
default = debuggers.${cfg.dap.debugger}.package;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
extraDiagnostics = {
|
||||||
|
enable = mkEnableOption "extra Go diagnostics" // {default = config.vim.languages.enableExtraDiagnostics;};
|
||||||
|
types = diagnostics {
|
||||||
|
langDesc = "Go";
|
||||||
|
inherit diagnosticsProviders;
|
||||||
|
inherit defaultDiagnosticsProvider;
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable (mkMerge [
|
config = mkIf cfg.enable (mkMerge [
|
||||||
|
|
@ -179,5 +272,15 @@ in {
|
||||||
debugger.nvim-dap.enable = true;
|
debugger.nvim-dap.enable = true;
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
|
(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);
|
||||||
|
};
|
||||||
|
})
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue