From e2eb892edbdeff0cddd1427aec46bdfeed21167c Mon Sep 17 00:00:00 2001 From: Prabhat Maurya Date: Tue, 7 Jul 2026 22:21:01 +0530 Subject: [PATCH] update --- lua/user/lsp.lua | 6 ++- lua/user/lsp_servers/golang.lua | 68 ++++++++++++++++++++++++++++++++ lua/user/lsp_servers/graphql.lua | 21 ---------- lua/user/lsp_servers/svelte.lua | 43 ++++++++++++++++++++ lua/user/lsp_servers/ts_ls.lua | 33 +++++++--------- lua/user/null-ls.lua | 6 +++ lua/user/treesitter.lua | 2 + lua/user/trouble.lua | 1 - 8 files changed, 137 insertions(+), 43 deletions(-) create mode 100644 lua/user/lsp_servers/golang.lua delete mode 100644 lua/user/lsp_servers/graphql.lua create mode 100644 lua/user/lsp_servers/svelte.lua diff --git a/lua/user/lsp.lua b/lua/user/lsp.lua index a606e89..d8cd0fa 100644 --- a/lua/user/lsp.lua +++ b/lua/user/lsp.lua @@ -7,7 +7,8 @@ require("mason-lspconfig").setup({ "ts_ls", "marksman", "kotlin_language_server", - "graphql" + "svelte", + "gopls", }, }) @@ -30,5 +31,6 @@ require("user.lsp_servers.ts_ls") -- require("user.lsp_servers.jdtls") require("user.lsp_servers.marksman") require("user.lsp_servers.kotlin_ls") -require("user.lsp_servers.graphql") require("user.lsp_servers.dartls") +require("user.lsp_servers.svelte") +require("user.lsp_servers.golang") diff --git a/lua/user/lsp_servers/golang.lua b/lua/user/lsp_servers/golang.lua new file mode 100644 index 0000000..bbf9324 --- /dev/null +++ b/lua/user/lsp_servers/golang.lua @@ -0,0 +1,68 @@ +-- Go LSP configuration +-- Uses gopls installed via Mason + +local capabilities = require("cmp_nvim_lsp").default_capabilities(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, + }, + }, +}) + +-- 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/lsp_servers/graphql.lua b/lua/user/lsp_servers/graphql.lua deleted file mode 100644 index d82e301..0000000 --- a/lua/user/lsp_servers/graphql.lua +++ /dev/null @@ -1,21 +0,0 @@ --- 1. Configuration -vim.lsp.config('graphql', { - cmd = { "graphql-lsp", "server", "-m", "stream" }, - filetypes = { "graphql", "gql", "javascript", "typescript", "typescriptreact", "javascriptreact" }, - - -- This ensures GraphQL only starts if it finds a config file - root_markers = { - ".graphqlrc", - ".graphqlrc.json", - ".graphqlrc.yaml", - ".graphqlrc.yml", - "graphql.config.json", - "graphql.config.yaml", - "graphql.config.yml" - }, - - capabilities = require("cmp_nvim_lsp").default_capabilities(), -}) - --- 2. Enable the server -vim.lsp.enable('graphql') diff --git a/lua/user/lsp_servers/svelte.lua b/lua/user/lsp_servers/svelte.lua new file mode 100644 index 0000000..c283bbb --- /dev/null +++ b/lua/user/lsp_servers/svelte.lua @@ -0,0 +1,43 @@ +-- Svelte LSP configuration +-- Uses svelte-language-server installed via Mason + +local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()) + +vim.lsp.config("svelte", { + cmd = { "svelteserver", "--stdio" }, + filetypes = { "svelte" }, + capabilities = capabilities, + root_markers = { "package.json", "svelte.config.js", ".git" }, + settings = { + svelte = { + enableTsPlugin = true, + plugin = { + svelte = { + enable = true, + }, + }, + }, + }, +}) + +-- Svelte-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 == "svelte" then + local bufnr = args.buf + + -- Restart Svelte language server + vim.keymap.set("n", "sr", function() + vim.cmd("LspRestart svelte") + end, { buffer = bufnr, desc = "Svelte: Restart LSP" }) + + -- Go to component definition (jumps to imported .svelte files) + vim.keymap.set("n", "gD", function() + vim.lsp.buf.declaration() + end, { buffer = bufnr, desc = "Svelte: Go to declaration" }) + end + end, +}) + +vim.lsp.enable("svelte") diff --git a/lua/user/lsp_servers/ts_ls.lua b/lua/user/lsp_servers/ts_ls.lua index c08c797..1a00812 100644 --- a/lua/user/lsp_servers/ts_ls.lua +++ b/lua/user/lsp_servers/ts_ls.lua @@ -1,5 +1,9 @@ --- 1. Configuration -vim.lsp.config('ts_ls', { +-- TypeScript/JavaScript LSP configuration +-- Uses typescript-language-server installed via Mason + +local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()) + +vim.lsp.config("ts_ls", { cmd = { "typescript-language-server", "--stdio" }, filetypes = { "typescript", @@ -9,7 +13,7 @@ vim.lsp.config('ts_ls', { "javascriptreact", "javascript.jsx", }, - -- In 0.11, root_markers replaces root_dir logic + capabilities = capabilities, root_markers = { "package.json", "tsconfig.json", "jsconfig.json", ".git" }, settings = { javascript = { @@ -21,6 +25,9 @@ vim.lsp.config('ts_ls', { indentStyle = "smart", indentSize = 2, }, + suggest = { + completeFunctionCalls = true, + }, }, typescript = { format = { @@ -31,23 +38,11 @@ vim.lsp.config('ts_ls', { indentStyle = "smart", indentSize = 2, }, + suggest = { + completeFunctionCalls = true, + }, }, }, }) --- 2. Global LspAttach for Keymaps --- This works for all servers, so you only need to define it once (e.g., in user/lsp.lua) -vim.api.nvim_create_autocmd('LspAttach', { - group = vim.api.nvim_create_augroup('UserLspConfig', {}), - callback = function(ev) - local opts = { buffer = ev.buf, noremap = true, silent = true } - - -- Modern way to set keymaps using the lua function directly - vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) - vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) - vim.keymap.set('n', 'rn', vim.lsp.buf.rename, opts) - end, -}) - --- 3. Enable the server -vim.lsp.enable('ts_ls') +vim.lsp.enable("ts_ls") diff --git a/lua/user/null-ls.lua b/lua/user/null-ls.lua index eae4ce1..ff343ae 100644 --- a/lua/user/null-ls.lua +++ b/lua/user/null-ls.lua @@ -8,6 +8,8 @@ local formatting = null_ls.builtins.formatting -- Configure null-ls local sources = { formatting.prettier, -- Use prettier for formatting (JavaScript, TypeScript, etc.) + formatting.gofumpt, -- Go: stricter gofmt + formatting.goimports, -- Go: organize imports + format formatting.black, -- Use black for Python formatting formatting.stylua, -- Use stylua for Lua formatting formatting.google_java_format.with({ @@ -28,6 +30,10 @@ local sources = { to_stdin = true, }), }, + -- YAML formatting via yamlfmt (Mason: yamlfmt) + formatting.yamlfmt, + -- XML formatting via xmllint (system package: libxml2-utils) + formatting.xmllint, -- Add other formatters based on your needs } diff --git a/lua/user/treesitter.lua b/lua/user/treesitter.lua index 25a7f57..1c9deb1 100644 --- a/lua/user/treesitter.lua +++ b/lua/user/treesitter.lua @@ -11,5 +11,7 @@ require("nvim-treesitter").setup({ "kotlin", "go", "dart", + "typescript", + "svelte", }, }) diff --git a/lua/user/trouble.lua b/lua/user/trouble.lua index 215e9d2..d901119 100644 --- a/lua/user/trouble.lua +++ b/lua/user/trouble.lua @@ -1,6 +1,5 @@ local status_ok, trouble = pcall(require, "trouble") if not status_ok then - vim.notify("trouble.nvim not found!") return end