diff --git a/lua/user/lsp.lua b/lua/user/lsp.lua index 829cb06..a68b7fe 100644 --- a/lua/user/lsp.lua +++ b/lua/user/lsp.lua @@ -1,5 +1,18 @@ --- 1. Setup Mason first -require("mason").setup() +-- 1. Setup Mason first (LSPs + tools) +require("mason").setup({ + ensure_installed = { + -- Go toolchain + "gofumpt", + "goimports", + "delve", + -- Lua + "stylua", + -- Python + "black", + -- YAML + "yamlfmt", + }, +}) require("mason-lspconfig").setup({ -- Remove "jdtls" from here to prevent the 'enable' (nil value) crash ensure_installed = { diff --git a/lua/user/lsp_servers/golang.lua b/lua/user/lsp_servers/golang.lua index fbdbe73..6fc8d00 100644 --- a/lua/user/lsp_servers/golang.lua +++ b/lua/user/lsp_servers/golang.lua @@ -1,3 +1,13 @@ +-- 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 @@ -35,37 +45,4 @@ vim.lsp.config("gopls", { }, }) --- Go-specific LSP attach handlers -vim.api.nvim_create_autocmd("LspAttach", { - callback = function(args) - local client = vim.lsp.get_client_by_id(args.data.client_id) - if client and client.name == "gopls" then - local bufnr = args.buf - - -- Go: organize imports on demand - vim.keymap.set("n", "gi", function() - vim.lsp.buf.code_action({ - context = { only = { "source.organizeImports" } }, - apply = true, - }) - end, { buffer = bufnr, desc = "Go: Organize imports" }) - - -- Go: toggle test file - vim.keymap.set("n", "gt", function() - local fname = vim.fn.expand("%") - if fname:match("_test%.go$") then - vim.cmd("edit " .. fname:gsub("_test%.go$", ".go")) - else - vim.cmd("edit " .. fname:gsub("%.go$", "_test.go")) - end - end, { buffer = bufnr, desc = "Go: Toggle test file" }) - - -- Go: run current file's tests - vim.keymap.set("n", "gr", function() - vim.cmd("!go test ./...") - end, { buffer = bufnr, desc = "Go: Run tests" }) - end - end, -}) - vim.lsp.enable("gopls") diff --git a/lua/user/options.lua b/lua/user/options.lua index 9730a90..90cd435 100644 --- a/lua/user/options.lua +++ b/lua/user/options.lua @@ -70,3 +70,6 @@ opt.scrolloff = 8 -- minimal number of screen columns either side of cursor if wrap is `false` opt.sidescrolloff = 8 +-- Add Mason's bin directory to PATH (LSPs, formatters, linters, debuggers) +vim.env.PATH = vim.fn.expand("~/.local/share/nvim/mason/bin") .. ":" .. (vim.env.PATH or "") +