neovim + coc.nvim 㧠LSP
TL;DR
- LSP (Language Server Protocol) ããµãã¼ããããã¼ã«ãå å®ãã¦ãã¦ãã
coc.nvim
ã使ã£ã¦ ã¾ã¨ãã¦åè¨èªã®è£å©æ©è½ã Language Server ã«ç§»è¡ãã- TypeScript 製ã§ãããã¨ã npm ã®å©ç¨ãªã©ï¼VSCode ã£ã½ããªã£ã¦é¢ç½ã
注
LanguageClient-neovim
使ã£ããã¨ããã¾ããvim-lsc
使ã£ããã¨ããã¾ããvim-lsp
使ã£ããã¨ããã¾ãã- VSCode 使ã£ããã¨ããã¾ãã
LSP ã¨ã¯
åè¨èªã®ï¼auto complete, goto def, find references, auto formatting, error checker ...
ï¼ ã®ãããªæ©è½ãã¾ã¨ãã¦æä¾ãããµã¼ãã¹ï¼= language serverï¼ã¨ãããå©ç¨ãããã¼ã«éã®ãããã³ã«ãå®ãããã®ã§ãï¼MS ãçºè¡¨ããã®ã確ã 2016å¹´é ã ã£ãã®ã§å²ã¨æããããã¾ãï¼
github.com
neovim ãã LSP ãå©ç¨ããã«ã¯
ã¾ã LSP Client ãå¿ è¦ï¼
neovim æ¬ä½ã§ã® LSP support ã«ã¤ãã¦
ä½è«ã ã neovim ã§ã¯ built-in 㧠LSP client ãæä¾ããè¨ç»ãããããã *1
- issue Language Server Implementation (LSP) · Issue #5522 · neovim/neovim · GitHub
- PR [RFC] Built-in LSP Support by tjdevries · Pull Request #6856 · neovim/neovim · GitHub
www.slideshare.net
ã©ã® LSP client ã使ãã
built-in ã® LSP Client ã®æä¾ã¯ã¾ã ã¾ã å
ãªã®ã§ï¼third party ã® LSP client ãé¸ã¶å¿
è¦ããã
www.reddit.com
Langserver.org ã§åLSP client ã®å¯¾å¿ç¶æ³ãè¦ã¦ã¿ã*2ï¼
æåã©ããã®
- GitHub - prabirshrestha/vim-lsp: async language server protocol plugin for vim and neovim
- GitHub - autozimu/LanguageClient-neovim: Language Server Protocol (LSP) support for vim and neovim.
- GitHub - w0rp/ale: Check syntax (linting) and fix files asynchronously, with Language Server Protocol (LSP) integration in Vim
- GitHub - neoclide/coc.nvim: Intellisense engine for vim8 & neovim, full language server protocol support as VSCode
ã¯ãããããã«ãã§ãã¯ãªã®ã§ï¼ã©ããé¸ãã§ãè¯ãããï¼æ¬å½ãï¼ï¼
LanguageClient-neovim
㯠Rust製ï¼coc.nvim
㯠TypeScript製ï¼vim-lsp
ALE
㯠VimScript 製ãªã®ã§ãã®è¾ºãã好ã¿ãåããããããããªãï¼
ALE
ALEã¯é«éãªéåæ linter ã ã¨æã£ã¦ããããã¤ã®éã«ã LSP integration ãæä¾ããããã«ãªã£ã¦ããï¼
GitHub - w0rp/ale: Check syntax (linting) and fix files asynchronously, with Language Server Protocol (LSP) integration in Vim
ALE acts as a "language client" to support a variety of Language Server Protocol features, including: Diagnostics (via Language Server Protocol linters) Go To Definition (:ALEGoToDefinition) Completion (let g:ale_completion_enabled = 1 before ALE is loaded) Finding references (:ALEFindReferences) Hover information (:ALEHover) Symbol search (:ALESymbolSearch)
å
ã
ALE ã使ã£ã¦ããã®ã§å
¨ã¦ããã§è³ããã°ä¾¿å©ãã¨æã£ããï¼æ¢åã® ale_linter
㨠ale_lsp_linter
ãä¸é¨ç«¶åãã¦ç
©ãããæããã*3ï¼é度é¢ã§ä¸æºãåºã¦ããã®ã§ ALE 㯠éLSPã®linterå°ç¨ã¨ãã¦ä½¿ããã¨ã«ãã*4ï¼
coc.nvim
å¾ã¯ vim-lsp
㨠coc.nvim
ã§æ©ãã ãï¼ç¾ç¶ coc
ãæãLSPã®æ©è½ãµãã¼ããå
å®ãã¦ãã
https://github.com/neoclide/coc.nvim/wiki/Language-servers#supported-features
ããã«è¦ããã¨ãããã¨ã¨ï¼TypeScript 製ãªã®ã§ä½ãå£ãã¦ã¦ãèªåã§ç´ãããã¨ããçç±ãã coc
ãé¸æããï¼*.nvim ã¨ä»ãã¦ã¾ãã Vimããã使ããããã *5
ãããæ¸ãã¦ãåæ¥ã®éã« GitHub Star ã500å¢ãã¦ã*6ã®ã§å±¥æ´ã調ã¹ãã¨ï¼ã©ããæè¿ææ°é¢æ°çã«ã¦ã¼ã¶ã¼æ°ãå¢ãã¦ããããã.
star-history ã§ã°ã©ããåã£ã¦ã¿ããï¼ä¸åº¦ããæ°æ¥ã§ coc ã language-client-neovim ãè¶
ãã¦ããï¼
nvim ã® floating window ããµãã¼ããã¦ãã¦ãã°ããï¼
F.A.Q · neoclide/coc.nvim Wiki · GitHub
vim-lsp
ä½è«ã ãï¼spacemacs 系㮠spacevim ã§ã¯ vim-lsp
ã®æ¹ãå梱ãã¦ããããã.
SpaceVim language server protocol layer | SpaceVim
coc.nvim ã® install
wiki ã®æ
å ±ãçµæ§ä¸è¶³ãã¦ãããã ã£ãã®ã§ï¼
coc.nvim/coc.txt at master · neoclide/coc.nvim · GitHub ãã½ã¼ã¹ãèªãã§ã¨ã¹ãã¼ãã*7
dependencies
node.js 㨠yarn ãå¿
è¦ã§ãï¼
Install coc.nvim · neoclide/coc.nvim Wiki · GitHub
dein
dein.vim ã使ã£ã¦ããã®ã§ toml ã§ã¤ã³ã¹ãã¼ã«ãã
[[plugins]] repo = 'neoclide/coc.nvim' build = './install.sh nightly' hook_add = 'source path/to/your/coc-setting.vim'
coc-setting.vim
ã«ã¤ãã¦ï¼ãã¼ããããªã©ã®è¨å®ã¯ä»¥ä¸ãåèã«ããã¨è¯ã
GitHub - neoclide/coc.nvim: Intellisense engine for vim8 & neovim, full language server protocol support as VSCode
status line 㯠lightline ã¨ã®é£æºæ¹æ³ãæä¾ããã¦ããï¼
GitHub - itchyny/lightline.vim: A light and configurable statusline/tabline plugin for Vim
validation
:CheckHealth
ããã°ï¼neovim ã®ä»ã®ç°å¢ã¨ä¸ç·ã« coc ã®ç¶æ
ã確èªã§ãã
ç¾ç¶ extension root ã®ãã£ã¬ã¯ããªã空ã 㨠coc ã® initialize ã«å¤±æãã¦ãã¾ãã®ã§ï¼$ mkdir -p ~/.config/coc/extensions
ãã¦ããå¿
è¦ããã.
[vim-node-coc]: Error on Initialize: ENOENT: no such file or directory, open .config/coc/memos.json
" dein/repos/github.com/neoclide/coc.nvim/autoload/coc/util.vim function! coc#util#extension_root() abort if s:is_win let dir = $HOME.'/AppData/Local/coc/extensions' else let dir = $HOME.'/.config/coc/extensions' endif return dir endfunction
coc settings
:CocConfig
ããã¨è¨å®ãã¡ã¤ã«ãéãã¾ã. ãã㯠nvim/coc-settings.json
ãããã«åºæ¥ã
Using configuration file · neoclide/coc.nvim Wiki · GitHub
:CocConfig Install coc-json for json intellisense ? [Y]es, [N]o:
coc ç¨ã® json extension ã空æ°ãèªãã§åæã«å
¥ãã¦ãããã®ã§æ¢ã«ä¾¿å©ã§ããï¼coc ç¨ config ã«ããã åå¤æ°ã®è£å®ããã¦ãããï¼
è¨å®ãã¡ã¤ã«ã®è©³ç´°ã«ä»ãã¦ã¯ wiki ã doc ãã½ã¼ã¹ãåç
§ãã¦æ¬²ãã.
coc extensions
Using coc extensions · neoclide/coc.nvim Wiki · GitHub
coc ã§ã¯ï¼æ§ã
㪠extension ã :CocInstall
ã§æ軽ã«å
¥ãããã¨ãåºæ¥ãï¼ããã¯ã¨ã³ãã§ã¯ yarn
ã使ã£ã¦ npm ã¢ã¸ã¥ã¼ã«ã ~/.config/coc/extensions/node_modules
ã«å
¥ãã¦ããæåã«ãªãï¼
:CocInstall coc-python coc-tsserver
:CocList extensions
ã§ç¾å¨ã¤ã³ã¹ãã¼ã«ããã¦ãããã©ã°ã¤ã³ã®ãªã¹ãã確èªã§ãã
extension ããªã language server ã¯
- ãã¡ããæ±ãã.
- Language servers · neoclide/coc.nvim Wiki · GitHub
C++
- clangd ã使ã£ã¦ã¿ã
- https://clang.llvm.org/extra/clangd/
$ brew install llvm $ echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.zshrc
:CocConfig
ã«è¨å®ã追å ãããã¨ã§å©ç¨ã§ãã
"languageserver": { "clangd": { "command": "clangd", "rootPatterns": ["compile_flags.txt", "compile_commands.json", ".vim/", ".git/", ".hg/"], "filetypes": ["c", "cpp", "objc", "objcpp"] } }
efm
æ¢åã®ãã¼ã«ã LSP対å¿ã«ãããã¼ã«ãæè¿å
¬éãããã°ããã§ï¼ããã使ãã¨ããªãæ軽ã«ãªã¬ãªã¬ language server ãèªä½ãããã¨ãã§ããï¼
Big Sky :: Lint ツールを Language Server に対応させるコマンド efm-langserver 作った。
efm-langserver で作る簡単 Language Server – dictav – Medium
é©ãããã¨ã« coc
ã® wiki ã§ã¯æ¢ã« efm-langserver
ããµãã¼ããã¦ããï¼ãããï¼
"languageserver": { "efm": { "command": "efm-langserver", "args": [], // custom config path // "args": ["-c", "/path/to/your/config.yaml"], "filetypes": ["vim", "eruby", "markdown"] } }
çµè«
- VSCode + nvim ãã¡ã¤ã³ã¨ãã£ã¿ã®äººã«ã¯
coc.nvim
ãé常ã«ãå§ãã§ããï¼VSCode使ã£ã¦ã¾ããï¼ - TypeScript + node + json ãªã®ã§ï¼VimLãè¦æã§ããããã°ãããã
- Vim Plugin ã®æ°ãããªãæ¸ããã
åè
*1:㨠vimconf.swp ã§èãã
*2:ãã®æç¹ã§ neovim å¤ããªã¨ããææ³ãæ±ã
*3:ale_linter ã surpress ããå¿ è¦ããã£ã
*4:ALE ã¯æ©è½ãå¢ãããããæ°ããã¦ãã¦ï¼1ã¤ã®ãã©ã°ã¤ã³ã¯ç´äº¤ããæ©è½ã追å ãã¹ãã§ãªã
*5:使ã£ããã¨ã¯ãªã. ç´ ã® vim 㯠RPC Client ãªãã®ã§ vim-node-lsp ãå¥éå ¥ããå¿ è¦ããããã
*6:Hacker News ã§ä¸ãã£ã¦ãããããã
*7:ts ã³ã¼ãã¯ããªã綺éºã§èªã¿ããã