[Swift] vim-lspでswiftのコード補完をする

VimでSwiftをコーディングするにあたり、LSPでコード補完をするための設定メモです。
手順は以下の通りです。

  1. sourcekit-lspを入れる
  2. vimrcの設定

sourcekit-lspを入れる

  1. SwiftのLanguage Serverを入れる

最新版は、Swiftのバージョンをあげないとビルドできません。
Xcode11 (この時はβ版)をインストールします。

  1. githubから最新版をクローンしてインストール

    $ git clone https://github.com/apple/sourcekit-lsp.git
    $ cd sourcekit-lsp
    $ swift build
  2. sourcekit-lspにパスを通す

ビルドしたsourcekit-lspは以下の場所にできます。
パスが通った場所におくなり、リンクを貼って実行できるようにします。

.build/debug/sourcekit-lsp

vimrcの設定

  1. 以下のプラグインをインストール

    Plug 'prabirshrestha/asyncomplete.vim'
    Plug 'prabirshrestha/async.vim'
    Plug 'prabirshrestha/vim-lsp'
    Plug 'prabirshrestha/asyncomplete-lsp.vim'
    Plug 'ryanolsonx/vim-lsp-swift'
  2. vimrcに以下の設定を追加します。

    " vim-lsp-swift setting
    if executable('sourcekit-lsp')
     augroup swift_lsp_omnifunc
         autocmd!
         autocmd FileType swift setlocal omnifunc=lsp#complete
     augroup END
    endif

参考URL

0 件のコメント :

コメントを投稿