LazyVim.LazyVim/lua/lazyvim/plugins/extras/lang/go.lua
cjon256 5c9732733d
fix(go): update go.lua to eliminate fieldalignment from analyses (#5170)
## Description

Removed a setting from the go lang plugin. The setting now just causes
an error:
LSP[gopls] Invalid settings: setting option "analyses": this setting is
deprecated, use "the 'fieldalignment' analyzer was removed in
gopls/v0.17.0; instead, hover over struct fields to see size/offset
information (https://go.dev/issue/66861)" instead

## Checklist

- [x] I've read the
[CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md)
guidelines.

Note: submitted similar request as f96aac6 but was rejected by CI/CD for
naming reasons. Changing the name did not help. Retrying.
2025-02-08 00:09:03 +01:00

152 lines
4.1 KiB
Lua

return {
recommended = function()
return LazyVim.extras.wants({
ft = { "go", "gomod", "gowork", "gotmpl" },
root = { "go.work", "go.mod" },
})
end,
{
"nvim-treesitter/nvim-treesitter",
opts = { ensure_installed = { "go", "gomod", "gowork", "gosum" } },
},
{
"neovim/nvim-lspconfig",
opts = {
servers = {
gopls = {
settings = {
gopls = {
gofumpt = true,
codelenses = {
gc_details = false,
generate = true,
regenerate_cgo = true,
run_govulncheck = true,
test = true,
tidy = true,
upgrade_dependency = true,
vendor = true,
},
hints = {
assignVariableTypes = true,
compositeLiteralFields = true,
compositeLiteralTypes = true,
constantValues = true,
functionTypeParameters = true,
parameterNames = true,
rangeVariableTypes = true,
},
analyses = {
nilness = true,
unusedparams = true,
unusedwrite = true,
useany = true,
},
usePlaceholders = true,
completeUnimported = true,
staticcheck = true,
directoryFilters = { "-.git", "-.vscode", "-.idea", "-.vscode-test", "-node_modules" },
semanticTokens = true,
},
},
},
},
setup = {
gopls = function(_, opts)
-- workaround for gopls not supporting semanticTokensProvider
-- https://github.com/golang/go/issues/54531#issuecomment-1464982242
LazyVim.lsp.on_attach(function(client, _)
if not client.server_capabilities.semanticTokensProvider then
local semantic = client.config.capabilities.textDocument.semanticTokens
client.server_capabilities.semanticTokensProvider = {
full = true,
legend = {
tokenTypes = semantic.tokenTypes,
tokenModifiers = semantic.tokenModifiers,
},
range = true,
}
end
end, "gopls")
-- end workaround
end,
},
},
},
-- Ensure Go tools are installed
{
"williamboman/mason.nvim",
opts = { ensure_installed = { "goimports", "gofumpt" } },
},
{
"nvimtools/none-ls.nvim",
optional = true,
dependencies = {
{
"williamboman/mason.nvim",
opts = { ensure_installed = { "gomodifytags", "impl" } },
},
},
opts = function(_, opts)
local nls = require("null-ls")
opts.sources = vim.list_extend(opts.sources or {}, {
nls.builtins.code_actions.gomodifytags,
nls.builtins.code_actions.impl,
nls.builtins.formatting.goimports,
nls.builtins.formatting.gofumpt,
})
end,
},
{
"stevearc/conform.nvim",
optional = true,
opts = {
formatters_by_ft = {
go = { "goimports", "gofumpt" },
},
},
},
{
"mfussenegger/nvim-dap",
optional = true,
dependencies = {
{
"williamboman/mason.nvim",
opts = { ensure_installed = { "delve" } },
},
{
"leoluz/nvim-dap-go",
opts = {},
},
},
},
{
"nvim-neotest/neotest",
optional = true,
dependencies = {
"fredrikaverpil/neotest-golang",
},
opts = {
adapters = {
["neotest-golang"] = {
-- Here we can set options for neotest-golang, e.g.
-- go_test_args = { "-v", "-race", "-count=1", "-timeout=60s" },
dap_go_enabled = true, -- requires leoluz/nvim-dap-go
},
},
},
},
-- Filetype icons
{
"echasnovski/mini.icons",
opts = {
file = {
[".go-version"] = { glyph = "", hl = "MiniIconsBlue" },
},
filetype = {
gotmpl = { glyph = "󰟓", hl = "MiniIconsGrey" },
},
},
},
}