From 6a51d7688129bde0cfe146bb2c300410b61f8a29 Mon Sep 17 00:00:00 2001 From: ViViDboarder Date: Thu, 24 Oct 2019 12:40:10 -0700 Subject: [PATCH] WIP: Switch to ALE with a few LS setup --- install-language-servers.sh | 47 +++++++++++++++++ vim/rc/input.rc.vim | 13 +++-- vim/rc/plugins.rc.vim | 81 +++++++++++++++++++++++------- vim/rc/plugins/tagbar.rc.vim | 1 - vim/rc/plugins/tcomment_vim.rc.vim | 3 -- 5 files changed, 119 insertions(+), 26 deletions(-) create mode 100755 install-language-servers.sh diff --git a/install-language-servers.sh b/install-language-servers.sh new file mode 100755 index 0000000..7ef6dce --- /dev/null +++ b/install-language-servers.sh @@ -0,0 +1,47 @@ +#! /bin/bash + +## Language servers + +# bash +npm install -g bash-language-server + +# Kotlin +# https://github.com/fwcd/kotlin-language-server/blob/master/BUILDING.md + +# Python +pip install --user python-language-server +pip3 install --user python-language-server + +# Rust +rustup component add rls rust-analysis rust-src + +## Linters + +# Python +pip install flake8 mypy + +# CSS +npm install -g csslint + +# Vim +pip install --user vim-vint +pip3 install --user vim-vint + +# YAML +pip install --user yamllint +pip3 install --user yamllint + +# Makefile +# https://github.com/mrtazz/checkmake + +## Fixers + +# CSS/JS/HTML/JSON/YAML/Markdown/and more! +npm install -g prettier + +# Python +pip install --user black autopep8 reorder-python-imports +pip3 install --user black autopep8 reorder-python-imports + +# Rust +rustup component add rustfmt diff --git a/vim/rc/input.rc.vim b/vim/rc/input.rc.vim index 881d692..caebdf9 100644 --- a/vim/rc/input.rc.vim +++ b/vim/rc/input.rc.vim @@ -34,9 +34,16 @@ cmap cd. lcd %:p:h " Bind Make to F5 like other IDEs nnoremap :make -" Remap Ctrl+Space for auto Complete -inoremap -inoremap +" Ctrl-Space for omnicompletions +inoremap pumvisible() \|\| &omnifunc == '' ? + \ "\C-n>" : + \ "\C-x>\C-o>=pumvisible() ?" . + \ "\"\\c-n>\\c-p>\\c-n>\" :" . + \ "\" \\bs>\\C-n>\"\" +imap +augroup close_docs + autocmd! CompleteDone * if pumvisible() == 0 | pclose | endif +augroup end " Toggle highlighting with \hr (highlight row) nnoremap hr :set cursorline! diff --git a/vim/rc/plugins.rc.vim b/vim/rc/plugins.rc.vim index 7a00ba2..72c9010 100644 --- a/vim/rc/plugins.rc.vim +++ b/vim/rc/plugins.rc.vim @@ -33,36 +33,79 @@ endif " }} Searching " Programming {{ +Plug 'FooSoft/vim-argwrap' -" TODO: Maybe replace with coc.nvim. If I'm doing a lot of development, I will -" have latest versions of vim or nvim -" Only need one fallback, maybe neocomplcache -call s:smart_source_rc('plugins/omnicompletion') -if !g:vim_as_an_ide || g:gui.has_autocomplete_features - " We'll keep Oni's autocomplete with Language Server -elseif (has('nvim') || v:version >= 800) && has('python3') - call s:smart_source_rc('plugins/deoplete') -else - call s:smart_source_rc('plugins/neocomplcache') +Plug 'tomtom/tcomment_vim', { 'on': ['TComment', 'TCommentBlock'] } +nnoremap // :TComment +vnoremap // :TCommentBlock + +" Install ALE +if !g:vim_as_an_ide || g:gui.has_linter_features + " We'll keep skip adding any of these features +elseif has('nvim') || v:version >= 800 + Plug 'dense-analysis/ale' + set omnifunc=ale#completion#OmniFunc + let g:airline#extensions#ale#enabled = 1 + let g:ale_lint_on_enter = 0 + + " TODO: Maybe move this to something per language + " TODO: Handle installing of language servers on setup (see ./install-language-servers.sh) + " NOTE: Some of these are installed when bootstrapping environment, + " outside of vim setup + let g:ale_linters = { + \ 'python': ['pyls', 'flake8', 'mypy', 'pylint'], + \ 'go': ['gopls', 'golint', 'gometalinter'], + \ 'rust': ['rls', 'cargo'], + \ 'sh': ['language_server', 'shell', 'shellcheck'], + \} + let g:ale_fixers = { + \ 'go': ['gofmt', 'goimports'], + \ 'rust': ['rustfmt'], + \} + + " Auto-complete from ALE, possible alternative to asyncomplete + " let g:ale_completion_enabled = 1 + + " Enable asyncomplete + Plug 'prabirshrestha/asyncomplete.vim' + " Add ALE to asyncomplete + augroup acomp_setup + au User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#ale#get_source_options({ + \ 'priority': 10, + \ })) + augroup end + + " let g:asyncomplete_auto_popup = 0 + " Make asyncomplete manually triggered + function! s:check_back_space() abort + let col = col('.') - 1 + return !col || getline('.')[col - 1] =~? '\s' + endfunction + + inoremap + \ pumvisible() ? "\" : + \ check_back_space() ? "\" : + \ asyncomplete#force_refresh() end -call s:smart_source_rc('plugins/tcomment_vim') +" TODO: Figure out if this is needed or if the ale completions are sufficient +" call s:smart_source_rc('plugins/omnicompletion') if g:vim_as_an_ide && (v:version > 703) && !g:gui.has_ctags_features call s:smart_source_rc('plugins/tagbar') Plug 'ludovicchabant/vim-gutentags' " Auto generate tags files - command! TagsUpdate :GutentagsUpdate + command! TagsUpdate :GutentagsUpdate end " TODO: Maybe ALE. Similar reason as coc.nvim. Probably only using latest vim " if developing seriously -if !g:vim_as_an_ide - " Do nothing -elseif (has('nvim') || v:version >= 800) - call s:smart_source_rc('plugins/neomake') -else - call s:smart_source_rc('plugins/syntastic') -endif +" if !g:vim_as_an_ide || g:ale_completion_enabled +" " Do nothing +" elseif (has('nvim') || v:version >= 800) +" call s:smart_source_rc('plugins/neomake') +" else +" call s:smart_source_rc('plugins/syntastic') +" endif " }} " GUI {{ diff --git a/vim/rc/plugins/tagbar.rc.vim b/vim/rc/plugins/tagbar.rc.vim index 77ab60d..75fd1dd 100644 --- a/vim/rc/plugins/tagbar.rc.vim +++ b/vim/rc/plugins/tagbar.rc.vim @@ -1,4 +1,3 @@ Plug 'majutsushi/tagbar', { 'on': 'TagbarToggle' } nnoremap :TagbarToggle let g:tagbar_autofocus = 1 " Autofocus tagbar - diff --git a/vim/rc/plugins/tcomment_vim.rc.vim b/vim/rc/plugins/tcomment_vim.rc.vim index cb128b8..e69de29 100644 --- a/vim/rc/plugins/tcomment_vim.rc.vim +++ b/vim/rc/plugins/tcomment_vim.rc.vim @@ -1,3 +0,0 @@ -Plug 'tomtom/tcomment_vim', { 'on': ['TComment', 'TCommentBlock'] } -nnoremap // :TComment -vnoremap // :TCommentBlock