]> git.rmz.io Git - dotfiles.git/blob - nvim/lua/plugins/lang/go.lua
vim: do not set pastetoggle in nvim
[dotfiles.git] / nvim / lua / plugins / lang / go.lua
1 return {
2 {
3 "nvim-treesitter/nvim-treesitter",
4 opts = { ensure_installed = { "go", "gomod", "gowork", "gosum" } },
5 },
6 {
7 "neovim/nvim-lspconfig",
8 opts = {
9 servers = {
10 gopls = {
11 settings = {
12 gopls = {
13 gofumpt = true,
14 codelenses = {
15 gc_details = false,
16 generate = true,
17 regenerate_cgo = true,
18 run_govulncheck = true,
19 test = true,
20 tidy = true,
21 upgrade_dependency = true,
22 vendor = true,
23 },
24 hints = {
25 assignVariableTypes = true,
26 compositeLiteralFields = true,
27 compositeLiteralTypes = true,
28 constantValues = true,
29 functionTypeParameters = true,
30 parameterNames = true,
31 rangeVariableTypes = true,
32 },
33 analyses = {
34 fieldalignment = true,
35 nilness = true,
36 unusedparams = true,
37 unusedwrite = true,
38 useany = true,
39 },
40 usePlaceholders = true,
41 completeUnimported = true,
42 staticcheck = true,
43 directoryFilters = { "-.git", "-.vscode", "-.idea", "-.vscode-test", "-node_modules" },
44 semanticTokens = true,
45 },
46 },
47 },
48 },
49 setup = {
50 gopls = function(_, opts)
51 -- workaround for gopls not supporting semanticTokensProvider
52 -- https://github.com/golang/go/issues/54531#issuecomment-1464982242
53 rmz.lsp.on_attach(function(client, _)
54 if not client.server_capabilities.semanticTokensProvider then
55 local semantic = client.config.capabilities.textDocument.semanticTokens
56 client.server_capabilities.semanticTokensProvider = {
57 full = true,
58 legend = {
59 tokenTypes = semantic.tokenTypes,
60 tokenModifiers = semantic.tokenModifiers,
61 },
62 range = true,
63 }
64 end
65 end, "gopls")
66 -- end workaround
67 end,
68 },
69 },
70 },
71 -- Ensure Go tools are installed
72 {
73 "williamboman/mason.nvim",
74 opts = { ensure_installed = { "goimports", "gofumpt" } },
75 },
76 {
77 "nvimtools/none-ls.nvim",
78 optional = true,
79 dependencies = {
80 {
81 "williamboman/mason.nvim",
82 opts = { ensure_installed = { "gomodifytags", "impl" } },
83 },
84 },
85 opts = function(_, opts)
86 local nls = require("null-ls")
87 opts.sources = vim.list_extend(opts.sources or {}, {
88 nls.builtins.code_actions.gomodifytags,
89 nls.builtins.code_actions.impl,
90 nls.builtins.formatting.goimports,
91 nls.builtins.formatting.gofumpt,
92 })
93 end,
94 },
95 {
96 "stevearc/conform.nvim",
97 optional = true,
98 opts = {
99 formatters_by_ft = {
100 go = { "goimports", "gofumpt" },
101 },
102 },
103 },
104 {
105 "mfussenegger/nvim-dap",
106 optional = true,
107 dependencies = {
108 {
109 "williamboman/mason.nvim",
110 opts = { ensure_installed = { "delve" } },
111 },
112 {
113 "leoluz/nvim-dap-go",
114 opts = {},
115 },
116 },
117 },
118 {
119 "nvim-neotest/neotest",
120 optional = true,
121 dependencies = {
122 "fredrikaverpil/neotest-golang",
123 },
124 opts = {
125 adapters = {
126 ["neotest-golang"] = {
127 -- Here we can set options for neotest-golang, e.g.
128 -- go_test_args = { "-v", "-race", "-count=1", "-timeout=60s" },
129 dap_go_enabled = true, -- requires leoluz/nvim-dap-go
130 },
131 },
132 },
133 },
134
135 -- Filetype icons
136 {
137 "echasnovski/mini.icons",
138 opts = {
139 file = {
140 [".go-version"] = { glyph = "", hl = "MiniIconsBlue" },
141 },
142 filetype = {
143 gotmpl = { glyph = "󰟓", hl = "MiniIconsGrey" },
144 },
145 },
146 },
147 }