本文へスキップ

Vim

Flowのエディタ統合は主にLanguage Server Protocolを介して行われます。多くのVim LSPクライアントから選択できます。例えばALEなどがあります。

ALE

Vim 8+およびNeovim用のAsynchronous Lint Engine (ALE)プラグイン、vim-aleは、Flowと多くの他のツールをサポートする汎用的なリンティングエンジンです。

インストール

ALEのREADMEにある手順に従ってください。

JavaScriptファイルに対してflow-language-serverリンターを使用するようにALEを設定します。

" In ~/.vim/ftplugin/javascript.vim, or somewhere similar.

" Enables only Flow for JavaScript. See :ALEInfo for a list of other available
" linters. NOTE: the `flow` linter uses an old API; prefer `flow-language-server`.
let b:ale_linters = ['flow-language-server']

" Or in ~/.vim/vimrc:
let g:ale_linters = {
\ 'javascript': ['flow-language-server'],
\}

coc.nvim-neovim

Cocは、vim8とneovim用のインテリセンスエンジンです。

設定

set nocompatible
filetype off

" install coc.nvim using Plug or preffered plugin manager
call plug#begin('~/.vim/plugged')
Plug 'neoclide/coc.nvim', {'branch': 'release'}
call plug#end()

filetype plugin indent on

" ======= coc settings
set updatetime=300
set shortmess+=c

" Use leader T to show documentation in preview window
nnoremap <leader>t :call <SID>show_documentation()<CR>


function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('&lt;cword&gt;')
else
call CocAction('doHover')
endif
endfunction

" instead of having ~/.vim/coc-settings.json
let s:LSP_CONFIG = {
\ 'flow': {
\ 'command': exepath('flow'),
\ 'args': ['lsp'],
\ 'filetypes': ['javascript', 'javascriptreact'],
\ 'initializationOptions': {},
\ 'requireRootPattern': 1,
\ 'settings': {},
\ 'rootPatterns': ['.flowconfig']
\ }
\}

let s:languageservers = {}
for [lsp, config] in items(s:LSP_CONFIG)
let s:not_empty_cmd = !empty(get(config, 'command'))
if s:not_empty_cmd | let s:languageservers[lsp] = config | endif
endfor

if !empty(s:languageservers)
call coc#config('languageserver', s:languageservers)
endif

LanguageClient-neovim

VimでFlowをサポートするもう一つの方法は、LanguageClient-neovimを使用することです。

  • Vim 8とneovimをサポート
  • omnifuncに補完を追加
  • 保存時にJavaScriptファイルの型エラーをチェック
  • カーソル下の型の参照

必要条件

  • Flowがインストールされ、パス上に存在する必要があります。
  • JavaScriptファイルを含むプロジェクトは、flow initで初期化する必要があります。
  • JavaScriptファイルの先頭に`/* @flow */`でマークする必要があります。

Pathogen

cd ~/.vim/bundle
git clone git://github.com/autozimu/LanguageClient-neovim.git

NeoBundle

これをあなたの~/.vimrcに追加してください。

  NeoBundleLazy 'autozimu/LanguageClient-neovim', {
\ 'autoload': {
\ 'filetypes': 'javascript'
\ }}

Flowビルドステップを使用し、flow-binを使用

  NeoBundleLazy 'autozimu/LanguageClient-neovim', {
\ 'autoload': {
\ 'filetypes': 'javascript'
\ },
\ 'build': {
\ 'mac': 'npm install -g flow-bin',
\ 'unix': 'npm install -g flow-bin'
\ }}

VimPlug

  Plug 'autozimu/LanguageClient-neovim', {
\ 'branch': 'next',
\ 'do': 'bash install.sh && npm install -g flow-bin',
\ }

設定

let g:LanguageClient_rootMarkers = {
\ 'javascript': ['.flowconfig', 'package.json']
\ }
let g:LanguageClient_serverCommands={
\ 'javascript': ['flow', 'lsp'],
\ 'javascript.jsx': ['flow', 'lsp']
\}

" check the type under cursor w/ leader T
nnoremap <leader>t :call LanguageClient_textDocument_hover()<CR>
nnoremap <leader>y :call LanguageClient_textDocument_definition()<CR>