nvim/lua/user/lsp_servers/golang.lua
Prabhat Maurya 8b868ed944 feat: proper Go setup with gopls, formatters, and debugger
- Add Mason bin to Neovim PATH so formatters/linters are discoverable
- Add Mason ensure_installed for gofumpt, goimports, delve + stylua, black, yamlfmt
- Add Go filetype settings (tabs, tabwidth=4) in golang.lua
- Remove redundant Go keymaps — existing LSP and vim-test keymaps already cover everything

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-26 00:06:12 +05:30

48 lines
1.5 KiB
Lua

-- Go filetype settings (Go uses tabs, not spaces)
vim.api.nvim_create_autocmd("FileType", {
pattern = { "go", "gomod", "gowork", "gotmpl" },
callback = function()
vim.opt_local.expandtab = false
vim.opt_local.tabstop = 4
vim.opt_local.shiftwidth = 4
end,
})
-- Go LSP configuration
-- Uses gopls installed via Mason
local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
local capabilities = status_ok
and cmp_nvim_lsp.default_capabilities(vim.lsp.protocol.make_client_capabilities())
or vim.lsp.protocol.make_client_capabilities()
vim.lsp.config("gopls", {
cmd = { "gopls" },
filetypes = { "go", "gomod", "gowork", "gotmpl" },
capabilities = capabilities,
root_markers = { "go.mod", ".git" },
settings = {
gopls = {
hints = {
assignVariableTypes = true,
compositeLiteralFields = true,
compositeLiteralTypes = true,
constantValues = true,
functionTypeParameters = true,
parameterNames = true,
rangeVariableTypes = true,
},
analyses = {
unusedparams = true,
shadow = true,
nilness = true,
},
staticcheck = true,
gofumpt = true, -- prefer gofumpt formatting
usePlaceholders = true,
completeUnimported = true,
},
},
})
vim.lsp.enable("gopls")