PoC: make async work with git and Neovim
This commit is contained in:
parent
3ad10c65b5
commit
e72ccb952d
@ -8,6 +8,13 @@ let g:sy_cache = {}
|
||||
|
||||
let s:has_doau_modeline = v:version > 703 || v:version == 703 && has('patch442')
|
||||
|
||||
" Function: #verbose {{{1
|
||||
function! sy#verbose(msg) abort
|
||||
if &verbose
|
||||
echomsg printf('[sy] %s', a:msg)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Function: #start {{{1
|
||||
function! sy#start() abort
|
||||
if g:signify_locked
|
||||
@ -24,9 +31,10 @@ function! sy#start() abort
|
||||
return
|
||||
endif
|
||||
|
||||
|
||||
function! s:chdir()
|
||||
return haslocaldir() ? 'lcd' : (exists(':tcd') && haslocaldir(-1, 0)) ? 'tcd' : 'cd'
|
||||
return haslocaldir()
|
||||
\ ? 'lcd'
|
||||
\ : (exists(':tcd') && haslocaldir(-1, 0)) ? 'tcd' : 'cd'
|
||||
endfunction
|
||||
|
||||
" sy_info is used in autoload/sy/repo
|
||||
@ -38,8 +46,8 @@ function! sy#start() abort
|
||||
\ 'file': sy#util#escape(fnamemodify(sy_path, ':t')),
|
||||
\ }
|
||||
|
||||
" new buffer.. add to list of registered files
|
||||
if !exists('b:sy') || b:sy.path != sy_path
|
||||
call sy#verbose('Register new file: '. sy_path)
|
||||
let b:sy = {
|
||||
\ 'path' : sy_path,
|
||||
\ 'buffer': bufnr(''),
|
||||
@ -51,65 +59,39 @@ function! sy#start() abort
|
||||
if get(g:, 'signify_disable_by_default')
|
||||
return
|
||||
endif
|
||||
|
||||
" register buffer as active
|
||||
let b:sy.active = 1
|
||||
|
||||
call sy#repo#detect(1)
|
||||
" let [ diff, b:sy.type ] = sy#repo#detect()
|
||||
" if b:sy.type == 'unknown'
|
||||
" call sy#disable()
|
||||
" return
|
||||
" endif
|
||||
|
||||
" " register file as active with found VCS
|
||||
" let b:sy.stats = [0, 0, 0]
|
||||
|
||||
" let dir = fnamemodify(b:sy.path, ':h')
|
||||
" if !has_key(g:sy_cache, dir)
|
||||
" let g:sy_cache[dir] = b:sy.type
|
||||
" endif
|
||||
|
||||
" if empty(diff)
|
||||
" " no changes found
|
||||
" return
|
||||
" endif
|
||||
|
||||
" inactive buffer.. bail out
|
||||
elseif !b:sy.active
|
||||
call sy#verbose('Inactive buffer: '. sy_path)
|
||||
return
|
||||
|
||||
" retry detecting VCS
|
||||
elseif b:sy.type == 'unknown'
|
||||
call sy#verbose('Retry detecting VCS: '. sy_path)
|
||||
call sy#repo#detect(0)
|
||||
|
||||
" update signs
|
||||
else
|
||||
let diff = sy#repo#get_diff_{b:sy.type}()[1]
|
||||
let b:sy.id_top = g:id_top
|
||||
call sy#verbose('Update signs: '. sy_path)
|
||||
call sy#repo#get_diff_{b:sy.type}(0)
|
||||
endif
|
||||
|
||||
call sy#update_signs(diff, type)
|
||||
endfunction
|
||||
|
||||
function! sy#update_signs(diff, type, do_register) abort
|
||||
if b:sy.type == 'unknown'
|
||||
echomsg 'DEBUG: type unknown'
|
||||
" no VCS found
|
||||
call sy#disable()
|
||||
return
|
||||
endif
|
||||
function! sy#update_signs(diff, do_register) abort
|
||||
" if b:sy.type == 'unknown'
|
||||
" echomsg 'DEBUG: type unknown'
|
||||
" " no VCS found
|
||||
" call sy#disable()
|
||||
" return
|
||||
" endif
|
||||
|
||||
if do_register
|
||||
if a:do_register
|
||||
" register file as active with found VCS
|
||||
let b:sy.stats = [0, 0, 0]
|
||||
|
||||
let dir = fnamemodify(b:sy.path, ':h')
|
||||
let dir = fnamemodify(b:sy.path, ':h')
|
||||
if !has_key(g:sy_cache, dir)
|
||||
let g:sy_cache[dir] = b:sy.type
|
||||
endif
|
||||
|
||||
if empty(diff)
|
||||
if empty(a:diff)
|
||||
" no changes found
|
||||
return
|
||||
endif
|
||||
|
@ -3,7 +3,7 @@
|
||||
scriptencoding utf-8
|
||||
|
||||
" Function: #detect {{{1
|
||||
function! sy#repo#detect() abort
|
||||
function! sy#repo#detect(do_register) abort
|
||||
let vcs_list = s:vcs_list
|
||||
" Simple cache. If there is a registered VCS-controlled file in this
|
||||
" directory already, assume that this file is probably controlled by
|
||||
@ -16,7 +16,7 @@ function! sy#repo#detect() abort
|
||||
endif
|
||||
|
||||
for type in vcs_list
|
||||
call sy#repo#get_diff_{type}()
|
||||
call sy#repo#get_diff_{type}(a:do_register)
|
||||
endfor
|
||||
" let [istype, diff] = sy#repo#get_diff_{type}()
|
||||
" if istype
|
||||
@ -40,25 +40,31 @@ endfunction
|
||||
|
||||
" Function: s:callback_exit {{{1
|
||||
function! s:callback_exit(_job_id, exitcode, _event) dict abort
|
||||
let [found_diff, diff] = a:exitcode ? [0, ''] : [1, diff]
|
||||
call sy#update_signs(found_diff, diff)
|
||||
let [found_diff, diff] = a:exitcode ? [0, ''] : [1, join(self.stdoutbuf, "\n")]
|
||||
" echomsg 'DEBUG: '. diff
|
||||
if found_diff
|
||||
let b:sy.type = 'git'
|
||||
endif
|
||||
if !self.do_register
|
||||
let b:sy.id_top = g:id_top
|
||||
endif
|
||||
call sy#update_signs(diff, self.do_register)
|
||||
endfunction
|
||||
|
||||
" Function: #get_diff_git {{{1
|
||||
function! sy#repo#get_diff_git() abort
|
||||
let cmd = (has('win32') && &shell =~ 'cmd')
|
||||
\ ? g:signify_vcs_cmds.git
|
||||
\ : ['sh', '-c', g:signify_vcs_cmds.git]
|
||||
let cmd = s:expand_cmd(cmd, b:sy_info.file)
|
||||
function! sy#repo#get_diff_git(do_register) abort
|
||||
let cmd = s:expand_cmd(g:signify_vcs_cmds.git, b:sy_info.file)
|
||||
let cmd = (has('win32') && &shell =~ 'cmd') ? cmd : ['sh', '-c', cmd]
|
||||
if exists('s:job_id_git')
|
||||
silent! call jobstop(s:job_id_git)
|
||||
endif
|
||||
execute b:sy_info.chdir fnameescape(b:sy_info.dir)
|
||||
try
|
||||
let s:job_id_git = jobstart(cmd, {
|
||||
\ 'stdoutbuf': [],
|
||||
\ 'on_stdout': function('s:callback_stdout_nvim'),
|
||||
\ 'on_exit': function('s:callback_exit'),
|
||||
\ 'stdoutbuf': [],
|
||||
\ 'do_register': a:do_register,
|
||||
\ 'on_stdout': function('s:callback_stdout_nvim'),
|
||||
\ 'on_exit': function('s:callback_exit'),
|
||||
\ })
|
||||
finally
|
||||
execute b:sy_info.chdir b:sy_info.cwd
|
||||
|
Loading…
Reference in New Issue
Block a user