From c9502c9c4b61c4cab7655c484ef7e577308343cf Mon Sep 17 00:00:00 2001 From: yuzu-eva Date: Fri, 23 Dec 2022 22:01:25 +0100 Subject: readded nvim --- .config/nvim/lua/user/plugins/lspconfig.lua | 131 ++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 .config/nvim/lua/user/plugins/lspconfig.lua (limited to '.config/nvim/lua/user/plugins/lspconfig.lua') diff --git a/.config/nvim/lua/user/plugins/lspconfig.lua b/.config/nvim/lua/user/plugins/lspconfig.lua new file mode 100644 index 0000000..a63975b --- /dev/null +++ b/.config/nvim/lua/user/plugins/lspconfig.lua @@ -0,0 +1,131 @@ +local buf_option = vim.api.nvim_buf_set_option +local buf_keymap = require 'lib.utils'.buf_keymap + +vim.diagnostic.config { + virtual_text = false, + severity_sort = true, + float = { + source = true, + focus = false, + format = function(diagnostic) + if diagnostic.user_data ~= nil and diagnostic.user_data.lsp.code ~= nil then + return string.format("%s: %s", diagnostic.user_data.lsp.code, diagnostic.message) + end + return diagnostic.message + end, + } +} + +local on_attach = function(_, bufnr) + buf_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + + buf_keymap(bufnr, 'n', 'gD', 'lua vim.lsp.buf.declaration()') + buf_keymap(bufnr, 'n', 'gd', 'lua vim.lsp.buf.definition()') + buf_keymap(bufnr, 'n', 'K', 'lua vim.lsp.buf.hover()') + buf_keymap(bufnr, 'n', 'gi', 'lua vim.lsp.buf.implementation()') + buf_keymap(bufnr, 'n', '', 'lua vim.lsp.buf.signature_help()') + buf_keymap(bufnr, 'n', 'D', 'lua vim.lsp.buf.type_definition()') + buf_keymap(bufnr, 'n', 'rn', 'lua vim.lsp.buf.rename()') + buf_keymap(bufnr, 'n', 'gr', ':Telescope lsp_references') + + buf_keymap(bufnr, 'n', 'ca', ':CodeActionMenu') + buf_keymap(bufnr, 'v', 'ca', ':CodeActionMenu') + + buf_keymap(bufnr, 'n', 'd', 'lua vim.diagnostic.open_float()') + buf_keymap(bufnr, 'n', '[d', 'lua vim.diagnostic.goto_prev()') + buf_keymap(bufnr, 'n', ']d', 'lua vim.diagnostic.goto_next()') + buf_keymap(bufnr, 'n', 'F', 'lua vim.lsp.buf.format { async = true }') + + -- Autoformat on save doesn't work with server_capabilities, even + -- though it's the replacement for the deprecated resolved_capabilities. + + -- if _.server_capabilities.document_formatting then + -- vim.api.nvim_command [[augroup Format]] + -- vim.api.nvim_command [[autocmd! * ]] + -- vim.api.nvim_command [[autocmd BufWritePre lua vim.lsp.buf.formatting_seq_sync()]] + -- vim.api.nvim_command [[augroup END]] + -- end +end + +-- provide additional completion capabilities +local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()) + +require 'lspconfig'.emmet_ls.setup { + on_attach = on_attach, + capabilities = capabilities, + flags = { + debounce_text_changes = 150, + }, + filetypes = { 'html', 'javascript', 'typescript', 'javascriptreact', 'typescriptreact' } +} + +local runtime_path = vim.split(package.path, ';') +table.insert(runtime_path, "lua/?.lua") +table.insert(runtime_path, "lua/?/init.lua") +require 'lspconfig'.sumneko_lua.setup { + on_attach = on_attach, + capabilities = capabilities, + flags = { + debounce_text_changes = 150, + }, + cmd = { "/home/cafebabe/.local/src/lua-language-server/bin/lua-language-server", "-E", "/home/cafebabe/.local/src/lua-language-server/bin/main.lua" }; + settings = { + Lua = { + runtime = { + -- Tell language server which version of lua is used. + version = 'LuaJIT', + -- Setup lua path + path = runtime_path, + }, + diagnostics = { + -- Recognize globals + globals = { 'vim', 'use', 'parse' }, + }, + workspace = { + -- Make server aware of Neovim runtime files + library = vim.api.nvim_get_runtime_file("", true), + }, + -- Do not send telemetry data + telemetry = { + enable = false, + }, + }, + }, +} + +require 'lspconfig'.bashls.setup { + on_attach = on_attach, + capabilities = capabilities, + flags = { + debounce_text_changes = 150, + }, +} + +require 'lspconfig'.pylsp.setup { + on_attach = on_attach, + capabilities = capabilities, + flags = { + debounce_text_changes = 150, + }, +} + +require 'lspconfig'.clangd.setup { + on_attach = on_attach, + capabilities = capabilities, + flags = { + debounce_text_changes = 150, + }, +} + + +-- suppress error messages from lang servers +vim.notify = function(msg, log_level, _) + if msg:match 'exit code' then + return + end + if log_level == vim.log.levels.ERROR then + vim.api.nvim_err_writeln(msg) + else + vim.api.nvim_echo({ { msg } }, true, {}) + end +end -- cgit v1.2.3