Files
dotfiles/nvim/.config/nvim/lua/configs/lspconfig.lua

108 lines
3.2 KiB
Lua

-- LSP capabilities (blink.cmp augments these automatically)
local capabilities = vim.lsp.protocol.make_client_capabilities()
-- on_attach function with LSP keybindings (shared with the gdscript
-- LspAttach handler in autocmds.lua -- see lua/configs/lsp_keymaps.lua)
local on_attach = function(client, bufnr)
require("configs.lsp_keymaps").attach(client, bufnr)
end
local servers = {
rust_analyzer = {
filetypes = { "rust" },
on_attach = on_attach,
capabilities = capabilities,
settings = {
["rust-analyzer"] = {
completion = {
addCallParenthesis = true,
addCallArgumentSnippets = false,
postfix = {
enabled = false,
},
},
callInfo = {
full = false,
},
}
}
},
csharp_ls = {
filetypes = { "cs" },
on_attach = on_attach,
capabilities = capabilities,
},
clangd = {
cmd = {
"clangd",
"--background-index",
"--clang-tidy",
"--suggest-missing-includes",
"--all-scopes-completion",
"--completion-style=detailed",
"--header-insertion=never", -- Godot headers use explicit includes
"--pch-storage=memory",
},
filetypes = { "c", "cpp", "objc", "objcpp" },
root_markers = {
"compile_commands.json",
".clangd",
"SConstruct",
"CMakeLists.txt",
".git",
},
on_attach = on_attach,
capabilities = capabilities,
},
glsl_analyzer = {
filetypes = { "glsl" },
on_attach = on_attach,
capabilities = capabilities,
},
wgsl_analyzer = {
filetypes = { "wgsl", "wesl" },
-- Real naga_oil shaders (assets/shaders/*.wgsl) use `#import`/`#{}`
-- syntax that wgsl-analyzer can't parse. Skip them entirely -- never
-- calling on_dir() means the client does not attach. Diagnostics for
-- those files run on in-memory shadow buffers instead (see
-- configs.wgsl_lsp) and are projected back onto the real files.
-- Shadow buffers are buftype=nofile, so vim.lsp.enable skips them and
-- wgsl_lsp starts the client for them explicitly -- no special-casing
-- needed here. Everything else attaches normally; outside a git root it
-- falls back to single-file mode.
root_dir = function(bufnr, on_dir)
local name = vim.api.nvim_buf_get_name(bufnr)
if name:match("assets/shaders/[^/]+%.wgsl$") then
return
end
local util = require("lspconfig.util")
on_dir(util.root_pattern(".git")(name))
end,
on_attach = on_attach,
capabilities = capabilities,
},
pylsp = {
filetypes = { "python" },
on_attach = on_attach,
capabilities = capabilities,
},
ron_lsp = {
cmd = { "ron-lsp" },
filetypes = { "ron" },
root_dir = function(bufnr, on_dir)
local util = require("lspconfig.util")
local fname = vim.api.nvim_buf_get_name(bufnr)
on_dir(util.root_pattern("Cargo.toml", ".git")(fname) or vim.uv.cwd())
end,
on_attach = on_attach,
capabilities = capabilities,
},
}
-- vim.lsp.enable() reads `filetypes` from each config and sets up its own
-- FileType autocmds, so no extra autocmds are needed here.
for server, opts in pairs(servers) do
vim.lsp.config(server, opts)
vim.lsp.enable(server)
end