Skip to content

Commit

Permalink
Merge pull request #685 from fatih/show-type-info-complete
Browse files Browse the repository at this point in the history
complete: show identifier information after completion is done
  • Loading branch information
fatih committed Jan 19, 2016
2 parents 55467c6 + 96090a3 commit 6bcbaed
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
14 changes: 10 additions & 4 deletions autoload/go/complete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -87,31 +87,32 @@ fu! s:gocodeCurrentBufferOpt(filename)
return '-in=' . a:filename
endf

fu! s:gocodeCursor()
fu! go#complete#gocodeCursor()
if &encoding != 'utf-8'
let sep = &l:fileformat == 'dos' ? "\r\n" : "\n"
let c = col('.')
let buf = line('.') == 1 ? "" : (join(getline(1, line('.')-1), sep) . sep)
let buf .= c == 1 ? "" : getline('.')[:c-2]
return printf('%d', len(iconv(buf, &encoding, "utf-8")))
endif

return printf('%d', line2byte(line('.')) + (col('.')-2))
endf

fu! s:gocodeAutocomplete()
let filename = s:gocodeCurrentBuffer()
let result = s:gocodeCommand('autocomplete',
\ [s:gocodeCurrentBufferOpt(filename), '-f=vim'],
\ [expand('%:p'), s:gocodeCursor()])
\ [expand('%:p'), go#complete#gocodeCursor()])
call delete(filename)
return result
endf

function! go#complete#GetInfo()
function! go#complete#GetInfoFromOffset(offset)
let filename = s:gocodeCurrentBuffer()
let result = s:gocodeCommand('autocomplete',
\ [s:gocodeCurrentBufferOpt(filename), '-f=godit'],
\ [expand('%:p'), s:gocodeCursor()])
\ [expand('%:p'), a:offset])
call delete(filename)

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

function! go#complete#GetInfo()
let offset = go#complete#gocodeCursor()
return go#complete#GetInfoFromOffset(offset)
endfunction

function! go#complete#Info()
let result = go#complete#GetInfo()
if !empty(result)
Expand Down
19 changes: 19 additions & 0 deletions plugin/go.vim
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ endfunction

" Autocommands
" ============================================================================
"
function! s:echo_go_info()
if !exists('v:completed_item') || empty(v:completed_item)
return
endif
let item = v:completed_item

if !has_key(item, "info")
return
endif

redraws! | echo "vim-go: " | echohl Function | echon item.info | echohl None
endfunction

augroup vim-go
autocmd!
Expand All @@ -129,6 +142,12 @@ augroup vim-go
autocmd CursorHold *.go nested call go#complete#Info()
endif

" Echo the identifier information when completion is done. Useful to see
" the signature of a function, etc...
if exists('##CompleteDone')
autocmd CompleteDone *.go nested call s:echo_go_info()
endif

" Go code formatting on save
if get(g:, "go_fmt_autosave", 1)
autocmd BufWritePre *.go call go#fmt#Format(-1)
Expand Down

0 comments on commit 6bcbaed

Please sign in to comment.