Dot_Files/.config/nvim/lua/plugins/configs/lsp.lua

101 lines
2.7 KiB
Lua
Raw Normal View History

2022-01-08 15:24:29 -06:00
local lsp_installer = require("nvim-lsp-installer")
2022-01-15 19:15:09 -06:00
local async = require("plenary.async")
2022-01-15 19:31:10 -06:00
local required_servers = {
"sumneko_lua",
"rust_analyzer",
"bashls",
"eslint",
"dockerls",
2022-02-24 04:29:51 -06:00
"ansiblels",
"pyright",
"tsserver"
2022-01-15 19:31:10 -06:00
}
for _, name in pairs(required_servers) do
local server_is_found, server = lsp_installer.get_server(name)
if server_is_found then
if not server:is_installed() then
async.run(function()
vim.notify.async("Installing Language Server " .. name, "info", {
title = "Lsp Installer",
2022-02-21 14:25:45 -06:00
})
2022-01-15 19:31:10 -06:00
end)
server:install()
end
end
end
2022-01-15 19:15:09 -06:00
local function on_attach(client, bufnr)
2022-01-15 19:31:10 -06:00
async.run(function()
vim.notify.async("Attached server " .. client.name, "info", {
title = "Lsp Attach",
2022-02-21 14:25:45 -06:00
}).events.close()
2022-01-15 19:31:10 -06:00
end)
end
2022-01-15 19:15:09 -06:00
2022-01-08 15:24:29 -06:00
lsp_installer.on_server_ready(function(server)
2022-01-10 04:49:12 -06:00
local opts = {
-- Coq configuration, ensure coq actual has capabilties shown
-- capabilities = require("coq").lsp_ensure_capabilities(vim.lsp.protocol.make_client_capabilities()),
capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities()),
2022-01-15 19:31:10 -06:00
on_attach = on_attach,
2022-01-10 04:49:12 -06:00
}
2022-01-08 15:24:29 -06:00
2022-01-10 04:49:12 -06:00
-- In the scenario we're using rust it makes more sense to use rust-tools
-- see: https://github.com/williamboman/nvim-lsp-installer/wiki/Rust
--
-- NOTE: Requires rust_analyzer
if server.name == "rust_analyzer" then
-- Dap installation, required vscode and the following extension to be installed:
-- https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb
--
-- locate it with `find ~/ -name `
2022-02-21 14:25:45 -06:00
local extension_path = os.getenv("HOME") .. "/.vscode/extensions/vadimcn.vscode-lldb-1.6.10/"
local codelldb_path = extension_path .. "adapter/codelldb"
local liblldb_path = extension_path .. "lldb/lib/liblldb.dylib"
2022-01-10 04:49:12 -06:00
local rustopts = {
server = vim.tbl_deep_extend("force", server:get_default_options(), opts, {}),
dap = {
2022-02-21 14:25:45 -06:00
adapter = require("rust-tools.dap").get_codelldb_adapter(codelldb_path, liblldb_path),
},
2022-01-10 04:49:12 -06:00
tools = {
hover_actions = { auto_focus = true },
},
}
require("rust-tools").setup(rustopts)
server:attach_buffers()
else
-- I use ansible a lot, define exceptions for servers that can use
-- server:setup & vim.cmd at the bottom here
if server.name == "ansiblels" then
opts.settings = {
ansible = {
ansible = {
2022-02-21 14:25:45 -06:00
useFullyQualifiedCollectionNames = true,
2022-01-10 04:49:12 -06:00
path = "ansible",
},
ansibleLint = {
enabled = true,
path = "ansible-lint",
},
python = {
interpreterPath = "python3",
},
},
}
2022-01-15 19:15:09 -06:00
elseif server.name == "bashls" then
opts.settings = {
filetypes = {
"zsh",
"bash",
"profile",
},
}
2022-01-10 04:49:12 -06:00
end
server:setup(opts)
vim.cmd([[ do User LspAttachBuffers ]])
end
2022-01-08 15:24:29 -06:00
end)