Vim
Flow 的编辑器集成主要通过 语言服务器协议。有 许多 vim LSP 客户端 可供选择,如 ALE。
¥Flow's editor integration is primarily via the Language Server Protocol. There are many vim LSP clients to choose from, such as ALE.
ALE
适用于 Vim 8+ 和 NeoVim vim-ale 的异步 Lint 引擎 (ALE) 插件是一个通用的 lint 引擎,支持 Flow 和许多其他工具。
¥The Asynchronous Lint Engine (ALE) plugin for Vim 8+ and NeoVim, vim-ale, is a generalized linting engine with support for Flow and many other tools.
安装
¥Installation
请遵循 ALE 自述文件中的 指示。
¥Follow the instructions in the ALE README.
配置 ALE 以对 JavaScript 文件使用 flow-language-server
linter:
¥Configure ALE to use the flow-language-server
linter for JavaScript files:
" 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 的智能感知引擎。
¥Coc is an intellisense engine for vim8 & neovim.
设置
¥Setup
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('<cword>')
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
语言客户端-neovim
¥LanguageClient-neovim
在 Vim 中添加 Flow 支持的另一种方法是使用 语言客户端-neovim。
¥Another way to add support for Flow in Vim is to use LanguageClient-neovim.
支持 vim 8 和 neovim
¥Suports vim 8 and neovim
向 omnifunc 添加补全
¥Adds completions to omnifunc
保存时检查 JavaScript 文件是否存在类型错误
¥Checks JavaScript files for type errors on save
查找光标下的类型
¥Look up types under cursor
要求
¥Requirements
需要安装 Flow 并且在你的路径上可用。
¥Requires Flow to be installed and available on your path.
需要使用 flow init 初始化包含 JavaScript 文件的项目。
¥Requires projects containing JavaScript files to be initialised with flow init.
要求 JavaScript 文件在顶部标有 / @flow / 。
¥Requires JavaScript files to be marked with / @flow / at the top.
Pathogen
cd ~/.vim/bundle
git clone git://github.com/autozimu/LanguageClient-neovim.git
NeoBundle
将其添加到你的 ~/.vimrc
¥Add this to your ~/.vimrc
NeoBundleLazy 'autozimu/LanguageClient-neovim', {
\ 'autoload': {
\ 'filetypes': 'javascript'
\ }}
通过 Flow 构建步骤,使用 flow-bin
¥With Flow build step, using 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',
\ }
设置
¥Setup
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>