2022-02-10 00:43:30 -08:00
|
|
|
local opts = { noremap=true, silent=true }
|
|
|
|
vim.api.nvim_set_keymap('n', '<space>e', '<cmd>lua vim.diagnostic.open_float()<CR>', opts)
|
|
|
|
vim.api.nvim_set_keymap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
|
|
|
|
vim.api.nvim_set_keymap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
|
|
|
|
vim.api.nvim_set_keymap('n', '<space>q', '<cmd>lua vim.diagnostic.setloclist()<CR>', 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 <c-x><c-o>
|
|
|
|
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
|
2022-02-10 23:02:09 -08:00
|
|
|
-- set in ~/.config/nvim/keybindings.vim
|
|
|
|
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
|
|
|
|
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
|
|
|
|
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
|
|
|
|
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
|
|
|
|
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<C-s>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
|
|
|
|
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
|
|
|
|
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
|
|
|
|
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
|
|
|
|
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
|
|
|
|
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
|
|
|
|
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
|
|
|
|
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
|
|
|
|
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', 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! * <buffer>
|
|
|
|
-- autocmd! CursorHold <buffer> lua vim.lsp.buf.document_highlight()
|
|
|
|
-- autocmd! CursorMoved <buffer> lua vim.lsp.buf.clear_references()
|
|
|
|
-- augroup END
|
|
|
|
-- ]]
|
|
|
|
-- end
|
2022-02-10 00:43:30 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
vim.cmd [[autocmd! ColorScheme * highlight NormalFloat guibg=#1f2335]]
|
|
|
|
vim.cmd [[autocmd! ColorScheme * highlight FloatBorder guifg=white guibg=#1f2335]]
|
|
|
|
|
2022-02-11 11:57:44 -08:00
|
|
|
-- squared corners
|
|
|
|
|
|
|
|
-- local border = {
|
|
|
|
-- {"┌", "FloatBorder"},
|
|
|
|
-- {"─", "FloatBorder"},
|
|
|
|
-- {"┐", "FloatBorder"},
|
|
|
|
-- {"|", "FloatBorder"},
|
|
|
|
-- {"┘", "FloatBorder"},
|
|
|
|
-- {"─", "FloatBorder"},
|
|
|
|
-- {"└", "FloatBorder"},
|
|
|
|
-- {"|", "FloatBorder"},
|
|
|
|
-- }
|
|
|
|
|
|
|
|
-- rounded
|
|
|
|
|
2022-02-10 00:43:30 -08:00
|
|
|
local border = {
|
2022-02-11 11:57:44 -08:00
|
|
|
{"╭", "FloatBorder"},
|
|
|
|
{"─", "FloatBorder"},
|
|
|
|
{"╮", "FloatBorder"},
|
|
|
|
{"│", "FloatBorder"},
|
|
|
|
{"╯", "FloatBorder"},
|
|
|
|
{"─", "FloatBorder"},
|
|
|
|
{"╰", "FloatBorder"},
|
|
|
|
{"│", "FloatBorder"},
|
2022-02-10 00:43:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
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 }),
|
|
|
|
}
|
|
|
|
|
2022-02-09 01:25:05 -08:00
|
|
|
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 = "<CR>",
|
|
|
|
-- 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.
|
2022-02-11 11:57:44 -08:00
|
|
|
-- install_root_dir = "/home/sudacode/.vim/lsp",
|
2022-02-09 01:25:05 -08:00
|
|
|
|
|
|
|
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 = {},
|
|
|
|
},
|
2022-02-10 00:43:30 -08:00
|
|
|
on_attach = on_attach,
|
2022-02-11 11:57:44 -08:00
|
|
|
handlers=handlers,
|
2022-02-09 01:25:05 -08:00
|
|
|
|
|
|
|
-- 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,
|
|
|
|
}
|
|
|
|
|
2022-02-10 00:43:30 -08:00
|
|
|
vim.diagnostic.config({
|
|
|
|
virtual_text = true,
|
|
|
|
signs = true,
|
2022-02-14 17:41:21 -08:00
|
|
|
underline = false,
|
2022-02-10 00:43:30 -08:00
|
|
|
update_in_insert = false,
|
2022-02-10 23:02:09 -08:00
|
|
|
severity_sort = true,
|
2022-02-10 00:43:30 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
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() ]]
|
2022-02-09 01:25:05 -08:00
|
|
|
|
|
|
|
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)
|
2022-02-10 00:43:30 -08:00
|
|
|
|
|
|
|
-- Use a loop to conveniently call 'setup' on multiple servers and
|
|
|
|
-- map buffer local keybindings when the language server attaches
|
2022-03-08 22:49:34 -08:00
|
|
|
local servers = { 'pyright', 'bashls', 'vimls', 'yamlls', 'dockerls', 'html', 'sumneko_lua', 'dotls', 'rust_analyzer', 'clangd' }
|
2022-02-11 11:57:44 -08:00
|
|
|
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
|