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

Commit a487fa6

Browse files
committed
fix: reload flow executable path before every call
1 parent 4acd33a commit a487fa6

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

after/ftplugin/javascript.vim

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
" Vim filetype plugin
22

33
" Require the flow executable.
4-
if !executable(g:flow#flowpath)
5-
finish
6-
endif
4+
call flow#SaveGetFlowExecutable()
75

86
" Omnicompletion.
97
if !exists("g:flow#omnifunc")

autoload/flowcomplete.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function! flowcomplete#Complete(findstart, base)
3434

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

4040
if result =~ '^Error: not enough type information to autocomplete' ||

plugin/flow.vim

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,53 @@ endif
2424
if !exists("g:flow#qfsize")
2525
let g:flow#qfsize = 1
2626
endif
27-
if !exists("g:flow#flowpath")
28-
let g:flow#flowpath = "flow"
29-
endif
3027
if !exists("g:flow#timeout")
3128
let g:flow#timeout = 2
3229
endif
3330
if !exists("g:flow#showquickfix")
3431
let g:flow#showquickfix = 1
3532
endif
3633

37-
" Require the flow executable.
38-
if !executable(g:flow#flowpath)
39-
finish
40-
endif
41-
4234
" flow error format.
4335
let s:flow_errorformat = '%EFile "%f"\, line %l\, characters %c-%.%#,%Z%m,'
4436
" flow from editor.
4537
let s:flow_from = '--from vim'
4638

39+
function! <SID>GetFlowExecutable()
40+
if exists("g:flow#flowpath")
41+
return g:flow#flowpath
42+
else
43+
" Search for a local version of flow
44+
let s:npm_local_flowpath = finddir("node_modules", ".;") . "/.bin/flow"
45+
if filereadable(s:npm_local_flowpath)
46+
return s:npm_local_flowpath
47+
else
48+
" fallback to global instance
49+
return "flow"
50+
endif
51+
endif
52+
endfunction
53+
54+
function! flow#SaveGetFlowExecutable()
55+
let a:flow_executable = <SID>GetFlowExecutable()
56+
if !executable(a:flow_executable)
57+
echohl WarningMsg
58+
echomsg 'No Flow executable found.'
59+
echohl None
60+
finish
61+
else
62+
return a:flow_executable
63+
endif
64+
endfunction
65+
4766

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

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

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

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

0 commit comments

Comments
 (0)