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 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
64 changes: 55 additions & 9 deletions autoload/go/auto.vim
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,68 @@ 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'))
let s:timer_id = 0

" go#auto#update_autocmd() will be called on BufEnter,CursorHold. This
" configures the augroup according to conditions below.
"
" | # | has_timer | should_enable | do |
" |---|-----------|---------------|------------------------------------|
" | 1 | false | false | return early |
" | 2 | true | true | return early |
" | 3 | true | false | clear the group and stop the timer |
" | 4 | false | true | configure the group |
function! go#auto#update_autocmd()
let has_timer = get(b:, 'has_timer')
let should_enable = go#config#AutoTypeInfo() || go#config#AutoSameids()
if (!has_timer && !should_enable) || (has_timer && should_enable)
return
endif

" GoInfo automatic update
call go#tool#Info(0)
if has_timer
augroup vim-go-buffer-auto
autocmd! * <buffer>
augroup END
let b:has_timer = 0
call s:timer_stop()
return
endif

augroup vim-go-buffer-auto
autocmd! * <buffer>
autocmd CursorMoved <buffer> call s:timer_restart()
autocmd BufLeave <buffer> call s:timer_stop()
augroup END
bhcleek marked this conversation as resolved.
Show resolved Hide resolved
let b:has_timer = 1
call s:timer_start()
endfunction

function! go#auto#auto_sameids()
if !go#config#AutoSameids() || !isdirectory(expand('%:p:h'))
return
function! s:timer_restart()
if isdirectory(expand('%:p:h'))
call s:timer_stop()
call s:timer_start()
endif
endfunction

function! s:timer_stop()
if s:timer_id
call timer_stop(s:timer_id)
let s:timer_id = 0
endif
endfunction

function! s:timer_start()
let s: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
10 changes: 5 additions & 5 deletions autoload/go/complete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,11 @@ 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")
endif
call go#auto#update_autocmd()
endfunction

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

function! go#config#Updatetime() abort
let go_updatetime = get(g:, 'go_updatetime', 800)
return go_updatetime == 0 ? &updatetime : go_updatetime
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
8 changes: 4 additions & 4 deletions autoload/go/guru.vim
Original file line number Diff line number Diff line change
Expand Up @@ -522,11 +522,11 @@ 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)
endif

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


Expand Down
15 changes: 8 additions & 7 deletions doc/vim-go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,8 @@ CTRL-t
the cursor. This basically toggles the option |'g:go_auto_sameids'|
on/off.
If enabled it starts highlighting whenever your cursor is staying at the
same position for a configurable period of time (see 'updatetime'). If
disabled it clears and stops automatic highlighting.
same position for a configurable period of time (see |'g:go_updatetime'|).
If disabled it clears and stops automatic highlighting.

*:GoMetaLinter*
:GoMetaLinter! [path]
Expand Down Expand Up @@ -1267,7 +1267,7 @@ with |:GoPlay|. By default it's enabled. >
Use this option to show the type info (|:GoInfo|) for the word under the
cursor automatically. Whenever the cursor changes the type info will be
updated. By default it's disabled. The delay can be configured with the
'g:go_updatetime' setting.
|'g:go_updatetime'| setting.
>
let g:go_auto_type_info = 0
<
Expand All @@ -1284,15 +1284,16 @@ Valid options are `gocode`, `gopls`, and `guru`.
*'g:go_auto_sameids'*

Use this option to highlight all uses of the identifier under the cursor
(:GoSameIds) automatically. By default it's disabled. The delay can be
configured with the 'g:go_updatetime' setting.
(|:GoSameIds|) automatically. By default it's disabled. The delay can be
configured with the |'g:go_updatetime'| setting.
>
let g:go_auto_sameids = 0
<
*'g:go_updatetime'*

Use this option to configure the a custom 'updatetime' for Go source files. If
set to 0, no custom time will be configured. By default it's set to 800ms.
Use this option to configure the delay until it starts some jobs (see
|'g:go_auto_type_info'|, |'g:go_auto_sameids'|). If set to 0, it uses the
value from 'updatetime'. By default it's set to 800ms.
>
let g:go_updatetime = 800
<
Expand Down
7 changes: 1 addition & 6 deletions ftplugin/go.vim
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ 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

" Autocommands
" ============================================================================
"
Expand All @@ -95,8 +91,7 @@ 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,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