diff options
author | Daniel Schadt <kingdread@gmx.de> | 2021-11-11 21:17:01 +0100 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2021-11-11 21:17:01 +0100 |
commit | 0d22a4b855bf1d772a1db1a26b6af4b7898cb942 (patch) | |
tree | a675708c144662925832f9fde88e59ee1c13aec4 /neovim | |
parent | 3334c6a2ff90be7bb996ca62a0c9b4caaa576015 (diff) | |
download | dotfiles-0d22a4b855bf1d772a1db1a26b6af4b7898cb942.tar.gz dotfiles-0d22a4b855bf1d772a1db1a26b6af4b7898cb942.tar.bz2 dotfiles-0d22a4b855bf1d772a1db1a26b6af4b7898cb942.zip |
nvim: switch from CoC to built-in LSP
Just for testing for now, to see how it performs.
Diffstat (limited to 'neovim')
-rw-r--r-- | neovim/.config/nvim/init.vim | 170 |
1 files changed, 88 insertions, 82 deletions
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 <tab>' to make sure tab is not mapped by -" other plugin before putting this into your config. -inoremap <silent><expr> <TAB> - \ pumvisible() ? "\<C-n>" : - \ <SID>check_back_space() ? "\<TAB>" : - \ coc#refresh() -inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>" - -function! s:check_back_space() abort - let col = col('.') - 1 - return !col || getline('.')[col - 1] =~# '\s' -endfunction - -" Use <c-space> to trigger completion. -inoremap <silent><expr> <c-space> coc#refresh() - -" Use <cr> to confirm completion, `<C-g>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 <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>" -else - imap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>" -endif +Plug 'neovim/nvim-lspconfig' -" Use `[g` and `]g` to navigate diagnostics -nmap <silent> [g <Plug>(coc-diagnostic-prev) -nmap <silent> ]g <Plug>(coc-diagnostic-next) - -" GoTo code navigation. -nmap <silent> gd <Plug>(coc-definition) -nmap <silent> gy <Plug>(coc-type-definition) -nmap <silent> gi <Plug>(coc-implementation) -nmap <silent> gr <Plug>(coc-references) - -" Use K to show documentation in preview window. -nnoremap <silent> K :call <SID>show_documentation()<CR> - -function! s:show_documentation() - if (index(['vim','help'], &filetype) >= 0) - execute 'h '.expand('<cword>') - 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 <leader>rn <Plug>(coc-rename) - -" Formatting selected code. -xmap <leader>f <Plug>(coc-format-selected) -nmap <leader>f <Plug>(coc-format-selected) -" Add `:Format` command to format current buffer. -command! -nargs=0 Format :call CocAction('format') -" Mappings using CoCList: -" Show all diagnostics. -nnoremap <silent> <space>a :<C-u>CocList diagnostics<cr> -" Manage extensions. -nnoremap <silent> <space>e :<C-u>CocList extensions<cr> -" Show commands. -nnoremap <silent> <space>c :<C-u>CocList commands<cr> -" Find symbol of current document. -nnoremap <silent> <space>o :<C-u>CocList outline<cr> -" Search workspace symbols. -nnoremap <silent> <space>s :<C-u>CocList -I symbols<cr> -" Do default action for next item. -nnoremap <silent> <space>j :<C-u>CocNext<CR> -" Do default action for previous item. -nnoremap <silent> <space>k :<C-u>CocPrev<CR> -" Resume latest coc list. -nnoremap <silent> <space>p :<C-u>CocListResume<CR> -" -- 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 <c-x><c-o> + buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') + + -- Mappings. + local opts = { noremap=true, silent=true } + + buf_set_keymap('i', '<c-space>', '<c-x><c-o>', opts) + + -- See `:help vim.lsp.*` for documentation on any of the below functions + buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts) + buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts) + buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts) + buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts) + buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts) + buf_set_keymap('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts) + buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts) + buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts) + buf_set_keymap('n', 'gy', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts) + buf_set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts) + buf_set_keymap('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts) + buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts) + buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts) + buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts) + buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts) + buf_set_keymap('n', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts) + buf_set_keymap('n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', 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 <silent><space>s :SymbolsOutline<CR> +nmap <F4> :SymbolsOutline<CR> + +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 <F4> :TagbarToggle<CR> -" 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" |