From 0d22a4b855bf1d772a1db1a26b6af4b7898cb942 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Thu, 11 Nov 2021 21:17:01 +0100 Subject: nvim: switch from CoC to built-in LSP Just for testing for now, to see how it performs. --- neovim/.config/nvim/init.vim | 170 ++++++++++++++++++++++--------------------- 1 file changed, 88 insertions(+), 82 deletions(-) (limited to 'neovim') diff --git a/neovim/.config/nvim/init.vim b/neovim/.config/nvim/init.vim index 93066ff..3ee0203 100644 --- a/neovim/.config/nvim/init.vim +++ b/neovim/.config/nvim/init.vim @@ -82,83 +82,11 @@ Plug 'fisadev/FixedTaskList.vim' " from this plugin is disabled "Plug 'davidhalter/jedi-vim' -Plug 'neoclide/coc.nvim', {'branch': 'release'} -" Use tab for trigger completion with characters ahead and navigate. -" NOTE: Use command ':verbose imap ' to make sure tab is not mapped by -" other plugin before putting this into your config. -inoremap - \ pumvisible() ? "\" : - \ check_back_space() ? "\" : - \ coc#refresh() -inoremap pumvisible() ? "\" : "\" - -function! s:check_back_space() abort - let col = col('.') - 1 - return !col || getline('.')[col - 1] =~# '\s' -endfunction - -" Use to trigger completion. -inoremap coc#refresh() - -" Use to confirm completion, `u` means break undo chain at current -" position. Coc only does snippet and additional edit on confirm. -if has('patch8.1.1068') - " Use `complete_info` if your (Neo)Vim version supports it. - inoremap complete_info()["selected"] != "-1" ? "\" : "\u\" -else - imap pumvisible() ? "\" : "\u\" -endif +Plug 'neovim/nvim-lspconfig' -" Use `[g` and `]g` to navigate diagnostics -nmap [g (coc-diagnostic-prev) -nmap ]g (coc-diagnostic-next) - -" GoTo code navigation. -nmap gd (coc-definition) -nmap gy (coc-type-definition) -nmap gi (coc-implementation) -nmap gr (coc-references) - -" Use K to show documentation in preview window. -nnoremap K :call show_documentation() - -function! s:show_documentation() - if (index(['vim','help'], &filetype) >= 0) - execute 'h '.expand('') - else - call CocAction('doHover') - endif -endfunction +Plug 'simrat39/symbols-outline.nvim' -" Highlight the symbol and its references when holding the cursor. -autocmd CursorHold * silent call CocActionAsync('highlight') - -" Symbol renaming. -nmap rn (coc-rename) - -" Formatting selected code. -xmap f (coc-format-selected) -nmap f (coc-format-selected) -" Add `:Format` command to format current buffer. -command! -nargs=0 Format :call CocAction('format') -" Mappings using CoCList: -" Show all diagnostics. -nnoremap a :CocList diagnostics -" Manage extensions. -nnoremap e :CocList extensions -" Show commands. -nnoremap c :CocList commands -" Find symbol of current document. -nnoremap o :CocList outline -" Search workspace symbols. -nnoremap s :CocList -I symbols -" Do default action for next item. -nnoremap j :CocNext -" Do default action for previous item. -nnoremap k :CocPrev -" Resume latest coc list. -nnoremap p :CocListResume -" -- END COC SETUP -- +Plug 'nvim-lua/lsp-status.nvim' " Automatically close parenthesis, etc "Plug 'Townk/vim-autoclose' @@ -222,6 +150,89 @@ Plug 'rust-lang/rust.vim' " Tell vim-plug we finished declaring plugins, so it can load them call plug#end() +lua << EOF +local lsp_status = require('lsp-status') +local kind_labels_mt = {__index = function(_, k) return k end} +local kind_labels = {} +setmetatable(kind_labels, kind_labels_mt) + +lsp_status.register_progress() +lsp_status.config({ + kind_labels = kind_labels, + indicator_errors = "×", + indicator_warnings = "!", + indicator_info = "i", + indicator_hint = "›", + -- the default is a wide codepoint which breaks absolute and relative + -- line counts if placed before airline's Z section + status_symbol = "", +}) + +local nvim_lsp = require('lspconfig') + +-- 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) + local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end + local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end + + -- Enable completion triggered by + buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') + + -- Mappings. + local opts = { noremap=true, silent=true } + + buf_set_keymap('i', '', '', opts) + + -- See `:help vim.lsp.*` for documentation on any of the below functions + buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) + buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) + buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) + buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) + buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) + buf_set_keymap('n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) + buf_set_keymap('n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) + buf_set_keymap('n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) + buf_set_keymap('n', 'gy', 'lua vim.lsp.buf.type_definition()', opts) + buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) + buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) + buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) + buf_set_keymap('n', 'e', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts) + buf_set_keymap('n', '[d', 'lua vim.lsp.diagnostic.goto_prev()', opts) + buf_set_keymap('n', ']d', 'lua vim.lsp.diagnostic.goto_next()', opts) + buf_set_keymap('n', 'q', 'lua vim.lsp.diagnostic.set_loclist()', opts) + buf_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', opts) + + lsp_status.on_attach(client) +end + +-- Use a loop to conveniently call 'setup' on multiple servers and +-- map buffer local keybindings when the language server attaches +local servers = { 'clangd', 'hls', 'rust_analyzer' } +for _, lsp in ipairs(servers) do + nvim_lsp[lsp].setup { + on_attach = on_attach, + flags = { + debounce_text_changes = 150, + }, + capabilities = lsp_status.capabilities + } +end + +EOF + +nmap s :SymbolsOutline +nmap :SymbolsOutline + +function! LspStatus() abort + return trim(luaeval("require('lsp-status').status()")) +endfunction +call airline#parts#define_function('lsp_status', 'LspStatus') +call airline#parts#define_condition('lsp_status', 'luaeval("#vim.lsp.buf_get_clients() > 0")') +let g:airline#extensions#nvimlsp#enabled = 0 +let g:airline_section_warning = airline#section#create_right(['lsp_status']) + + " ============================================================================ " Install plugins the first time vim runs @@ -279,13 +290,6 @@ autocmd BufWritePre *.py :%s/\s\+$//e " Plugins settings and mappings " Edit them as you wish. -" Tagbar ----------------------------- - -" toggle tagbar display -map :TagbarToggle -" autofocus on tagbar open -let g:tagbar_autofocus = 1 - " NERDTree ----------------------------- " toggle nerdtree display @@ -393,6 +397,8 @@ let g:airline#extensions#whitespace#enabled = 0 "let g:airline_symbols.readonly = '⭤' "let g:airline_symbols.linenr = '⭡' +let g:vimtex_view_method = 'zathura' + set clipboard=unnamedplus inccommand=nosplit set mouse=a let g:tex_flavor = "latex" -- cgit v1.2.3