diff --git a/autoload/go/complete.vim b/autoload/go/complete.vim index a5992c63ad..988a182c75 100644 --- a/autoload/go/complete.vim +++ b/autoload/go/complete.vim @@ -67,7 +67,7 @@ function! go#complete#GetInfo() abort endfunction function! go#complete#Info() abort - if go#util#has_job(1) + if go#util#has_job(1) || has('nvim') return s:async_info(1) else return s:sync_info(1) @@ -75,51 +75,27 @@ function! go#complete#Info() abort endfunction function! s:async_info(echo) - if exists("s:async_info_job") - call job_stop(s:async_info_job) - unlet s:async_info_job - endif - - let state = { - \ 'exited': 0, - \ 'exit_status': 0, - \ 'closed': 0, - \ 'messages': [], - \ 'echo': a:echo - \ } - - function! s:callback(chan, msg) dict - let l:msg = a:msg - if &encoding != 'utf-8' - let l:msg = iconv(l:msg, 'utf-8', &encoding) - endif - call add(self.messages, l:msg) - endfunction - - function! s:exit_cb(job, exitval) dict - let self.exit_status = a:exitval - let self.exited = 1 - - if self.closed - call self.complete() - endif - endfunction + let state = {'echo': a:echo} - function! s:close_cb(ch) dict - let self.closed = 1 - if self.exited - call self.complete() + function! s:complete(job, exit_status, messages) abort dict + if a:exit_status != 0 + return endif - endfunction - function state.complete() dict - if self.exit_status != 0 - return + if &encoding != 'utf-8' + let i = 0 + while i < len(a:messages) + let a:messages[i] = iconv(a:messages[i], 'utf-i', &encoding) + let i += 1 + endwhile endif - let result = s:info_filter(self.echo, join(self.messages, "\n")) + let result = s:info_filter(self.echo, join(a:messages, "\n")) call s:info_complete(self.echo, result) endfunction + " explicitly bind complete to state so that within it, self will + " always refer to state. See :help Partial for more information. + let state.complete = function('s:complete', [], state) " add 1 to the offset, so that the position at the cursor will be included " in gocode's search @@ -131,23 +107,28 @@ function! s:async_info(echo) \ "GOROOT": go#util#env("goroot") \ } + let opts = { + \ 'bang': 1, + \ 'complete': state.complete, + \ 'for': '_', + \ } + + let opts = go#job#Options(l:opts) + let cmd = s:gocodeCommand('autocomplete', \ [expand('%:p'), offset]) - " TODO(bc): Don't write the buffer to a file; pass the buffer directrly to + " TODO(bc): Don't write the buffer to a file; pass the buffer directly to " gocode's stdin. It shouldn't be necessary to use {in_io: 'file', in_name: " s:gocodeFile()}, but unfortunately {in_io: 'buffer', in_buf: bufnr('%')} - " should work. - let options = { + " doesn't work. + call extend(opts, { \ 'env': env, \ 'in_io': 'file', \ 'in_name': s:gocodeFile(), - \ 'callback': funcref("s:callback", [], state), - \ 'exit_cb': funcref("s:exit_cb", [], state), - \ 'close_cb': funcref("s:close_cb", [], state) - \ } + \ }) - let s:async_info_job = job_start(cmd, options) + call go#job#Start(cmd, opts) endfunction function! s:gocodeFile() diff --git a/autoload/go/def_test.vim b/autoload/go/def_test.vim index 5a8df6baaf..18e5608f67 100644 --- a/autoload/go/def_test.vim +++ b/autoload/go/def_test.vim @@ -45,7 +45,7 @@ func! Test_Jump_leaves_lists() abort call setqflist(copy(expected), 'r' ) let l:bufnr = bufnr('%') - call cursor(6, 3) + call cursor(6, 7) call go#def#Jump('') let start = reltime() diff --git a/autoload/go/guru.vim b/autoload/go/guru.vim index 8d5f5483bc..d2955e4ec4 100644 --- a/autoload/go/guru.vim +++ b/autoload/go/guru.vim @@ -411,7 +411,7 @@ function! go#guru#DescribeInfo() abort return endif - call go#util#EchoInfo(info) + echo "vim-go: " | echohl Function | echon info | echohl None endfunction let args = {