VIM语言客户端和ALE互操作/重叠

时间:2019-02-14 19:02:10

标签: vim reason

我是VIM用户,最近开始使用Reason for React开发人员。我将ALE和LanguageClient用于不同的语言,即:

autozimu / LanguageClient-neovim

  • 铁锈
  • ocaml
  • 原因

w0rp / ale

  • python
  • javascript
  • 原因

请注意与Reason重叠。

我似乎在这个奇怪的地方,在这里我使用了每种功能的一半。具体地说,ALE正在运行refmt来格式化代码,但它没有执行棉绒。 LanguageClient正在执行linting。我已经通过注释掉ALE中的refmt(中断格式)并注释掉LanguageClient行的原因(中断棉絮)来确认这一点。我更喜欢ALE而不是LanguageClient,因为它使用quickfix(:lopen查看所有问题)并在退出插入模式时进行异步错误检查。我现在似乎在这两个插件之间都具有冗余功能,这使我的内部完美主义者感到烦恼。

问题:

  1. 同时拥有这两个插件是否有意义,或者功能在ALE和LanguageClient之间完全重复?
  2. 为什么棉绒在ALE中不起作用?可以使用其他所有语言,并且OLS在我的:ALEInfo中显示为有效选项。

.vimrc ...

有想法吗?

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" General NVIM
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

if has("nvim")
  let g:python_host_prog = '/Users/nathan/.pyenv/versions/neovim2/bin/python'
  let g:python3_host_prog = '/Users/nathan/.pyenv/versions/neovim3/bin/python'
endif

if has("nvim") || (v:version > 8)
  set termguicolors
  set guicursor=a:blinkon0
endif

colorscheme dark


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugins
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
filetype off
call plug#begin('~/.vim/plugged')

" Linting
Plug 'w0rp/ale'
Plug 'autozimu/LanguageClient-neovim', {
      \ 'branch': 'next',
      \ 'do': 'bash install.sh',
      \ }

" Completion
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' } 
Plug 'Shougo/neco-syntax'
Plug 'wokalski/autocomplete-flow', { 'for': 'javascript' }
Plug 'carlitux/deoplete-ternjs', { 'do': 'npm install -g tern', 'for': 'javascript'  }
Plug 'Shougo/neosnippet'
Plug 'zchee/deoplete-jedi'
Plug 'Shougo/neosnippet-snippets'


" General
Plug 'chriskempson/base16-vim' "Color Scheme
Plug 'ctrlpvim/ctrlp.vim' "Fuzzy Find
Plug 'dkprice/vim-easygrep' "Instant grep across files
Plug 'easymotion/vim-easymotion' "Fast movement
Plug 'jeetsukumaran/vim-buffergator' "Buffer management
Plug 'jiangmiao/auto-pairs' "Close pairs
Plug 'scrooloose/nerdtree', { 'on':  'NERDTreeToggle'  } "NerdTree
Plug 'tpope/vim-commentary' "File-specific commenting
Plug 'tpope/vim-surround' "Handle surrounds
Plug 'vim-airline/vim-airline' "Airline bar
Plug 'vim-airline/vim-airline-themes' "Make airline pretty
Plug '/usr/local/opt/fzf' | Plug 'junegunn/fzf.vim' "Fuzzy finder
" Plug 'vim-scripts/paredit.vim', {'for': 'clojure'} "Lisp balance

" Javascript - need to be in order
Plug 'pangloss/vim-javascript', {'for': ['javascript', 'reason']}
Plug 'reasonml-editor/vim-reason-plus', {'for': ['reason']}
Plug 'mxw/vim-jsx', {'for': ['javascript', 'reason']}
Plug 'alvan/vim-closetag', {'for': ['html', 'vue', 'javascript', 'reason']}

" Filetype Plugins
Plug 'fatih/vim-go', {'for': 'go'}
Plug 'hdima/python-syntax', {'for': 'python'}
Plug 'jparise/vim-graphql', {'for': 'graphql'}
Plug 'neovimhaskell/haskell-vim', {'for': 'haskell'}
Plug 'rust-lang/rust.vim', {'for': 'rust'}
" Plug 'derekwyatt/vim-scala', {'for': 'scala'}
" Plug 'elixir-lang/vim-elixir', {'for': 'elixir'}
" Plug 'keith/swift.vim', {'for': 'swift'}
" Plug 'udalov/kotlin-vim', {'for': 'kotlin'}
" Plug 'guns/vim-clojure-static', {'for': 'clojure'}


call plug#end()
filetype plugin indent on
syntax on
" END Plug


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" General settings
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

set autoindent "Enable automatic indentation
set backspace=indent,eol,start "Adaptive backspace
set cb=unnamed "Use global clipboard
set cc=0 "Color column (off by default, 80 for python, etc)
set copyindent "Copy indentation
set expandtab "Use spaces for tabs 
set hlsearch "Highlight search
set ignorecase "Case insensitive search
set laststatus=2 "Always show airline
set mouse=a "Respond to mouse
set noerrorbells "Don't beep
set nostartofline "Keep cursor in place when switching buffers
set novisualbell "No annoying flashing
set ruler "Adds line numbers and distance to airline
set shiftround "Tab half-indented to the next tabstop
set shiftwidth=2 "Default indentation
set shortmess+=c "Avoid unnecessary messages
set sidescrolloff=0 "Don't scroll horizontally
set smartcase "Use case in search if caps is used
set smarttab "Use semantic tabs
set softtabstop=2 "Pretend spaces are tabs
set t_vb= "Disable visual bell
set tabstop=2 "Default tab width
set vb "Disable visual bell
set wildignore=.DS_Store,node_modules,bower_components "Ignore for CtrlP
set wrap "Wrap long lines


