This repository has been archived on 2023-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/.config/nvim/lua/plugin/backup
David JULIEN f20223da57 [nvim] feat: update lsp config to follow plugins
nvim-lsp-installer stopped setting things up, setup lsp through
lspconfig
2022-05-02 23:35:31 +02:00

131 lines
5.4 KiB
Plaintext

-- 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 = "✓",
server_pending = "o",
server_uninstalled = "x"
}
}
}
local servers = {
"clangd",
"sumneko_lua",
}
for _, name in ipairs(servers) do
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
local lsp_root_path = vim.fn.stdpath("data") .. "/lsp_servers/"
local runtime_path = vim.split(package.path, ';')
table.insert(runtime_path, "lua/?.lua")
table.insert(runtime_path, "lua/?/init.lua")
local enhance_server_opts = {
["clangd"] = function(opts)
opts.settings = {
cmd = { lsp_root_path .. "clangd/clangd/bin/clangd",
"--background-index",
"--suggest-missing-includes",
"--clang-tidy",
"--header-insertion=iwyu"
},
}
end,
["sumneko_lua"] = function(opts)
opts.settings = {
cmd = { lsp_root_path
.. "sumneko_lua/extension/server/bin/"
.. "lua-language-server",
"-E",
lsp_root_path
.. "sumneko_lua/extension/server/main.lua"
},
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",
"use",
"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,
}
local on_attach = function(_, bufnr)
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', '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', '<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', 'gr', vim.lsp.buf.references, 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)
vim.api.nvim_create_user_command("Format", vim.lsp.buf.formatting, {})
end
-- nvim-cmp supports additional completion capabilities
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities)
lsp_installer.on_server_ready(function(server)
-- Specify the default options which we'll use to setup all servers
local opts = {
on_attach = on_attach,
capabilities = capabilities,
}
if enhance_server_opts[server.name] then
-- Enhance the default opts with the server-specific ones
enhance_server_opts[server.name](opts)
end
server:setup(opts)
end)