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

lsp: log more efficiently #3616

Merged
merged 2 commits into from
Dec 24, 2023
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
4 changes: 4 additions & 0 deletions autoload/go/config.vim
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ function! go#config#Debug() abort
return get(g:, 'go_debug', [])
endfunction

function! go#config#DebugLogDelay() abort
return get(g:, 'go_debug_log_delay', 10)
endfunction

function! go#config#DebugWindows() abort
return get(g:, 'go_debug_windows', {
\ 'vars': 'leftabove 30vnew',
Expand Down
40 changes: 27 additions & 13 deletions autoload/go/lsp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,15 @@ let s:logtimer = 0
function! s:debugasync(timer) abort
let s:logtimer = 0

" set the timer to try again if Vim is in a state where we don't want to
" change the window.
let l:state = state('a')
let l:mode = mode(1)
if len(l:state) > 0 || l:mode[0] == 'v' || l:mode[0] == 'V' || l:mode[0] == 's' || l:mode =~ 'CTRL-V'
let s:logtimer = timer_start(go#config#DebugLogDelay(), function('s:debugasync', []))
return
endif

if !go#util#HasDebug('lsp')
let s:log = []
return
Expand All @@ -1347,34 +1356,39 @@ function! s:debugasync(timer) abort
silent file `='__GOLSP_LOG__'`
setlocal buftype=nofile bufhidden=wipe nomodified nobuflisted noswapfile nowrap nonumber nocursorline
setlocal filetype=golsplog
else
call win_gotoid(l:log_winid)
call win_gotoid(l:winid)
endif

let l:logwinid = bufwinid(l:name)

try
setlocal modifiable
call setbufvar(l:name, '&modifiable', 1)
for [l:event, l:data] in s:log
call remove(s:log, 0)
if getline(1) == ''
call setline('$', printf('===== %s =====', l:event))
if getbufline(l:name, 1)[0] == ''
call setbufline(l:name, '$', printf('===== %s =====', l:event))
else
call append('$', printf('===== %s =====', l:event))
call appendbufline(l:name, '$', printf('===== %s =====', l:event))
endif
call append('$', split(l:data, "\r\n"))
call appendbufline(l:name, '$', split(l:data, "\r\n"))
endfor

" TODO(bc): how to move the window's cursor position without switching
" to the window?
call win_gotoid(l:logwinid)
normal! G
setlocal nomodifiable
finally
call win_gotoid(l:winid)
call setbufvar(l:name, '&modifiable', 0)
finally
endtry
catch
call go#util#EchoError(v:exception)
call go#util#EchoError(printf('at %s: %s', v:throwpoint, v:exception))
finally
" retry in when there's an exception. This can happen when trying to do
" retry when there's an exception. This can happen when trying to do
" completion, because the window can not be changed while completion is in
" progress.
if len(s:log) != 0
let s:logtimer = timer_start(10, function('s:debugasync', []))
let s:logtimer = timer_start(go#config#DebugLogDelay(), function('s:debugasync', []))
endif
endtry
endfunction
Expand All @@ -1384,7 +1398,7 @@ function! s:debug(event, data) abort
let s:log = add(s:log, [a:event, a:data])

if l:shouldStart
let s:logtimer = timer_start(10, function('s:debugasync', []))
let s:logtimer = timer_start(go#config#DebugLogDelay(), function('s:debugasync', []))
endif
endfunction

Expand Down
Loading