LazyVim.LazyVim/lua/lazyvim/plugins/extras/lang/go.lua

153 lines
4.1 KiB
Lua
Raw Permalink Normal View History

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, _)
2024-06-08 08:11:28 +02:00
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
2024-06-08 08:11:28 +02:00
end, "gopls")
-- end workaround
end,
},
},
},
-- Ensure Go tools are installed
{
2025-05-12 10:39:04 +02:00
"mason-org/mason.nvim",
opts = { ensure_installed = { "goimports", "gofumpt" } },
},
{
"nvimtools/none-ls.nvim",
optional = true,
dependencies = {
{
2025-05-12 10:39:04 +02:00
"mason-org/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,
},
2023-10-01 16:01:43 -05:00
{
"stevearc/conform.nvim",
optional = true,
opts = {
formatters_by_ft = {
go = { "goimports", "gofumpt" },
2023-10-01 16:01:43 -05:00
},
},
},
{
"mfussenegger/nvim-dap",
optional = true,
dependencies = {
{
2025-05-12 10:39:04 +02:00
"mason-org/mason.nvim",
opts = { ensure_installed = { "delve" } },
},
{
"leoluz/nvim-dap-go",
2024-06-11 00:06:56 +02:00
opts = {},
},
},
},
{
"nvim-neotest/neotest",
optional = true,
dependencies = {
feat(go): switch to neotest-golang (#3749) ## What is this PR for? This PR switches [nvim-neotest/neotest-go](https://github.com/nvim-neotest/neotest-go) for [fredrikaverpil/neotest-golang](https://github.com/fredrikaverpil/neotest-golang). ## Does this PR fix an existing issue? Neotest-go comes with some problems which are mitigated in neotest-golang. A full description/background is available in the project README, but here are some highlights: ### Neotest-go issues mitigated in neotest-golang - Test Output in JSON, making it difficult to read: [neotest-go#52](https://github.com/nvim-neotest/neotest-go/issues/52) - "Run nearest" runs all tests: [neotest-go#83](https://github.com/nvim-neotest/neotest-go/issues/83) - Running test suite doesn't work: [neotest-go#89](https://github.com/nvim-neotest/neotest-go/issues/89) - Diagnostics for table tests on the line of failure: [neotest-go#75](https://github.com/nvim-neotest/neotest-go/issues/75) - Support for Nested Subtests: [neotest-go#74](https://github.com/nvim-neotest/neotest-go/issues/74) - DAP support: [neotest-go#12](https://github.com/nvim-neotest/neotest-go/issues/12) ### Features - Supports all [Neotest usage](https://github.com/nvim-neotest/neotest#usage). - Integrates with [nvim-dap-go](https://github.com/leoluz/nvim-dap-go) for debugging of tests using delve. - Inline diagnostics. - Works great with [andythigpen/nvim-coverage](https://github.com/andythigpen/nvim-coverage) for displaying coverage in the sign column (per-Go package, or per-test basis). - Monorepo support (detect, run and debug tests in sub-projects). - Supports table tests (relies on treesitter AST detection). - Supports nested test functions. ## Notes - I'm the author of [fredrikaverpil/neotest-golang](https://github.com/fredrikaverpil/neotest-golang). ## Checklist - [x] I've read the [CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md) guidelines.
2024-06-23 07:01:22 +02:00
"fredrikaverpil/neotest-golang",
},
opts = {
adapters = {
feat(go): switch to neotest-golang (#3749) ## What is this PR for? This PR switches [nvim-neotest/neotest-go](https://github.com/nvim-neotest/neotest-go) for [fredrikaverpil/neotest-golang](https://github.com/fredrikaverpil/neotest-golang). ## Does this PR fix an existing issue? Neotest-go comes with some problems which are mitigated in neotest-golang. A full description/background is available in the project README, but here are some highlights: ### Neotest-go issues mitigated in neotest-golang - Test Output in JSON, making it difficult to read: [neotest-go#52](https://github.com/nvim-neotest/neotest-go/issues/52) - "Run nearest" runs all tests: [neotest-go#83](https://github.com/nvim-neotest/neotest-go/issues/83) - Running test suite doesn't work: [neotest-go#89](https://github.com/nvim-neotest/neotest-go/issues/89) - Diagnostics for table tests on the line of failure: [neotest-go#75](https://github.com/nvim-neotest/neotest-go/issues/75) - Support for Nested Subtests: [neotest-go#74](https://github.com/nvim-neotest/neotest-go/issues/74) - DAP support: [neotest-go#12](https://github.com/nvim-neotest/neotest-go/issues/12) ### Features - Supports all [Neotest usage](https://github.com/nvim-neotest/neotest#usage). - Integrates with [nvim-dap-go](https://github.com/leoluz/nvim-dap-go) for debugging of tests using delve. - Inline diagnostics. - Works great with [andythigpen/nvim-coverage](https://github.com/andythigpen/nvim-coverage) for displaying coverage in the sign column (per-Go package, or per-test basis). - Monorepo support (detect, run and debug tests in sub-projects). - Supports table tests (relies on treesitter AST detection). - Supports nested test functions. ## Notes - I'm the author of [fredrikaverpil/neotest-golang](https://github.com/fredrikaverpil/neotest-golang). ## Checklist - [x] I've read the [CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md) guidelines.
2024-06-23 07:01:22 +02:00
["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" },
},
},
},
}