nixos: gen 108 @ lilac — 2026-10-27 13:48 26.05.20260918.cf9d2fb (Yarara) ----- adding golang support to neovim

This commit is contained in:
2026-10-27 13:48:12 -06:00
parent 9510cb10c8
commit e6dd280c9b
2 changed files with 102 additions and 3 deletions
+101 -2
View File
@@ -151,7 +151,7 @@ in
-- started per buffer. Indent is deliberately left alone so treesitter -- started per buffer. Indent is deliberately left alone so treesitter
-- doesn't fight the Eclipse-matching tab settings below. -- doesn't fight the Eclipse-matching tab settings below.
vim.api.nvim_create_autocmd("FileType", { vim.api.nvim_create_autocmd("FileType", {
pattern = { "java", "xml", "nix", "lua", "rs" }, pattern = { "java", "xml", "nix", "lua", "rs", "go", "gomod" },
callback = function(args) callback = function(args)
pcall(vim.treesitter.start, args.buf) pcall(vim.treesitter.start, args.buf)
end, end,
@@ -168,6 +168,17 @@ in
end, end,
}) })
-- Go indentation must match gofmt: real tabs, displayed 4 wide.
vim.api.nvim_create_autocmd("FileType", {
pattern = { "go", "gomod" },
callback = function()
vim.bo.expandtab = false
vim.bo.tabstop = 4
vim.bo.shiftwidth = 4
vim.bo.softtabstop = 4
end,
})
local cmp = require("cmp") local cmp = require("cmp")
local luasnip = require("luasnip") local luasnip = require("luasnip")
cmp.setup({ cmp.setup({
@@ -206,6 +217,94 @@ in
}, },
} }
-- Go: gopls (LSP) + golangci-lint-langserver (lint diagnostics) via
-- Neovim's native LSP config, so no nvim-lspconfig plugin is needed.
-- Like rust-analyzer above, both binaries are resolved from PATH, so a
-- project's flake devShell/direnv pins are used automatically.
vim.lsp.config("gopls", {
cmd = { "gopls" },
filetypes = { "go", "gomod", "gowork", "gotmpl" },
root_markers = { "go.work", "go.mod", ".git" },
capabilities = capabilities,
settings = {
gopls = {
gofumpt = true,
usePlaceholders = true,
completeUnimported = true,
staticcheck = false, -- golangci-lint already covers this
analyses = {
unusedparams = true,
unusedwrite = true,
useany = true,
},
hints = {
assignVariableTypes = true,
compositeLiteralFields = true,
constantValues = true,
parameterNames = true,
rangeVariableTypes = true,
},
},
},
on_attach = function(_, bufnr)
local map = function(k, f) vim.keymap.set("n", k, f, { buffer = bufnr, silent = true }) end
map("gd", vim.lsp.buf.definition)
map("gr", vim.lsp.buf.references)
map("K", vim.lsp.buf.hover)
map("<leader>rn", vim.lsp.buf.rename)
map("<leader>ca", vim.lsp.buf.code_action)
map("<leader>f", function() vim.lsp.buf.format({ async = true }) end)
map("<leader>ci", function()
vim.lsp.buf.code_action({
context = { only = { "source.organizeImports" }, diagnostics = {} },
apply = true,
})
end)
end,
})
-- golangci-lint v2 syntax (current in nixpkgs). Needs golangci-lint on
-- PATH; a project .golangci.yml (with `version: "2"`) controls the rules.
vim.lsp.config("golangci_lint_ls", {
cmd = { "golangci-lint-langserver" },
filetypes = { "go", "gomod" },
root_markers = { ".golangci.yml", ".golangci.yaml", ".golangci.toml", ".golangci.json", "go.work", "go.mod", ".git" },
capabilities = capabilities,
init_options = {
command = {
"golangci-lint", "run",
"--output.json.path", "stdout",
"--show-stats=false",
"--issues-exit-code=1",
},
},
})
vim.lsp.enable({ "gopls", "golangci_lint_ls" })
-- On save: organize imports via gopls, then format (gofumpt via gopls).
vim.api.nvim_create_autocmd("BufWritePre", {
pattern = "*.go",
callback = function(args)
local clients = vim.lsp.get_clients({ bufnr = args.buf, name = "gopls" })
local client = clients[1]
if not client then
return
end
local params = vim.lsp.util.make_range_params(0, client.offset_encoding)
params.context = { only = { "source.organizeImports" } }
local result = vim.lsp.buf_request_sync(args.buf, "textDocument/codeAction", params, 1000)
for _, res in pairs(result or {}) do
for _, action in pairs(res.result or {}) do
if action.edit then
vim.lsp.util.apply_workspace_edit(action.edit, client.offset_encoding)
end
end
end
vim.lsp.buf.format({ bufnr = args.buf, async = false })
end,
})
local bundles = vim.fn.glob( local bundles = vim.fn.glob(
"${javaDebug}/share/vscode/extensions/vscjava.vscode-java-debug/server/com.microsoft.java.debug.plugin-*.jar", "${javaDebug}/share/vscode/extensions/vscjava.vscode-java-debug/server/com.microsoft.java.debug.plugin-*.jar",
true, true) true, true)
@@ -360,7 +459,7 @@ in
{ plugin = luasnip; } { plugin = luasnip; }
{ plugin = cmp_luasnip; } { plugin = cmp_luasnip; }
{ plugin = rustaceanvim; } { plugin = rustaceanvim; }
{ plugin = (nvim-treesitter.withPlugins (p: [ p.java p.xml p.nix p.lua p.rust ])); } { plugin = (nvim-treesitter.withPlugins (p: [ p.java p.xml p.nix p.lua p.rust p.go p.gomod ])); }
{ plugin = vim-obsession; } { plugin = vim-obsession; }
]; ];
+1 -1
View File
@@ -46,7 +46,7 @@
bind -n M-K resize-pane -U 2 bind -n M-K resize-pane -U 2
bind -n M-L resize-pane -R 2 bind -n M-L resize-pane -R 2
bind -n M-z resize-pane -Z bind -n M-f resize-pane -Z
bind -n M-c new-window bind -n M-c new-window