59 lines
1.9 KiB
Lua
59 lines
1.9 KiB
Lua
-- Modern LSP setup for Neovim 0.11+
|
|
-- Compatible with LazyVim and nvim-lspconfig >= v0.2.1
|
|
|
|
-- Load Mason to manage LSP servers
|
|
require("mason").setup()
|
|
require("mason-lspconfig").setup({
|
|
ensure_installed = { "lua_ls", "ts_ls", "pyright", "clangd" },
|
|
})
|
|
|
|
-- New Neovim 0.11 API for configuring LSPs
|
|
local lsp = vim.lsp
|
|
local configs = lsp.configs
|
|
local util = require("lspconfig.util")
|
|
|
|
-- Function that runs when an LSP attaches
|
|
local on_attach = function(client, bufnr)
|
|
local opts = { buffer = bufnr, noremap = true, silent = true }
|
|
local map = vim.keymap.set
|
|
map("n", "gd", vim.lsp.buf.definition, opts, { desc = "Go to definition" })
|
|
map("n", "K", vim.lsp.buf.hover, opts, { desc = "Hover documentation" })
|
|
map("n", "<leader>rn", vim.lsp.buf.rename, opts, { desc = "Rename symbol" })
|
|
map("n", "<leader>ca", vim.lsp.buf.code_action, opts, { desc = "Code action" })
|
|
map("n", "gr", vim.lsp.buf.references, opts, { desc = "Go to references" })
|
|
map("n", "<leader>e", vim.diagnostic.open_float, opts, { desc = "Show diagnostics" })
|
|
end
|
|
|
|
-- Default capabilities (for autocompletion)
|
|
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
|
|
|
-- Configure LSP servers
|
|
local servers = {
|
|
lua_ls = { cmd = { "lua-language-server" } },
|
|
ts_ls = { cmd = { "typescript-language-server", "--stdio" } },
|
|
pyright = { cmd = { "pyright-langserver", "--stdio" } },
|
|
clangd = {
|
|
cmd = { "clangd" },
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
init_options = {
|
|
clangdFileStatus = true,
|
|
fallbackFlags = { "-style={UseTab: ForIndentation}" },
|
|
}
|
|
},
|
|
}
|
|
|
|
for name, config in pairs(servers) do
|
|
vim.lsp.config[name] = vim.tbl_extend("force", {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
}, config)
|
|
vim.lsp.start(vim.lsp.config[name])
|
|
end
|
|
|
|
require('lspconfig').asm_lsp.setup{
|
|
cmd = { "asm-lsp" },
|
|
filetypes = { "asm", "nasm", "gas" },
|
|
}
|
|
|