1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
---@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
--- ```
---@type vim.lsp.Config
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, v2 = false, false
-- 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')
v2 = string.match(version.stdout, '\tmod\tgithub.com/golangci/golangci%-lint/v2\t')
end
if not v1 and not v2 then
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,
}
|