@@ -24,34 +24,53 @@ endif
24
24
if ! exists (" g:flow#qfsize" )
25
25
let g: flow #qfsize = 1
26
26
endif
27
- if ! exists (" g:flow#flowpath" )
28
- let g: flow #flowpath = " flow"
29
- endif
30
27
if ! exists (" g:flow#timeout" )
31
28
let g: flow #timeout = 2
32
29
endif
33
30
if ! exists (" g:flow#showquickfix" )
34
31
let g: flow #showquickfix = 1
35
32
endif
36
33
37
- " Require the flow executable.
38
- if ! executable (g: flow #flowpath)
39
- finish
40
- endif
41
-
42
34
" flow error format.
43
35
let s: flow_errorformat = ' %EFile "%f"\, line %l\, characters %c-%.%#,%Z%m,'
44
36
" flow from editor.
45
37
let s: flow_from = ' --from vim'
46
38
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
+
47
66
48
67
" Call wrapper for flow.
49
68
function ! <SID> FlowClientCall (cmd, suffix, ... )
50
69
" Invoke typechecker.
51
70
" We also concatenate with the empty string because otherwise
52
71
" cgetexpr complains about not having a String argument, even though
53
72
" 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
55
74
56
75
let flow_result = a: 0 > 0 ? system (command , a: 1 ) : system (command )
57
76
@@ -104,7 +123,7 @@ endfunction
104
123
function ! flow#get_type ()
105
124
let pos = line (' .' ).' ' .col (' .' )
106
125
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
108
127
let stdin = join (getline (1 ,' $' ), " \n " )
109
128
110
129
let output = ' FlowType: ' .system (cmd, stdin)
0 commit comments