aboutsummaryrefslogtreecommitdiffstats
path: root/lua/lspconfig/configs/golangci_lint_ls.lua
blob: 5e8222066182e979b42a525fb10f8f09e2bc1ef4 (plain) (blame)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-- This config is DEPRECATED.
-- Use the configs in `lsp/` instead (requires Nvim 0.11).
--
-- ALL configs in `lua/lspconfig/configs/` will be DELETED.
-- They exist only to support Nvim 0.10 or older.
-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
local util = require 'lspconfig.util'

return {
  default_config = {
    cmd = { 'golangci-lint-langserver' },
    filetypes = { 'go', 'gomod' },
    init_options = {
      command = { 'golangci-lint', 'run', '--output.json.path=stdout', '--show-stats=false' },
    },
    root_dir = function(fname)
      return util.root_pattern(
        '.golangci.yml',
        '.golangci.yaml',
        '.golangci.toml',
        '.golangci.json',
        'go.work',
        'go.mod',
        '.git'
      )(fname)
    end,
    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,
  },
  docs = {
    description = [[
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
```

]],
  },
}