nvim/plugin-confs/lspconfig.lua

204 lines
8.1 KiB
Lua
Raw Normal View History

2023-08-15 11:11:38 -07: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)
2022-11-02 22:50:13 -07:00
-- 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
-- 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
end
2023-08-17 01:12:44 -07:00
-- vim.cmd [[autocmd! ColorScheme * highlight NormalFloat guibg=#1f2335]]
-- vim.cmd [[autocmd! ColorScheme * highlight FloatBorder guifg=white guibg=#1f2335]]
2022-11-02 22:50:13 -07:00
-- squared corners
-- local border = {
-- {"┌", "FloatBorder"},
-- {"─", "FloatBorder"},
-- {"┐", "FloatBorder"},
-- {"|", "FloatBorder"},
-- {"┘", "FloatBorder"},
-- {"─", "FloatBorder"},
-- {"└", "FloatBorder"},
-- {"|", "FloatBorder"},
-- }
-- rounded
local border = {
2023-08-14 18:26:43 -07:00
{ "", "FloatBorder" }, { "", "FloatBorder" }, { "", "FloatBorder" },
{ "", "FloatBorder" }, { "", "FloatBorder" }, { "", "FloatBorder" },
{ "", "FloatBorder" }, { "", "FloatBorder" }
2022-11-02 22:50:13 -07:00
}
local handlers = {
2023-08-14 18:26:43 -07:00
["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover,
{ border = border }),
["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers
.signature_help,
{ border = border })
2022-11-02 22:50:13 -07:00
}
-- local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview
-- function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...)
-- opts = {
-- { "border", border },
-- }
-- opts.border = opts.border or border
-- return orig_util_open_floating_preview(contents, syntax, opts, ...)
-- end
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.
2023-08-14 18:26:43 -07:00
server_uninstalled = ""
2022-11-02 22:50:13 -07:00
},
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
2023-08-14 18:26:43 -07:00
uninstall_server = "X"
}
2022-11-02 22:50:13 -07:00
},
-- 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" }
2023-08-14 18:26:43 -07:00
install_args = {}
2022-11-02 22:50:13 -07:00
},
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.
2023-08-14 18:26:43 -07:00
max_concurrent_installers = 4
2022-11-02 22:50:13 -07:00
}
vim.diagnostic.config({
virtual_text = true,
signs = true,
underline = false,
update_in_insert = false,
2023-08-14 18:26:43 -07:00
severity_sort = true
2022-11-02 22:50:13 -07: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
2023-08-14 18:26:43 -07:00
diagnostic_message = diagnostic_message ..
string.format("%d: %s", i,
diagnostic.message or "")
2022-11-02 22:50:13 -07:00
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() ]]
-- 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).
-- local servers = { 'jedi_language_server', 'bashls', 'vimls', 'yamlls', 'dockerls', 'rust_analyzer', 'clangd', 'ansiblels' }
-- for _, lsp in pairs(servers) do
-- require('lspconfig')[lsp].setup {
-- on_attach = on_attach,
-- handlers = handlers,
-- flags = {
-- -- This will be the default in neovim 0.7+
-- debounce_text_changes = 150,
-- }
-- }
-- end
-- local plugins_path = vim.fn.stdpath("data") .. "site/autoload/plug.vim"
-- local dir_list = vim.fn.glob(plugins_path .. "/*", true, true)
-- local library_table = {}
-- for _, v in ipairs(dir_list) do
-- library_table[v .. "/lua"] = true
-- end
-- library_table[vim.fn.expand("$VIMRUNTIME/lua")] = true
-- library_table[vim.fn.stdpath("config") .. "/lua"] = true
-- require('lspconfig').sumneko_lua.setup({
-- settings = {
-- Lua = {
-- diagnostics = { globals = { "vim" } },
-- workspace = { library = library_table },
-- },
-- },
-- })
-- -- require 'lspconfig'.bashls.setup {}