Go
info
You can enable the extra with the :LazyExtras
command.
Plugins marked as optional will only be configured if they are installed.
Alternatively, you can add it to your lazy.nvim
imports
lua/config/lazy.lua
require("lazy").setup({
spec = {
{ "LazyVim/LazyVim", import = "lazyvim.plugins" },
{ import = "lazyvim.plugins.extras.lang.go" },
{ import = "plugins" },
},
})
Below you can find a list of included plugins and their default settings.
caution
You don't need to copy the default settings to your config. They are only shown here for reference.
nvim-treesitter
- Options
- Full Spec
opts = { ensure_installed = { "go", "gomod", "gowork", "gosum" } }
{
"nvim-treesitter/nvim-treesitter",
opts = { ensure_installed = { "go", "gomod", "gowork", "gosum" } },
}
nvim-lspconfig
- Options
- Full Spec
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 = {
fieldalignment = true,
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,
},
}
{
"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 = {
fieldalignment = true,
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,
},
},
}
mason.nvim
Ensure Go tools are installed
- Options
- Full Spec
opts = { ensure_installed = { "goimports", "gofumpt" } }
{
"williamboman/mason.nvim",
opts = { ensure_installed = { "goimports", "gofumpt" } },
}
mason.nvim
- Options
- Full Spec
opts = { ensure_installed = { "gomodifytags", "impl" } }
{
"williamboman/mason.nvim",
opts = { ensure_installed = { "gomodifytags", "impl" } },
}
mason.nvim
- Options
- Full Spec
opts = { ensure_installed = { "delve" } }
{
"williamboman/mason.nvim",
opts = { ensure_installed = { "delve" } },
}
nvim-dap-go
- Options
- Full Spec
opts = {}
{
"leoluz/nvim-dap-go",
opts = {},
}
neotest-golang
- Options
- Full Spec
opts = nil
{
"fredrikaverpil/neotest-golang",
}
mini.icons
Filetype icons
- Options
- Full Spec
opts = {
file = {
[".go-version"] = { glyph = "", hl = "MiniIconsBlue" },
},
filetype = {
gotmpl = { glyph = "", hl = "MiniIconsGrey" },
},
}
{
"echasnovski/mini.icons",
opts = {
file = {
[".go-version"] = { glyph = "", hl = "MiniIconsBlue" },
},
filetype = {
gotmpl = { glyph = "", hl = "MiniIconsGrey" },
},
},
}
none-ls.nvim (optional)
- Options
- Full Spec
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
{
"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,
}
conform.nvim (optional)
- Options
- Full Spec
opts = {
formatters_by_ft = {
go = { "goimports", "gofumpt" },
},
}
{
"stevearc/conform.nvim",
optional = true,
opts = {
formatters_by_ft = {
go = { "goimports", "gofumpt" },
},
},
}
nvim-dap (optional)
- Options
- Full Spec
opts = nil
{
"mfussenegger/nvim-dap",
optional = true,
dependencies = {
{
"williamboman/mason.nvim",
opts = { ensure_installed = { "delve" } },
},
{
"leoluz/nvim-dap-go",
opts = {},
},
},
}
neotest (optional)
- Options
- Full Spec
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
},
},
}
{
"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
},
},
},
}