diff options
| author | anand <anand.panchdhari@gmail.com> | 2025-12-17 15:57:55 +0530 |
|---|---|---|
| committer | anand <anand.panchdhari@gmail.com> | 2025-12-17 15:57:55 +0530 |
| commit | b7ef29a8886a57aadb787807a7c6cf74c1f0ed3a (patch) | |
| tree | 366a68240fbc9da6b1d567bd6c46d1350ad814de /nvim/lsp/golangci_lint_ls.lua | |
Nixos
Diffstat (limited to 'nvim/lsp/golangci_lint_ls.lua')
| -rwxr-xr-x | nvim/lsp/golangci_lint_ls.lua | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/nvim/lsp/golangci_lint_ls.lua b/nvim/lsp/golangci_lint_ls.lua new file mode 100755 index 0000000..9d6cd48 --- /dev/null +++ b/nvim/lsp/golangci_lint_ls.lua @@ -0,0 +1,48 @@ +---@brief +--- +--- Combination of both lint server and client +--- +--- https://github.com/nametake/golangci-lint-langserver +--- https://github.com/golangci/golangci-lint +--- +--- +--- Installation of binaries needed is done via +--- +--- ``` +--- go install github.com/nametake/golangci-lint-langserver@latest +--- go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest +--- ``` +return { + cmd = { 'golangci-lint-langserver' }, + filetypes = { 'go', 'gomod' }, + init_options = { + command = { 'golangci-lint', 'run', '--output.json.path=stdout', '--show-stats=false' }, + }, + root_markers = { + '.golangci.yml', + '.golangci.yaml', + '.golangci.toml', + '.golangci.json', + 'go.work', + 'go.mod', + '.git', + }, + before_init = function(_, config) + -- Add support for golangci-lint V1 (in V2 `--out-format=json` was replaced by + -- `--output.json.path=stdout`). + local v1 + -- PERF: `golangci-lint version` is very slow (about 0.1 sec) so let's find + -- version using `go version -m $(which golangci-lint) | grep '^\smod'`. + if vim.fn.executable 'go' == 1 then + local exe = vim.fn.exepath 'golangci-lint' + local version = vim.system({ 'go', 'version', '-m', exe }):wait() + v1 = string.match(version.stdout, '\tmod\tgithub.com/golangci/golangci%-lint\t') + else + local version = vim.system({ 'golangci-lint', 'version' }):wait() + v1 = string.match(version.stdout, 'version v?1%.') + end + if v1 then + config.init_options.command = { 'golangci-lint', 'run', '--out-format', 'json' } + end + end, +} |
