update
This commit is contained in:
parent
f4119e7818
commit
e2eb892edb
8 changed files with 137 additions and 43 deletions
|
|
@ -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")
|
||||
|
|
|
|||
68
lua/user/lsp_servers/golang.lua
Normal file
68
lua/user/lsp_servers/golang.lua
Normal file
|
|
@ -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", "<leader>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", "<leader>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", "<leader>gr", function()
|
||||
vim.cmd("!go test ./...")
|
||||
end, { buffer = bufnr, desc = "Go: Run tests" })
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
vim.lsp.enable("gopls")
|
||||
|
|
@ -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')
|
||||
43
lua/user/lsp_servers/svelte.lua
Normal file
43
lua/user/lsp_servers/svelte.lua
Normal file
|
|
@ -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", "<leader>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")
|
||||
|
|
@ -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', '<leader>rn', vim.lsp.buf.rename, opts)
|
||||
end,
|
||||
})
|
||||
|
||||
-- 3. Enable the server
|
||||
vim.lsp.enable('ts_ls')
|
||||
vim.lsp.enable("ts_ls")
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,5 +11,7 @@ require("nvim-treesitter").setup({
|
|||
"kotlin",
|
||||
"go",
|
||||
"dart",
|
||||
"typescript",
|
||||
"svelte",
|
||||
},
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
local status_ok, trouble = pcall(require, "trouble")
|
||||
if not status_ok then
|
||||
vim.notify("trouble.nvim not found!")
|
||||
return
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue