takafumi blog

日々の勉強メモ

【Rust】【Vim】LSPの導入

  • 環境
    • archlinux 5.0.9-arch1-1-ARCH
    • rust 1.34.1
    • neovim 0.3.5

rust

rls(Rust Language Server)

https://github.com/rust-lang/rls

rustup component add rls
rustup component add rust-analysis
rustup component add rust-src

neovim

dein + LanguageClient-neovim

https://github.com/autozimu/LanguageClient-neovim

"
" lsp.toml
"
[[plugins]]
repo        = 'autozimu/LanguageClient-neovim'
rev         = 'next'
build       = 'bash install.sh'
hook_add = '''
   let g:LanguageClient_autoStart = 1  " LanguageServerを自動起動する

   " 言語毎のLSPを設定
   let g:LanguageClient_serverCommands = {
      \ 'rust': ['rustup', 'run', 'stable', 'rls'],
   \ }

   augroup LanguageClient_config
      autocmd!
      autocmd User LanguageClientStarted setlocal signcolumn=yes
      autocmd User LanguageClientStopped setlocal signcolumn=auto
   augroup END

   nnoremap [lsp] <Nop>
   nmap <Space>l [lsp]

   nnoremap [lsp]h :call LanguageClient_textDocument_hover()<CR>
   nnoremap [lsp]d :call LanguageClient_textDocument_definition()<CR>
   nnoremap [lsp]r :call LanguageClient_textDocument_rename()<CR>
   nnoremap [lsp]f :call LanguageClient_textDocument_formatting()<CR>
   '''

init.vimなどで以下のコマンドで読み込ませる

call dein#load_toml(s:toml_dir . '/lsp.toml', {'lazy': 0})

遅延読み込み('lazy':1)だとLanguageServerが起動ないので注意(大分長い事嵌った)