mirror of
https://github.com/foo-dogsquared/dotfiles.git
synced 2025-01-31 10:57:58 +00:00
55 lines
2.2 KiB
Lua
55 lines
2.2 KiB
Lua
-- LSP config
|
|
local nvim_lsp = require("lspconfig")
|
|
|
|
function setup()
|
|
-- Use an on_attach function to only map the following keys
|
|
-- after the language server attaches to the current buffer
|
|
local on_attach = function(client, bufnr)
|
|
local function buf_set_option(...)
|
|
vim.api.nvim_buf_set_option(bufnr, ...)
|
|
end
|
|
|
|
-- Enable completion triggered by <c-x><c-o>
|
|
buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc")
|
|
|
|
-- Mappings.
|
|
local opts = { noremap = true, silent = true }
|
|
|
|
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
|
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
|
|
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
|
|
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
|
|
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts)
|
|
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, opts)
|
|
vim.keymap.set("n", "<space>wa", vim.lsp.buf.add_workspace_folder, opts)
|
|
vim.keymap.set("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, opts)
|
|
vim.keymap.set("n", "<space>wl", print(vim.inspect(vim.lsp.buf.list_workspace_folders, opts)))
|
|
vim.keymap.set("n", "<space>D", vim.lsp.buf.type_definition, opts)
|
|
vim.keymap.set("n", "<space>rn", vim.lsp.buf.rename, opts)
|
|
vim.keymap.set("n", "<space>ca", vim.lsp.buf.code_action, opts)
|
|
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts)
|
|
vim.keymap.set("n", "<space>e", vim.lsp.diagnostic.show_line_diagnostics, opts)
|
|
vim.keymap.set("n", "[d", vim.lsp.diagnostic.goto_prev, opts)
|
|
vim.keymap.set("n", "]d", vim.lsp.diagnostic.goto_next, opts)
|
|
vim.keymap.set("n", "<space>q", vim.lsp.diagnostic.set_loclist, opts)
|
|
vim.keymap.set("n", "<space>f", vim.lsp.buf.formatting, opts)
|
|
end
|
|
|
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
|
capabilities.textDocument.completion.completionItem.snippetSupport = true
|
|
capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities)
|
|
|
|
-- Enable the following language servers
|
|
local servers = { "clangd", "rust_analyzer", "pyright", "tsserver", "rnix", "lua_ls" }
|
|
for _, lsp in ipairs(servers) do
|
|
nvim_lsp[lsp].setup({
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
})
|
|
end
|
|
end
|
|
|
|
return {
|
|
setup = setup,
|
|
}
|