all repos

dotfiles @ afb46d4

i use rach linux btw

dotfiles/config/nvim/after/lsp/gopls.lua (view raw)

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
move nvim config in here, 1 month ago
1
---@return vim.lsp.Config
2
return {
3
  cmd = { "gopls" },
4
  filetypes = { "go", "gomod", "gosum", "gowork", "gotmpl" },
5
  root_markers = { "go.mod", "go.work" },
6
  on_attach = function(_, buf)
7
    Config.map("n", "<leader>lf", function()
8
      vim.lsp.buf.format()
9
10
      local params = vim.lsp.util.make_range_params(0, "utf-8")
11
      params.context = { only = { "source.organizeImports" } } ---@diagnostic disable-line: inject-field
12
      local result = vim.lsp.buf_request_sync(buf, "textDocument/codeAction", params)
13
      for cid, res in pairs(result or {}) do
14
        for _, r in pairs(res.result or {}) do
15
          if r.edit then
16
            vim.lsp.util.apply_workspace_edit(r.edit, (vim.lsp.get_client_by_id(cid) or {}).offset_encoding or "utf-8")
17
          end
18
        end
19
      end
20
    end, buf)
21
  end,
22
  settings = {
23
    gopls = {
24
      staticcheck = true,
25
      gofumpt = true,
26
      renameMovesSubpackages = true,
27
      directoryFilters = { "-.git", "-.jj", "-node_modules" },
28
      analyses = {
29
        unusedparams = true,
30
        unreachable = true,
31
        unusedwrite = true,
32
        nilness = true,
33
        shadow = true,
34
        S1008 = true, -- simplify returning boolean expression
35
        SA5000 = true, -- assignment to nil map
36
        SA5007 = true, -- infinite recursion call
37
        ST1019 = true, -- importing the same package multiple times
38
        SA1000 = true, -- invalid regular expression
39
        SA1020 = true, -- using an invalid host:port pair with a net.Listen-related function
40
        SA1023 = true, -- modifying the buffer in an io.Writer implementation
41
        SA9001 = true, -- defers in range loops may not run when you expect them to
42
        ST1013 = true, -- should use constants for HTTP error codes, not magic numbers
43
        ST1000 = false, -- Incorrect or missing package comment
44
      },
45
      hints = {
46
        assignVariableTypes = true,
47
        compositeLiteralFields = true,
48
        compositeLiteralTypes = false,
49
        constantValues = true,
50
        ignoredError = true,
51
        functionTypeParameters = false,
52
        parameterNames = true,
53
        rangeVariableTypes = true,
54
      },
55
      codelenses = {
56
        generate = true,
57
        regenerate_cgo = true,
58
        gc_details = true,
59
        test = false,
60
        tidy = true,
61
        upgrade_dependency = true,
62
        vendor = true,
63
      },
64
    },
65
  },
66
}