local opts = { noremap=true, silent=true } vim.api.nvim_set_keymap('n', 'e', 'lua vim.diagnostic.open_float()', opts) vim.api.nvim_set_keymap('n', '[d', 'lua vim.diagnostic.goto_prev()', opts) vim.api.nvim_set_keymap('n', ']d', 'lua vim.diagnostic.goto_next()', opts) vim.api.nvim_set_keymap('n', 'q', 'lua vim.diagnostic.setloclist()', opts) -- 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) -- Enable completion triggered by vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') -- Mappings. -- See `:help vim.lsp.*` for documentation on any of the below functions -- set in ~/.config/nvim/keybindings.vim -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', 'lua vim.lsp.buf.declaration()', opts) -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', 'lua vim.lsp.buf.definition()', opts) -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', 'lua vim.lsp.buf.hover()', opts) -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', 'lua vim.lsp.buf.implementation()', opts) -- vim.api.nvim_buf_set_keymap(bufnr, 'n', '', 'lua vim.lsp.buf.signature_help()', opts) -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'D', 'lua vim.lsp.buf.type_definition()', opts) -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'rn', 'lua vim.lsp.buf.rename()', opts) -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'ca', 'lua vim.lsp.buf.code_action()', opts) -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', 'lua vim.lsp.buf.references()', opts) -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'f', 'lua vim.lsp.buf.formatting()', opts) -- highlighting things under cursor -- if client.resolved_capabilities.document_highlight then -- vim.cmd [[ -- hi! LspReferenceRead cterm=bold ctermbg=red guibg=LightYellow -- hi! LspReferenceText cterm=bold ctermbg=red guibg=LightYellow -- hi! LspReferenceWrite cterm=bold ctermbg=red guibg=LightYellow -- augroup lsp_document_highlight -- autocmd! * -- autocmd! CursorHold lua vim.lsp.buf.document_highlight() -- autocmd! CursorMoved lua vim.lsp.buf.clear_references() -- augroup END -- ]] -- end end vim.cmd [[autocmd! ColorScheme * highlight NormalFloat guibg=#1f2335]] vim.cmd [[autocmd! ColorScheme * highlight FloatBorder guifg=white guibg=#1f2335]] -- squared corners -- local border = { -- {"┌", "FloatBorder"}, -- {"─", "FloatBorder"}, -- {"┐", "FloatBorder"}, -- {"|", "FloatBorder"}, -- {"┘", "FloatBorder"}, -- {"─", "FloatBorder"}, -- {"└", "FloatBorder"}, -- {"|", "FloatBorder"}, -- } -- rounded local border = { {"╭", "FloatBorder"}, {"─", "FloatBorder"}, {"╮", "FloatBorder"}, {"│", "FloatBorder"}, {"╯", "FloatBorder"}, {"─", "FloatBorder"}, {"╰", "FloatBorder"}, {"│", "FloatBorder"}, } local handlers = { ["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {border = border}), ["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, {border = border }), } local DEFAULT_SETTINGS = { ui = { icons = { -- The list icon to use for installed servers. server_installed = "◍", -- The list icon to use for servers that are pending installation. server_pending = "◍", -- The list icon to use for servers that are not installed. server_uninstalled = "◍", }, keymaps = { -- Keymap to expand a server in the UI toggle_server_expand = "", -- Keymap to install a server install_server = "i", -- Keymap to reinstall/update a server update_server = "u", -- Keymap to update all installed servers update_all_servers = "U", -- Keymap to uninstall a server uninstall_server = "X", }, }, -- The directory in which to install all servers. -- install_root_dir = "/home/sudacode/.vim/lsp", pip = { -- These args will be added to `pip install` calls. Note that setting extra args might impact intended behavior -- and is not recommended. -- -- Example: { "--proxy", "https://proxyserver" } install_args = {}, }, on_attach = on_attach, handlers=handlers, -- Controls to which degree logs are written to the log file. It's useful to set this to vim.log.levels.DEBUG when -- debugging issues with server installations. log_level = vim.log.levels.INFO, -- Limit for the maximum amount of servers to be installed at the same time. Once this limit is reached, any further -- servers that are requested to be installed will be put in a queue. max_concurrent_installers = 4, } vim.diagnostic.config({ virtual_text = true, signs = true, underline = false, update_in_insert = false, severity_sort = true, }) local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " } for type, icon in pairs(signs) do local hl = "DiagnosticSign" .. type vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) end function PrintDiagnostics(opts, bufnr, line_nr, client_id) bufnr = bufnr or 0 line_nr = line_nr or (vim.api.nvim_win_get_cursor(0)[1] - 1) opts = opts or {['lnum'] = line_nr} local line_diagnostics = vim.diagnostic.get(bufnr, opts) if vim.tbl_isempty(line_diagnostics) then return end local diagnostic_message = "" for i, diagnostic in ipairs(line_diagnostics) do diagnostic_message = diagnostic_message .. string.format("%d: %s", i, diagnostic.message or "") print(diagnostic_message) if i ~= #line_diagnostics then diagnostic_message = diagnostic_message .. "\n" end end vim.api.nvim_echo({{diagnostic_message, "Normal"}}, false, {}) end -- vim.cmd [[ autocmd! CursorHold * lua PrintDiagnostics() ]] local lsp_installer = require("nvim-lsp-installer") -- Register a handler that will be called for each installed server when it's ready (i.e. when installation is finished -- or if the server is already installed). lsp_installer.on_server_ready(function(server) local opts = {} -- (optional) Customize the options passed to the server -- if server.name == "tsserver" then -- opts.root_dir = function() ... end -- end -- This setup() function will take the provided server configuration and decorate it with the necessary properties -- before passing it onwards to lspconfig. -- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md server:setup(DEFAULT_SETTINGS) end) -- Use a loop to conveniently call 'setup' on multiple servers and -- map buffer local keybindings when the language server attaches local servers = { 'pyright', 'bashls', 'sqls', 'vimls', 'yamlls', 'dockerls', 'html', 'sumneko_lua', 'jsonls', 'dotls', 'rust_analyzer', 'clangd' } for _, lsp in pairs(servers) do require('lspconfig')[lsp].setup { on_attach = on_attach, flags = { -- This will be the default in neovim 0.7+ debounce_text_changes = 150, } } end