vimrc/sources_non_forked/vim-gitgutter/autoload/gitgutter/debug.vim

110 lines
2.5 KiB
VimL
Raw Normal View History

let s:plugin_dir = expand('<sfile>:p:h:h:h').'/'
let s:log_file = s:plugin_dir.'gitgutter.log'
let s:channel_log = s:plugin_dir.'channel.log'
let s:new_log_session = 1
function! gitgutter#debug#debug()
" Open a scratch buffer
vsplit __GitGutter_Debug__
normal! ggdG
setlocal buftype=nofile
setlocal bufhidden=delete
setlocal noswapfile
2018-03-31 14:56:26 +00:00
call s:vim_version()
call s:separator()
2018-03-31 14:56:26 +00:00
call s:git_version()
call s:separator()
2018-03-31 14:56:26 +00:00
call s:grep_version()
call s:separator()
2018-03-31 14:56:26 +00:00
call s:option('updatetime')
endfunction
2018-03-31 14:56:26 +00:00
function! s:separator()
call s:output('')
endfunction
2018-03-31 14:56:26 +00:00
function! s:vim_version()
redir => version_info
silent execute 'version'
redir END
2018-03-31 14:56:26 +00:00
call s:output(split(version_info, '\n')[0:2])
endfunction
2018-03-31 14:56:26 +00:00
function! s:git_version()
let v = system(g:gitgutter_git_executable.' --version')
2018-03-31 14:56:26 +00:00
call s:output( substitute(v, '\n$', '', '') )
endfunction
2018-03-31 14:56:26 +00:00
function! s:grep_version()
2020-12-04 21:15:32 +00:00
let v = system(g:gitgutter_grep.' --version')
2018-03-31 14:56:26 +00:00
call s:output( substitute(v, '\n$', '', '') )
2020-12-04 21:15:32 +00:00
let v = system(g:gitgutter_grep.' --help')
2018-03-31 14:56:26 +00:00
call s:output( substitute(v, '\%x00', '', 'g') )
endfunction
2018-03-31 14:56:26 +00:00
function! s:option(name)
if exists('+' . a:name)
let v = eval('&' . a:name)
2018-03-31 14:56:26 +00:00
call s:output(a:name . '=' . v)
" redir => output
" silent execute "verbose set " . a:name . "?"
" redir END
2018-03-31 14:56:26 +00:00
" call s:output(a:name . '=' . output)
else
2018-03-31 14:56:26 +00:00
call s:output(a:name . ' [n/a]')
end
endfunction
2018-03-31 14:56:26 +00:00
function! s:output(text)
call append(line('$'), a:text)
endfunction
" assumes optional args are calling function's optional args
function! gitgutter#debug#log(message, ...) abort
if g:gitgutter_log
if s:new_log_session && gitgutter#async#available()
if exists('*ch_logfile')
call ch_logfile(s:channel_log, 'w')
endif
endif
execute 'redir >> '.s:log_file
if s:new_log_session
let s:start = reltime()
silent echo "\n==== start log session ===="
endif
let elapsed = reltimestr(reltime(s:start)).' '
silent echo ''
" callers excluding this function
silent echo elapsed.expand('<sfile>')[:-22].':'
silent echo elapsed.s:format_for_log(a:message)
if a:0 && !empty(a:1)
for msg in a:000
silent echo elapsed.s:format_for_log(msg)
endfor
endif
redir END
let s:new_log_session = 0
endif
endfunction
function! s:format_for_log(data) abort
if type(a:data) == 1
return join(split(a:data,'\n'),"\n")
elseif type(a:data) == 3
return '['.join(a:data,"\n").']'
else
return a:data
endif
endfunction