1. 程式人生 > 其它 >YouCompleteMe | 安裝過程記錄 2021

YouCompleteMe | 安裝過程記錄 2021

YCM

託管庫地址:https://github.com/ycm-core/YouCompleteMe
這裡有英文描述的安裝過程,分別對於:Win, Linux, BSD描述

以下是我的個人安裝過程

環境配置

確認下列環境已經安裝:

  • 工具:Git
  • 開發環境:MSVC(Visual Studio自帶), CMake, Python, Go, Node.JS
  • Vim外掛:vim-plug

注意:python版本是3,並且受所安裝Vim的支援
可通過:version檢視支援的版本,:echo has('python3') 檢視當前python環境是否可用於Vim。

安裝

在 _vimrc 中新增:

set encoding=utf-8

vim-plug載入外掛的區域中新增ycm外掛記錄:

call plug#begin('$VIM/vimfiles/plugged')
...
Plug 'ycm-core/YouCompleteMe'
...
call plug#end()

過載_vimrc::so %

執行::PlugInstall呼叫vim-plug安裝函式,開始從github克隆到本地

由於連線github經常斷線,手動到外掛目錄(vimfiles\plugged\YouCompleteMe)檢視狀態,提示我執行:
git submodule update --init --recursive

git報錯:

fatal: unable to access 'https://github.com/gorakhargosh/watchdog/': OpenSSL SSL_read: Connection was reset, errno 10054
Failed to clone 'third_party/watchdog_deps/watchdog'. Retry scheduled ...

由於眾所周知的原因,連線github的網路經常會被重置,多試幾次

斷續下載了一些檔案

到這個第三方模組時,重新嘗試一直報錯:

fatal: could not get a repository handle for submodule 'third_party/mrab-regex'
Failed to recurse into submodule path 'third_party/ycmd'

...
fatal: not a git repository: D:/Software/Vim/vimfiles/plugged/YouCompleteMe/third_party/ycmd/third_party/mrab-regex/../../../../.git/modules/third_party/ycmd/modules/third_party/mrab-regex
Failed to clone 'third_party/mrab-regex'. Retry scheduled

開啟YCM的倉庫一看,發現mrab-regex已經放到bitbucket託管了

進入ycmd/modules/third_party/mrab-regex目錄,在此執行:
git clone https://bitbucket.org/mrabarnett/mrab-regex.git

後續顯示:

Submodule path 'third_party/ycmd/third_party/mrab-regex': checked out 'fa9def53cf920ed9343a0afab54d5075d4c75394'
Submodule path 'third_party/ycmd/third_party/watchdog_deps/watchdog': checked out '5fbd4b689ab86cef21834d6359969bd57f20dab0'

應該就是這些模組已經克隆成功了

所有檔案克隆到本地後,進入外掛目錄(.../plugged/YouCompleteMe/)

先確認要補全的語言環境:
對應的指令碼執行引數:

  • C/C++(C-family): --clangd-completer
  • C#: --cs-completer
  • TypeScript/JS: --ts-completer

其他語言選項可進倉庫檢視官方說明

執行:python3 install.py [lang-option]

比如:安裝YCM同時安裝C系列語言的補全:python3 install.py --clangd-completer

自動下載安裝clangd:

Downloading Clangd from https://github.com/ycm-core/llvm/releases/download/12.0.0/clangd-12.0.0-win64.tar.bz2...
Extracting Clangd to D:\Software\Vim\vimfiles\plugged\YouCompleteMe\third_party\ycmd\third_party\clangd\output...
Done installing Clangd

此處的clangd是LLVM的分析後端程式,通過LSP(Language Server Protocol)與前端(編輯器外掛)通訊

安裝好後重新載入_vimrc配置就可使用了