require('my/plugins') require('my/completion') local map = require('my.functions').map -- only do this after the language server attaches to the current buffer local on_attach = function(client, bufnr) ---@format disable map('n', '', vim.diagnostic.goto_prev, nil, bufnr) map('n', '', vim.diagnostic.goto_next, nil, bufnr) map('n', 'gD', vim.lsp.buf.declaration, 'Go to declaration', bufnr) map('n', 'gd', vim.lsp.buf.definition, 'Go to definition', bufnr) map('n', '', vim.lsp.buf.definition, 'Go to definition', bufnr) map('n', 'gi', vim.lsp.buf.implementation, 'Go to implementation', bufnr) map('n', 'gr', vim.lsp.buf.references, 'Show references', bufnr) map('n', 'K', vim.lsp.buf.hover, 'Hover', bufnr) map('i', '', vim.lsp.buf.hover, 'Hover', bufnr) map('n', 'lwa', vim.lsp.buf.add_workspace_folder, 'Add workspace folder', bufnr) map('n', 'lwr', vim.lsp.buf.remove_workspace_folder, 'Remove workspace folder', bufnr) map('n', 'lwl', function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, 'List workspace folders', bufnr) map('n', 'lr', vim.lsp.buf.rename, 'Rename symbol', bufnr) map('n', 'la', vim.lsp.buf.code_action, 'Code action', bufnr) map('n', 'lf', vim.lsp.buf.formatting, 'Format buffer', bufnr) -- highlight symbol under cursor if client.resolved_capabilities.document_highlight then vim.api.nvim_create_augroup('config_lsp', { clear = false }) vim.api.nvim_clear_autocmds({ buffer = bufnr, group = 'config_lsp', }) vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { group = 'config_lsp', buffer = bufnr, callback = vim.lsp.buf.document_highlight, }) vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { group = 'config_lsp', buffer = bufnr, callback = vim.lsp.buf.clear_references, }) -- Don't autoformat code like text vim.bo.formatoptions = vim.o.formatoptions:gsub('t', '') -- Let LSP autoformat on save require('lsp-format').on_attach(client) -- virtual text hint for parameters require ('lsp_signature').on_attach({ bind = true, handler_opts = { border = 'rounded' }, floating_window = false }, bufnr) end -- -- show help on hover -- if client.resolved_capabilities.hover then -- vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { -- group = 'config_lsp', -- buffer = bufnr, -- callback = vim.lsp.buf.hover -- }) -- end end -- update client capabilities with completion plugin stuff local capabilities = require('cmp_nvim_lsp').update_capabilities( vim.lsp.protocol.make_client_capabilities()) vim.lsp.handlers['textDocument/hover'] = vim.lsp.with( vim.lsp.handlers.hover, { border = 'rounded', width = 60, focusable = false }) -- setup servers local lspconfig = require('lspconfig') if vim.fn.executable('clangd') > 0 then require("clangd_extensions").setup({ server = { cmd = { 'clangd', '--compile-commands-dir=build', '--clang-tidy', -- needs >=clangd-9 '--ranking-model=decision_forest' -- needs >=clangd-12 }, on_attach = on_attach, capabilities = capabilities }, extensions = { inlay_hints = { show_parameter_hints = false } } }) end if vim.fn.executable('lua-language-server') > 0 then lspconfig.sumneko_lua.setup({ settings = { Lua = { runtime = { version = 'LuaJIT', }, diagnostics = { globals = { 'vim' }, }, workspace = { library = vim.api.nvim_get_runtime_file('', true), }, telemetry = { enable = false, }, completion = { -- complete full function signature callSnippet = 'Replace', }, }, }, on_attach = on_attach, capabilities = capabilities }) end if vim.fn.executable('pylsp') > 0 then lspconfig.pylsp.setup({ settings = { pylsp = { } }, on_attach = on_attach, capabilities = capabilities }) end if vim.fn.executable('lemminx') > 0 then lspconfig.lemminx.setup({ filetypes = { 'xml', 'xsd', 'xsl', 'xslt', 'svg', 'gentoo-metadata' }, on_attach = on_attach, capabilities = capabilities }) end if vim.fn.executable('vscode-html-language-server') > 0 then lspconfig.html.setup({ on_attach = on_attach, capabilities = capabilities }) end if vim.fn.executable('vscode-css-language-server') > 0 then lspconfig.cssls.setup({ on_attach = on_attach, capabilities = capabilities }) end if vim.fn.executable('vscode-eslint-language-server') > 0 then lspconfig.eslint.setup({ on_attach = on_attach, capabilities = capabilities }) end if vim.fn.executable('vscode-json-language-server') > 0 then lspconfig.jsonls.setup({ on_attach = on_attach, capabilities = capabilities }) end if vim.fn.executable('rust_analyzer') > 0 then lspconfig.rust_analyzer.setup({ on_attach = on_attach, capabilities = capabilities }) end if vim.fn.executable('gopls') > 0 then lspconfig.gopls.setup({ on_attach = on_attach, capabilities = capabilities }) end -- binary probably doesn't exist even when installed if vim.fn.executable('perlls') > 0 then lspconfig.perlls.setup({ on_attach = on_attach, capabilities = capabilities }) end require('lsp-format').setup({ sync = true -- seems to be needed to not interfere with Neogit })