Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

complete: show identifier information after completion is done #685

Merged
merged 5 commits into from
Jan 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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