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

Fix #2524: Use own interval to call AutoTypeInfo/AutoSameids #2529

Merged
merged 16 commits into from
Oct 20, 2019
Merged
Show file tree
Hide file tree
Changes from 8 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
46 changes: 35 additions & 11 deletions autoload/go/auto.vim
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,46 @@ function! go#auto#echo_go_info()
redraws! | echo "vim-go: " | echohl Function | echon item.info | echohl None
endfunction

function! go#auto#auto_type_info()
if !go#config#AutoTypeInfo() || !isdirectory(expand('%:p:h'))
return
endif
function! go#auto#update_autocmd()
execute 'augroup vim-go-buffer-auto-' . bufnr('')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the value of using a group that's unique to the buffer? Will augroup vim-go-buffer-auto suffice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right. I tested and recognized vim-go-suffer-auto is just enough. Fixed on bb1d460

autocmd! * <buffer>
if go#config#AutoTypeInfo() || go#config#AutoSameids()
" vint: -ProhibitAutocmdWithNoGroup
autocmd CursorMoved <buffer> call go#auto#timer_restart()
autocmd BufLeave <buffer> call s:timer_stop()
" vint: +ProhibitAutocmdWithNoGroup
else
call s:timer_stop()
endif
augroup END
bhcleek marked this conversation as resolved.
Show resolved Hide resolved
endfunction

" GoInfo automatic update
call go#tool#Info(0)
function! go#auto#timer_restart()
if isdirectory(expand('%:p:h'))
call s:timer_stop()
call s:timer_start()
endif
endfunction

function! go#auto#auto_sameids()
if !go#config#AutoSameids() || !isdirectory(expand('%:p:h'))
return
function! s:timer_stop()
if get(b:, 'go_auto_timer_id')
call timer_stop(b:go_auto_timer_id)
let b:go_auto_timer_id = 0
endif
endfunction

function! s:timer_start()
let b:go_auto_timer_id = timer_start(go#config#Updatetime(), function('s:handler'))
endfunction

" GoSameId automatic update
call go#guru#SameIds(0)
function! s:handler(timer_id)
if go#config#AutoTypeInfo()
call go#tool#Info(0)
endif
if go#config#AutoSameids()
call go#guru#SameIds(0)
endif
let s:timer_id = 0
endfunction

function! go#auto#fmt_autosave()
Expand Down
11 changes: 6 additions & 5 deletions autoload/go/complete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,12 @@ function! go#complete#ToggleAutoTypeInfo() abort
if go#config#AutoTypeInfo()
call go#config#SetAutoTypeInfo(0)
call go#util#EchoProgress("auto type info disabled")
return
end

call go#config#SetAutoTypeInfo(1)
call go#util#EchoProgress("auto type info enabled")
else
call go#config#SetAutoTypeInfo(1)
call go#util#EchoProgress("auto type info enabled")
call go#auto#timer_restart()
endif
call go#auto#update_autocmd()
endfunction

" restore Vi compatibility settings
Expand Down
4 changes: 4 additions & 0 deletions autoload/go/config.vim
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,10 @@ function! go#config#CodeCompletionEnabled() abort
return get(g:, "go_code_completion_enabled", 1)
endfunction

function! go#config#Updatetime() abort
return get(g:, 'go_updatetime', 800)
endfunction

" Set the default value. A value of "1" is a shortcut for this, for
" compatibility reasons.
if exists("g:go_gorename_prefill") && g:go_gorename_prefill == 1
Expand Down
9 changes: 5 additions & 4 deletions autoload/go/guru.vim
Original file line number Diff line number Diff line change
Expand Up @@ -522,11 +522,12 @@ function! go#guru#AutoToggleSameIds() abort
call go#util#EchoProgress("sameids auto highlighting disabled")
call go#guru#ClearSameIds()
call go#config#SetAutoSameids(0)
return
else
call go#util#EchoSuccess("sameids auto highlighting enabled")
call go#config#SetAutoSameids(1)
call go#auto#timer_restart()
endif

call go#util#EchoSuccess("sameids auto highlighting enabled")
call go#config#SetAutoSameids(1)
call go#auto#update_autocmd()
endfunction


Expand Down
9 changes: 4 additions & 5 deletions ftplugin/go.vim
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ if get(g:, "go_textobj_enabled", 1)
xnoremap <buffer> <silent> [[ :<c-u>call go#textobj#FunctionJump('v', 'prev')<cr>
endif

if go#config#AutoTypeInfo() || go#config#AutoSameids()
let &l:updatetime= get(g:, "go_updatetime", 800)
endif
" Set up autocmd to call :GoSameIds / :GoInfo automatically
call go#auto#update_autocmd()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that there's a CursorHold autocmd that calls go#auto#update_autocmd, is this call necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exactly because BufEnter does. I removed this line: 3b576be.


" Autocommands
" ============================================================================
Expand All @@ -95,8 +94,8 @@ augroup vim-go-buffer
autocmd BufDelete <buffer> call go#lsp#DidClose(expand('<afile>:p'))
endif

autocmd CursorHold <buffer> call go#auto#auto_type_info()
autocmd CursorHold <buffer> call go#auto#auto_sameids()
autocmd BufEnter <buffer> call go#auto#timer_restart()
autocmd BufEnter,CursorHold <buffer> call go#auto#update_autocmd()

" Echo the identifier information when completion is done. Useful to see
" the signature of a function, etc...
Expand Down