1
1
let s: sock_type = (has (' win32' ) || has (' win64' )) ? ' tcp' : ' unix'
2
2
3
- function ! s: gocodeCommand (cmd, options , args ) abort
3
+ function ! s: gocodeCommand (cmd, args ) abort
4
4
let bin_path = go#path#CheckBinPath (" gocode" )
5
5
if empty (bin_path)
6
6
return []
@@ -10,21 +10,21 @@ function! s:gocodeCommand(cmd, options, args) abort
10
10
11
11
let cmd = [bin_path]
12
12
let cmd = extend (cmd, [' -sock' , socket_type])
13
- let cmd = extend (cmd, a: options )
13
+ let cmd = extend (cmd, [ ' -f ' , ' vim ' ] )
14
14
let cmd = extend (cmd, [a: cmd ])
15
15
let cmd = extend (cmd, a: args )
16
16
17
17
return cmd
18
18
endfunction
19
19
20
- function ! s: sync_gocode (cmd, options , args , input ) abort
20
+ function ! s: sync_gocode (cmd, args , input ) abort
21
21
" We might hit cache problems, as gocode doesn't handle different GOPATHs
22
22
" well. See: https://github.com/nsf/gocode/issues/239
23
23
let old_goroot = $GOROOT
24
24
let $GOROOT = go#util#env (" goroot" )
25
25
26
26
try
27
- let cmd = s: gocodeCommand (a: cmd , a: options , a: args )
27
+ let cmd = s: gocodeCommand (a: cmd , a: args )
28
28
" gocode can sometimes be slow, so redraw now to avoid waiting for gocode
29
29
" to return before redrawing automatically.
30
30
redraw
@@ -91,7 +91,6 @@ function! go#complete#Info(auto) abort
91
91
endif
92
92
endfunction
93
93
94
-
95
94
function ! s: async_info (auto)
96
95
if exists (" s:async_info_job" )
97
96
call job_stop (s: async_info_job )
@@ -135,38 +134,8 @@ function! s:async_info(auto)
135
134
return
136
135
endif
137
136
138
- " first line is: Charcount,,NumberOfCandidates, i.e: 8,,1
139
- " following lines are candiates, i.e: func foo(name string),,foo(
140
-
141
- " no candidates are found
142
- if len (self .messages ) == 1
143
- return s: info_complete (self .auto, " " )
144
- endif
145
-
146
- " only one candidate is found
147
- if len (self .messages ) == 2
148
- let result = split (self .messages [1 ], ' ,,' )[0 ]
149
- return s: info_complete (self .auto, result)
150
- endif
151
-
152
- " too many candidates are available, pick one that matches the word under
153
- " the cursor
154
- let infos = []
155
- for info in self .messages [1 :]
156
- call add (infos, split (info, ' ,,' )[0 ])
157
- endfor
158
-
159
- let wordMatch = ' \<' . expand (" <cword>" ) . ' \>'
160
- " escape single quotes in wordMatch before passing it to filter
161
- let wordMatch = substitute (wordMatch, " '" , " ''" , " g" )
162
- let filtered = filter (infos, " v:val =~ '" .wordMatch." '" )
163
-
164
- let result = " "
165
- if len (filtered) == 1
166
- let result = filtered[0 ]
167
- endif
168
-
169
- return s: info_complete (self .auto, result)
137
+ let result = s: info_filter (self .auto, join (self .messages , " \n " ))
138
+ call s: info_complete (self .auto, result)
170
139
endfunction
171
140
172
141
let offset = go#util#OffsetCursor ()+ 1
@@ -177,9 +146,7 @@ function! s:async_info(auto)
177
146
\ " GOROOT" : go#util#env (" goroot" )
178
147
\ }
179
148
180
- " TODO(bc): refactor to use `-f vim` instead of `-f=godit`.
181
149
let cmd = s: gocodeCommand (' autocomplete' ,
182
- \ [' -f=godit' ],
183
150
\ [expand (' %:p' ), offset])
184
151
185
152
" TODO(bc): Don't write the buffer to a file; pass the buffer directrly to
@@ -208,58 +175,53 @@ function! s:sync_info(auto)
208
175
" auto is true if we were called by g:go_auto_type_info's autocmd
209
176
let offset = go#util#OffsetCursor ()+ 1
210
177
211
- " TODO(bc): refactor to use `-f vim` instead of `-f=godit`.
212
178
let result = s: sync_gocode (' autocomplete' ,
213
- \ [' -f=godit ' ],
179
+ \ [' -f=vim ' ],
214
180
\ [expand (' %:p' ), offset],
215
181
\ go#util#GetLines ())
216
182
217
- " first line is: Charcount,,NumberOfCandidates, i.e: 8,,1
218
- " following lines are candiates, i.e: func foo(name string),,foo(
219
- let out = split (result, ' \n ' )
183
+ let result = s: info_filter ( a: auto , result)
184
+ call s: info_complete ( a: auto , result)
185
+ endfunction
220
186
221
- " no candidates are found
222
- if len (out) == 1
223
- return s: info_complete ( a: auto , " " )
187
+ function ! s: info_filter (auto, result) abort
188
+ if empty ( a: result )
189
+ return " "
224
190
endif
225
191
226
- " only one candidate is found
227
- if len (out) == 2
228
- let result = split (out[1 ], ' ,,' )[0 ]
229
- return s: info_complete (a: auto , result)
192
+ let l: result = eval (a: result )
193
+ if len (l: result ) != 2
194
+ return " "
230
195
endif
231
196
232
- " too many candidates are available, pick one that maches the word under the
233
- " cursor
234
- let infos = []
235
- for info in out[1 :]
236
- call add (infos, split (info, ' ,,' )[0 ])
237
- endfor
197
+ let l: candidates = l: result [1 ]
198
+ if len (l: candidates ) == 1
199
+ " When gocode panics in vim mode, it returns
200
+ " [0, [{'word': 'PANIC', 'abbr': 'PANIC PANIC PANIC', 'info': 'PANIC PANIC PANIC'}]]
201
+ if a: auto && l: candidates [0 ].info == # " PANIC PANIC PANIC"
202
+ return " "
203
+ endif
238
204
205
+ return l: candidates [0 ].info
206
+ endif
207
+
208
+ let filtered = []
239
209
let wordMatch = ' \<' . expand (" <cword>" ) . ' \>'
240
210
" escape single quotes in wordMatch before passing it to filter
241
211
let wordMatch = substitute (wordMatch, " '" , " ''" , " g" )
242
- let filtered = filter (infos , " v:val =~ '" .wordMatch." '" )
212
+ let filtered = filter (l: candidates , " v:val.info =~ '" .wordMatch." '" )
243
213
244
- let result = " "
245
- if len (filtered) == 1
246
- let result = filtered[0 ]
214
+ if len (l: filtered ) != 1
215
+ return " "
247
216
endif
248
217
249
- return s: info_complete ( a: auto , result)
218
+ return l: filtered [ 0 ].info
250
219
endfunction
251
220
252
221
function ! s: info_complete (auto, result) abort
253
222
if ! empty (a: result )
254
- " if auto, and the result is a PANIC by gocode, hide it
255
- if a: auto && a: result == # ' PANIC PANIC PANIC'
256
- return " "
257
- endif
258
-
259
223
echo " vim-go: " | echohl Function | echon a: result | echohl None
260
224
endif
261
-
262
- return a: result
263
225
endfunction
264
226
265
227
function ! s: trim_bracket (val) abort
@@ -282,7 +244,7 @@ function! go#complete#Complete(findstart, base) abort
282
244
283
245
return s: completions [1 ]
284
246
endif
285
- endf
247
+ endfunction
286
248
287
249
function ! go#complete#ToggleAutoTypeInfo () abort
288
250
if get (g: , " go_auto_type_info" , 0 )
@@ -295,5 +257,4 @@ function! go#complete#ToggleAutoTypeInfo() abort
295
257
call go#util#EchoProgress (" auto type info enabled" )
296
258
endfunction
297
259
298
-
299
260
" vim: sw = 2 ts = 2 et
0 commit comments