2021-10-17 12:44:44 +02:00
|
|
|
-- Author : swytch
|
|
|
|
-- Created : Saturday Sept. 11, 2021 22:12:33 CET
|
|
|
|
-- License : GPLv3
|
|
|
|
-- Description : nvim-lsp-installer plugin config file
|
|
|
|
|
|
|
|
local lsp_installer = require("nvim-lsp-installer")
|
|
|
|
|
|
|
|
lsp_installer.settings {
|
|
|
|
ui = {
|
|
|
|
icons = {
|
|
|
|
server_installed = "✓",
|
2022-04-27 20:12:47 +02:00
|
|
|
server_pending = "o",
|
|
|
|
server_uninstalled = "x"
|
2021-10-17 12:44:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-17 12:49:55 +02:00
|
|
|
local servers = {
|
2022-04-27 20:12:47 +02:00
|
|
|
"clangd",
|
2021-10-17 12:49:55 +02:00
|
|
|
"sumneko_lua",
|
|
|
|
}
|
|
|
|
|
2022-04-27 20:12:47 +02:00
|
|
|
for _, name in ipairs(servers) do
|
2021-10-17 12:49:55 +02:00
|
|
|
local ok, server = lsp_installer.get_server(name)
|
|
|
|
-- Check that the server is supported in nvim-lsp-installer
|
|
|
|
if ok then
|
|
|
|
if not server:is_installed() then
|
|
|
|
print("Installing " .. name)
|
|
|
|
server:install()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-27 20:12:47 +02:00
|
|
|
local lsp_root_path = vim.fn.stdpath("data") .. "/lsp_servers/"
|
|
|
|
local runtime_path = vim.split(package.path, ';')
|
|
|
|
|
|
|
|
|
|
|
|
local clangd_binary = lsp_root_path .. "clangd/clangd/bin/clangd"
|
|
|
|
|
|
|
|
table.insert(runtime_path, "lua/?.lua")
|
|
|
|
table.insert(runtime_path, "lua/?/init.lua")
|
|
|
|
|
|
|
|
local enhance_server_opts = {
|
2022-04-27 21:58:12 +02:00
|
|
|
["clangd"] = function(opts)
|
|
|
|
opts.settings = {
|
|
|
|
cmd = { clangd_binary,
|
|
|
|
"--background-index",
|
|
|
|
"--suggest-missing-includes",
|
|
|
|
"--clang-tidy",
|
|
|
|
"--header-insertion=iwyu"
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end,
|
|
|
|
["sumneko_lua"] = function(opts)
|
|
|
|
opts.settings = {
|
|
|
|
Lua = {
|
|
|
|
runtime = {
|
|
|
|
-- Tell the language server which version of Lua you're
|
|
|
|
-- using (most likely LuaJIT in the case of Neovim)
|
|
|
|
version = 'LuaJIT',
|
|
|
|
-- Setup your lua path
|
|
|
|
path = runtime_path,
|
|
|
|
},
|
|
|
|
diagnostics = {
|
|
|
|
-- Get the language server to recognize the `vim` global
|
|
|
|
globals = {
|
|
|
|
"vim",
|
|
|
|
"globals",
|
|
|
|
"utils"
|
|
|
|
},
|
|
|
|
},
|
|
|
|
workspace = {
|
|
|
|
-- Make the server aware of Neovim runtime files
|
|
|
|
library =
|
|
|
|
vim.api.nvim_get_runtime_file("", true),
|
|
|
|
},
|
|
|
|
-- Do not send telemetry data containing a randomized but
|
|
|
|
-- unique identifier
|
|
|
|
telemetry = {
|
|
|
|
enable = false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end,
|
2022-04-27 20:12:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
local on_attach = function(_, bufnr)
|
2022-04-27 21:58:12 +02:00
|
|
|
local opts = { buffer = bufnr }
|
|
|
|
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
|
|
|
|
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
|
|
|
|
vim.keymap.set("n", "gr", vim.lsp.buf.references, 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", "<leader>ln", vim.diagnostic.goto_next, opts)
|
|
|
|
vim.keymap.set("n", "<leader>lp", vim.diagnostic.goto_prev, opts)
|
|
|
|
vim.keymap.set("n", "<leader>lf", vim.lsp.buf.formatting, opts)
|
|
|
|
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, opts)
|
|
|
|
vim.keymap.set("n", "<leader>wa",
|
|
|
|
vim.lsp.buf.add_workspace_folder, opts)
|
|
|
|
vim.keymap.set("n", "<leader>wr",
|
|
|
|
vim.lsp.buf.remove_workspace_folder, opts)
|
|
|
|
vim.keymap.set("n", "<leader>wl", function()
|
|
|
|
vim.inspect(vim.lsp.buf.list_workspace_folders())
|
|
|
|
end, opts)
|
|
|
|
vim.keymap.set("n", "<leader>D", vim.lsp.buf.type_definition, opts)
|
|
|
|
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts)
|
|
|
|
vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, opts)
|
|
|
|
vim.keymap.set("n", "<leader>so",
|
|
|
|
require("telescope.builtin").lsp_document_symbols, opts)
|
2022-04-27 20:12:47 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- nvim-cmp supports additional completion capabilities
|
|
|
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
|
|
|
capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities)
|
|
|
|
|
2021-10-17 12:44:44 +02:00
|
|
|
lsp_installer.on_server_ready(function(server)
|
2022-04-27 21:58:12 +02:00
|
|
|
-- Specify the default options which we'll use to setup all servers
|
|
|
|
local opts = {
|
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = capabilities,
|
|
|
|
}
|
2021-10-17 12:44:44 +02:00
|
|
|
|
2022-04-27 21:58:12 +02:00
|
|
|
if enhance_server_opts[server.name] then
|
|
|
|
-- Enhance the default opts with the server-specific ones
|
|
|
|
enhance_server_opts[server.name](opts)
|
|
|
|
end
|
2021-10-17 12:44:44 +02:00
|
|
|
|
2022-04-27 21:58:12 +02:00
|
|
|
server:setup(opts)
|
2021-10-17 12:44:44 +02:00
|
|
|
end)
|