Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Commit

Permalink
fix: reload flow executable path before every call
Browse files Browse the repository at this point in the history
  • Loading branch information
halbgut committed Feb 18, 2018
1 parent 4acd33a commit a487fa6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
4 changes: 1 addition & 3 deletions after/ftplugin/javascript.vim
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
" Vim filetype plugin

" Require the flow executable.
if !executable(g:flow#flowpath)
finish
endif
call flow#SaveGetFlowExecutable()

" Omnicompletion.
if !exists("g:flow#omnifunc")
Expand Down
2 changes: 1 addition & 1 deletion autoload/flowcomplete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function! flowcomplete#Complete(findstart, base)

" Pass the buffer to flow.
let buffer = join(lines, "\n")
let command = g:flow#flowpath.' autocomplete "'.expand('%:p').'"'
let command = flow#SaveGetFlowExecutable().' autocomplete "'.expand('%:p').'"'
let result = system(command, buffer)

if result =~ '^Error: not enough type information to autocomplete' ||
Expand Down
39 changes: 29 additions & 10 deletions plugin/flow.vim
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,53 @@ endif
if !exists("g:flow#qfsize")
let g:flow#qfsize = 1
endif
if !exists("g:flow#flowpath")
let g:flow#flowpath = "flow"
endif
if !exists("g:flow#timeout")
let g:flow#timeout = 2
endif
if !exists("g:flow#showquickfix")
let g:flow#showquickfix = 1
endif

" Require the flow executable.
if !executable(g:flow#flowpath)
finish
endif

" flow error format.
let s:flow_errorformat = '%EFile "%f"\, line %l\, characters %c-%.%#,%Z%m,'
" flow from editor.
let s:flow_from = '--from vim'

function! <SID>GetFlowExecutable()
if exists("g:flow#flowpath")
return g:flow#flowpath
else
" Search for a local version of flow
let s:npm_local_flowpath = finddir("node_modules", ".;") . "/.bin/flow"
if filereadable(s:npm_local_flowpath)
return s:npm_local_flowpath
else
" fallback to global instance
return "flow"
endif
endif
endfunction

function! flow#SaveGetFlowExecutable()
let a:flow_executable = <SID>GetFlowExecutable()
if !executable(a:flow_executable)
echohl WarningMsg
echomsg 'No Flow executable found.'
echohl None
finish
else
return a:flow_executable
endif
endfunction


" Call wrapper for flow.
function! <SID>FlowClientCall(cmd, suffix, ...)
" Invoke typechecker.
" We also concatenate with the empty string because otherwise
" cgetexpr complains about not having a String argument, even though
" type(flow_result) == 1.
let command = g:flow#flowpath.' '.a:cmd.' '.s:flow_from.' '.a:suffix
let command = flow#SaveGetFlowExecutable().' '.a:cmd.' '.s:flow_from.' '.a:suffix

let flow_result = a:0 > 0 ? system(command, a:1) : system(command)

Expand Down Expand Up @@ -104,7 +123,7 @@ endfunction
function! flow#get_type()
let pos = line('.').' '.col('.')
let path = ' --path '.fnameescape(expand('%'))
let cmd = g:flow#flowpath.' type-at-pos '.pos.path
let cmd = flow#SaveGetFlowExecutable().' type-at-pos '.pos.path
let stdin = join(getline(1,'$'), "\n")

let output = 'FlowType: '.system(cmd, stdin)
Expand Down

0 comments on commit a487fa6

Please sign in to comment.