set backupcopy=yes " Fix for bucklescript

" Fix some shiftwidths
autocmd Filetype haskell set shiftwidth=4
autocmd Filetype go set shiftwidth=4


"Variables
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Ale (linting and error checking)
let g:ale_javascript_eslint_executable = 'eslint_d' "Faster implementation
let g:ale_lint_on_text_changed="normal" "Lint on normal mode
let g:ale_reason_ols_executable = '/usr/local/bin/reason-language-server'
let g:ale_linters = {
      \ 'javascript': ['flow', 'eslint'],
      \ 'python': ['pyflakes'],
      \ 'reason': ['ols'],
      \}
let g:ale_fixers = {
      \ 'javascript': ['eslint', 'prettier'],
      \ 'reason': ['refmt'],
      \ 'python': ['autopep8'],
      \}
let g:ale_fix_on_save = 1

" Airline
let g:airline_theme='bubblegum'
let g:airline#extensions#ale#enabled = 1

" Buffergator
let g:buffergator_display_regime = "parentdir"
let g:buffergator_expand_on_split = 0

" vim-javascript conceal
let g:javascript_conceal_function = "ƒ"
let g:javascript_conceal_null = "ø"
let g:javascript_conceal_this = "@"
let g:javascript_conceal_return = "⇚"
let g:javascript_conceal_arrow_function = "⇒"

let g:closetag_filenames = "*.html,*.xhtml,*.phtml,*.js,*.jsx,*.re,*.xml,*.vue"
let g:haskell_indent_in = 0
let g:NERDTreeQuitOnOpen = 1
let g:jsx_ext_required = 0
let g:javascript_plugin_flow = 1

" Match Tag Always (close HTML tags)
let g:mta_filetypes = {
      \ 'html' : 1,
      \ 'xhtml' : 1,
      \ 'xml' : 1,
      \ 'jinja' : 1,
      \ 'javascript' : 1,
      \ 'reason' : 1,
      \ 'javascript.jsx' : 1,
      \}


let g:LanguageClient_serverCommands = {
      \ 'ocaml': ['ocaml-language-server', '--stdio'],
      \ 'rust': ['rustup', 'run', 'nightly', 'rls'],
      \ 'reason': ['/usr/local/bin/reason-language-server'],
      \ }
"'python': ['/usr/local/bin/pyls'],
"'javascript': ['javascript-typescript-stdio'],


" Use Platinum Searcher Grep, CtrlP, etc
if executable('pt')
  " Use pt over grep
  set grepprg=pt\ --nogroup\ --nocolor
  " Use pt in CtrlP for listing files. Lightning fast and respects .gitignore
  let g:ctrlp_user_command = 'pt %s -l --nocolor -g ""'
  " pt is fast enough that CtrlP doesn't need to cache
  let g:ctrlp_use_caching = 0
endif

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Keyboard mappings
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let mapleader = "\<Space>"

nnoremap <Leader>[ :BuffergatorMruCyclePrev<CR>
nnoremap <Leader>] :BuffergatorMruCycleNext<CR>
nnoremap <Leader>b :BuffergatorOpen<CR>
nnoremap <Leader>c :ALEToggle<CR>
nnoremap <Leader>d :NERDTreeToggle<CR>
nnoremap <Leader>f :Grep<space>
nnoremap <Leader>g :CtrlPBuffer<CR>
nnoremap <Leader>h :exec &conceallevel ? "set conceallevel=0" : "set conceallevel=1"<CR>
nnoremap <Leader>j :ALENextWrap<CR>
nnoremap <Leader>k :ALEPreviousWrap<CR>
nnoremap <Leader>o :CtrlP<CR>
"nnoremap <Leader>p "+p
nnoremap <Leader>q :q<CR>
nnoremap <Leader>r :ALEFix<CR>
nnoremap <Leader>s :w<CR>
nnoremap <Leader>w <C-W><C-W>
"vnoremap <Leader>y "+y

imap jk <Esc>


" Language Client
nnoremap <silent> K :call LanguageClient#textDocument_hover()<CR>
nnoremap <silent> gd :call LanguageClient#textDocument_definition()<CR>

" Autocomplete
let g:deoplete#enable_at_startup = 1
let g:neosnippet#enable_completed_snippet = 1
inoremap <expr><Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"



"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Fixes
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" https://github.com/jiangmiao/auto-pairs/issues/187
autocmd VimEnter,BufEnter,BufWinEnter * silent! iunmap <buffer> <M-">


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"GUI stuffs
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

if has("gui_vimr")
  nnoremap <D-S-}> :tabnext<CR>
  nnoremap <D-S-{> :tabprevious<CR>
endif


1 个答案:

答案 0 :(得分:1)

想通了。

.vimrc中的这一行不起作用:

let g:ale_reason_ols_executable = '/usr/local/bin/reason-language-server'

在ocaml-language-server要求的--stdio选项上使用ALE。原因语言服务器不接受此设置。它不仅被忽略,而且语言服务器根本不运行。我可以通过创建一个外壳脚本来调用忽略了额外参数的原因语言服务器来使其工作。本质上是这样:

#!/bin/bash
reason-language-server

有了这一更改,ALE现在可以正常掉毛了,并且我已经删除了多余的LanguageClient插件。据我所知,与推理语言服务器(或ocaml语言服务器)和LanguageClient进行交互的ALE提供了完全相同的信息。它们都提供语言服务器告诉他们的内容。我并不是要歪曲任何一个项目,但两个插件的细节和功能似乎是相同的-它们只是通过稍微不同的UI提供的。将锈转移到ALE之后,所有语言都应具有相同的UI,热键等。

任何一个开发人员都不会看到这种SO,这两个项目都很棒,并且我感谢使VIM成为有效,功能齐全的IDE的努力。