87 lines
3.0 KiB
Lua
87 lines
3.0 KiB
Lua
-- LSP
|
|
local function augroup(name)
|
|
return vim.api.nvim_create_augroup("user_" .. name, { clear = true })
|
|
end
|
|
|
|
local default_keymaps = {
|
|
{ keys = "<leader>ca", func = vim.lsp.buf.code_action, desc = "Code Actions" },
|
|
{ keys = "<leader>cr", func = vim.lsp.buf.rename, desc = "Code Rename" },
|
|
{ keys = "<leader>k", func = vim.lsp.buf.hover, desc = "Hover Documentation", has = "hoverProvider" },
|
|
{ keys = "K", func = vim.lsp.buf.hover, desc = "Hover (alt)", has = "hoverProvider" },
|
|
{ keys = "gd", func = vim.lsp.buf.definition, desc = "Goto Definition", has = "definitionProvider" },
|
|
}
|
|
|
|
-- I use blink.cmp for completion, but you can use native completion too
|
|
local completion = vim.g.completion_mode or "blink" -- or 'native' for built-in completion
|
|
vim.api.nvim_create_autocmd("LspAttach", {
|
|
group = augroup("lsp_attach"),
|
|
callback = function(args)
|
|
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
|
local buf = args.buf
|
|
if client then
|
|
-- Built-in completion
|
|
if completion == "native" and client:supports_method("textDocument/completion") then
|
|
vim.lsp.completion.enable(true, client.id, args.buf, { autotrigger = true })
|
|
end
|
|
|
|
-- Inlay hints
|
|
if client:supports_method("textDocument/inlayHints") then
|
|
vim.lsp.inlay_hint.enable(true, { bufnr = args.buf })
|
|
end
|
|
|
|
if client:supports_method("textDocument/documentColor") then
|
|
vim.lsp.document_color.enable(true, { bufnr = args.buf }, {
|
|
style = "background", -- 'background', 'foreground', or 'virtual'
|
|
})
|
|
end
|
|
|
|
for _, km in ipairs(default_keymaps) do
|
|
-- Only bind if there's no `has` requirement, or the server supports it
|
|
if not km.has or client.server_capabilities[km.has] then
|
|
vim.keymap.set(
|
|
km.mode or "n",
|
|
km.keys,
|
|
km.func,
|
|
{ buffer = buf, desc = "LSP: " .. km.desc, nowait = km.nowait }
|
|
)
|
|
end
|
|
end
|
|
end
|
|
end,
|
|
})
|
|
|
|
-- Enable LSP servers. Configs come from nvim-lspconfig (lua/plugins/lspconfig.lua).
|
|
-- Per-server overrides go through vim.lsp.config("<server>", { ... }).
|
|
|
|
-- Server-specific overrides
|
|
|
|
-- Neovim uses LuaJIT
|
|
vim.lsp.config("lua_ls", {
|
|
settings = {
|
|
Lua = {
|
|
runtime = { version = "LuaJIT" },
|
|
diagnostics = { globals = { "vim" } }, -- Recognize 'vim' global
|
|
},
|
|
},
|
|
})
|
|
|
|
-- gdscript: Godot's LSP runs inside the Godot editor over TCP (no standalone binary).
|
|
-- Enable it in Godot via Editor Settings > Network > Language Server (default port 6005).
|
|
-- It is only available while the project is open in the Godot editor (or headless:
|
|
-- `godot --headless --editor --path .`); override the port with GDScript_Port.
|
|
|
|
vim.lsp.enable({
|
|
"lua_ls",
|
|
"ols",
|
|
"clangd",
|
|
"gdscript",
|
|
"rust_analyzer",
|
|
"gopls",
|
|
})
|
|
|
|
-- Load Lsp on-demand, e.g: eslint is disable by default
|
|
-- e.g: We could enable eslint by set vim.g.lsp_on_demands = {"eslint"}
|
|
if vim.g.lsp_on_demands then
|
|
vim.lsp.enable(vim.g.lsp_on_demands)
|
|
end
|