local coq = require("coq") local lsp_installer = require("nvim-lsp-installer") local nvim_runtime_path = vim.split(package.path, ';') table.insert(nvim_runtime_path, "lua/?.lua") table.insert(nvim_runtime_path, "lua/?/init.lua") local language_servers = { "ansiblels", "bashls", "dockerls", "efm", "eslint", "html", "pyright", "rust_analyzer", "sumneko_lua", "svelte", "taplo", "tsserver", "volar" } for _, server_name in pairs(language_servers) do local server_found, server = lsp_installer.get_server(server_name) if server_found and not server:is_installed() then print("Installing " .. server_name) server:install() end end local extra_server_opts = { ["efm"] = function(opts) opts.filetypes = {"lua"} opts.init_options = {documentFormatting = true} opts.settings = { rootMarkers = {".git/"}, languages = { lua = {{formatCommand = "lua-format -i", formatStdin = true}} } } end, ["sumneko_lua"] = function(opts) opts.settings = { Lua = { runtime = {version = 'LuaJIT', path = nvim_runtime_path}, diagnostics = {globals = {'vim'}}, workspace = {library = vim.api.nvim_get_runtime_file("", true)}, telemetry = {enable = false} } } end } local function custom_on_attach(client, buffer_nr) -- onmifunc vim.api.nvim_buf_set_option(buffer_nr, "omnifunc", "v:lua.vim.lsp.omnifunc") -- Helper function local opts = {noremap = true, silent = true} local function bufnnoremap(key, action) vim.api.nvim_buf_set_keymap(buffer_nr, 'n', key, action, opts) end -- Inspect function bufnnoremap("K", "lua vim.lsp.buf.hover()") bufnnoremap("", "lua vim.lsp.buf.signature_help()") -- Navigation bufnnoremap("gd", "lua vim.lsp.buf.definition()") bufnnoremap("gD", "lua vim.lsp.buf.declaration()") bufnnoremap("gi", "lua vim.lsp.buf.implementation()") bufnnoremap("gr", "lua vim.lsp.buf.references()") bufnnoremap("ga", "lua vim.lsp.buf.code_action()") -- Rename all references of symbol bufnnoremap("R", "lua vim.lsp.buf.rename()") -- Navigate diagnostics bufnnoremap("", "lua vim.diagnostic.goto_next()") bufnnoremap("", "lua vim.diagnostic.goto_prev()") -- Show line diagnostics bufnnoremap("d", 'lua vim.diagnostic.open_float(0, {scope = "line"})') -- Open local diagnostics in local list bufnnoremap("D", "lua vim.diagnostic.setloclist()") -- Open all project diagnostics in quickfix list bufnnoremap("", "lua vim.diagnostic.setqflist()") if client.resolved_capabilities.document_formatting then vim.cmd("autocmd BufWritePre lua vim.lsp.buf.formatting_sync()") end -- vim-illuminate require("illuminate").on_attach(client) end lsp_installer.on_server_ready(function(server) local opts = coq.lsp_ensure_capabilities({ on_attach = custom_on_attach, capabilities = vim.lsp.protocol.make_client_capabilities() }) if extra_server_opts[server.name] then extra_server_opts[server.name](opts) end server:setup(opts) end)