Skip to content

Commit 6bcbaed

Browse files
committed
Merge pull request #685 from fatih/show-type-info-complete
complete: show identifier information after completion is done
2 parents 55467c6 + 96090a3 commit 6bcbaed

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

autoload/go/complete.vim

+10-4
Original file line numberDiff line numberDiff line change
@@ -87,31 +87,32 @@ fu! s:gocodeCurrentBufferOpt(filename)
8787
return '-in=' . a:filename
8888
endf
8989

90-
fu! s:gocodeCursor()
90+
fu! go#complete#gocodeCursor()
9191
if &encoding != 'utf-8'
9292
let sep = &l:fileformat == 'dos' ? "\r\n" : "\n"
9393
let c = col('.')
9494
let buf = line('.') == 1 ? "" : (join(getline(1, line('.')-1), sep) . sep)
9595
let buf .= c == 1 ? "" : getline('.')[:c-2]
9696
return printf('%d', len(iconv(buf, &encoding, "utf-8")))
9797
endif
98+
9899
return printf('%d', line2byte(line('.')) + (col('.')-2))
99100
endf
100101

101102
fu! s:gocodeAutocomplete()
102103
let filename = s:gocodeCurrentBuffer()
103104
let result = s:gocodeCommand('autocomplete',
104105
\ [s:gocodeCurrentBufferOpt(filename), '-f=vim'],
105-
\ [expand('%:p'), s:gocodeCursor()])
106+
\ [expand('%:p'), go#complete#gocodeCursor()])
106107
call delete(filename)
107108
return result
108109
endf
109110

110-
function! go#complete#GetInfo()
111+
function! go#complete#GetInfoFromOffset(offset)
111112
let filename = s:gocodeCurrentBuffer()
112113
let result = s:gocodeCommand('autocomplete',
113114
\ [s:gocodeCurrentBufferOpt(filename), '-f=godit'],
114-
\ [expand('%:p'), s:gocodeCursor()])
115+
\ [expand('%:p'), a:offset])
115116
call delete(filename)
116117

117118
" first line is: Charcount,,NumberOfCandidates, i.e: 8,,1
@@ -147,6 +148,11 @@ function! go#complete#GetInfo()
147148
return ""
148149
endfunction
149150

151+
function! go#complete#GetInfo()
152+
let offset = go#complete#gocodeCursor()
153+
return go#complete#GetInfoFromOffset(offset)
154+
endfunction
155+
150156
function! go#complete#Info()
151157
let result = go#complete#GetInfo()
152158
if !empty(result)

plugin/go.vim

+19
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,19 @@ endfunction
120120

121121
" Autocommands
122122
" ============================================================================
123+
"
124+
function! s:echo_go_info()
125+
if !exists('v:completed_item') || empty(v:completed_item)
126+
return
127+
endif
128+
let item = v:completed_item
129+
130+
if !has_key(item, "info")
131+
return
132+
endif
133+
134+
redraws! | echo "vim-go: " | echohl Function | echon item.info | echohl None
135+
endfunction
123136

124137
augroup vim-go
125138
autocmd!
@@ -129,6 +142,12 @@ augroup vim-go
129142
autocmd CursorHold *.go nested call go#complete#Info()
130143
endif
131144

145+
" Echo the identifier information when completion is done. Useful to see
146+
" the signature of a function, etc...
147+
if exists('##CompleteDone')
148+
autocmd CompleteDone *.go nested call s:echo_go_info()
149+
endif
150+
132151
" Go code formatting on save
133152
if get(g:, "go_fmt_autosave", 1)
134153
autocmd BufWritePre *.go call go#fmt#Format(-1)

0 commit comments

Comments
 (0)