Core: cleanup buffer handling (stage 1).

This commit is contained in:
LCD 47 2016-09-07 19:27:12 +03:00
parent 0bedeb99c7
commit 557b52fb20
5 changed files with 51 additions and 37 deletions

View File

@ -372,8 +372,8 @@ function! syntastic#util#stamp() abort " {{{2
return split( split(reltimestr(reltime(g:_SYNTASTIC_START)))[0], '\.' ) return split( split(reltimestr(reltime(g:_SYNTASTIC_START)))[0], '\.' )
endfunction " }}}2 endfunction " }}}2
function! syntastic#util#setChangedtick(buf) abort " {{{2 function! syntastic#util#setLastTick(buf) abort " {{{2
call setbufvar(a:buf, 'syntastic_changedtick', getbufvar(a:buf, 'changedtick')) call setbufvar(a:buf, 'syntastic_lasttick', getbufvar(a:buf, 'changedtick'))
endfunction " }}}2 endfunction " }}}2
let s:_wid_base = 'syntastic_' . getpid() . '_' . reltimestr(g:_SYNTASTIC_START) . '_' let s:_wid_base = 'syntastic_' . getpid() . '_' . reltimestr(g:_SYNTASTIC_START) . '_'

View File

@ -19,7 +19,7 @@ if has('reltime')
lockvar! g:_SYNTASTIC_START lockvar! g:_SYNTASTIC_START
endif endif
let g:_SYNTASTIC_VERSION = '3.7.0-216' let g:_SYNTASTIC_VERSION = '3.7.0-217'
lockvar g:_SYNTASTIC_VERSION lockvar g:_SYNTASTIC_VERSION
" Sanity checks {{{1 " Sanity checks {{{1
@ -233,6 +233,15 @@ endfunction " }}}2
function! SyntasticReset() abort " {{{2 function! SyntasticReset() abort " {{{2
call s:ClearCache(bufnr('')) call s:ClearCache(bufnr(''))
call s:notifiers.refresh(g:SyntasticLoclist.New([])) call s:notifiers.refresh(g:SyntasticLoclist.New([]))
if !empty(get(w:, 'syntastic_loclist_set', []))
let w:syntastic_loclist_set = []
try
" Vim 7.4.2200 or later
call setloclist(0, [], 'r', { 'title': '' })
catch /\m^Vim\%((\a\+)\)\=:E118/
" do nothing
endtry
endif
endfunction " }}}2 endfunction " }}}2
function! SyntasticToggleMode() abort " {{{2 function! SyntasticToggleMode() abort " {{{2
@ -243,7 +252,7 @@ function! SyntasticToggleMode() abort " {{{2
endfunction " }}}2 endfunction " }}}2
function! SyntasticSetLoclist() abort " {{{2 function! SyntasticSetLoclist() abort " {{{2
call g:SyntasticLoclist.current().setloclist() call g:SyntasticLoclist.current().setloclist(0)
endfunction " }}}2 endfunction " }}}2
" }}}1 " }}}1
@ -305,7 +314,7 @@ function! s:BufEnterHook(fname) abort " {{{2
call remove(s:_check_stack, -idx - 1) call remove(s:_check_stack, -idx - 1)
call s:UpdateErrors(buf, 1, []) call s:UpdateErrors(buf, 1, [])
endif endif
else elseif &buftype ==# ''
call s:notifiers.refresh(g:SyntasticLoclist.current()) call s:notifiers.refresh(g:SyntasticLoclist.current())
endif endif
elseif &buftype ==# 'quickfix' elseif &buftype ==# 'quickfix'
@ -387,14 +396,14 @@ function! s:UpdateErrors(buf, auto_invoked, checker_names) abort " {{{2
let run_checks = !a:auto_invoked || s:modemap.doAutoChecking() let run_checks = !a:auto_invoked || s:modemap.doAutoChecking()
if run_checks if run_checks
call s:CacheErrors(a:buf, a:checker_names) call s:CacheErrors(a:buf, a:checker_names)
call syntastic#util#setChangedtick(a:buf) call syntastic#util#setLastTick(a:buf)
else else
if a:auto_invoked if a:auto_invoked
return return
endif endif
endif endif
let loclist = g:SyntasticLoclist.current() let loclist = g:SyntasticLoclist.current(a:buf)
if exists('*SyntasticCheckHook') if exists('*SyntasticCheckHook')
call SyntasticCheckHook(loclist.getRaw()) call SyntasticCheckHook(loclist.getRaw())
@ -412,12 +421,7 @@ function! s:UpdateErrors(buf, auto_invoked, checker_names) abort " {{{2
let w:syntastic_loclist_set = [] let w:syntastic_loclist_set = []
if syntastic#util#var('always_populate_loc_list') || do_jump if syntastic#util#var('always_populate_loc_list') || do_jump
call syntastic#log#debug(g:_SYNTASTIC_DEBUG_NOTIFICATIONS, 'loclist: setloclist (new)') call loclist.setloclist(1)
call setloclist(0, loclist.getRaw())
if !exists('b:syntastic_changedtick')
call syntastic#util#setChangedtick(a:buf)
endif
let w:syntastic_loclist_set = [a:buf, b:syntastic_changedtick]
if run_checks && do_jump && !loclist.isEmpty() if run_checks && do_jump && !loclist.isEmpty()
call syntastic#log#debug(g:_SYNTASTIC_DEBUG_NOTIFICATIONS, 'loclist: jump') call syntastic#log#debug(g:_SYNTASTIC_DEBUG_NOTIFICATIONS, 'loclist: jump')
execute 'silent! lrewind ' . do_jump execute 'silent! lrewind ' . do_jump
@ -438,11 +442,9 @@ endfunction " }}}2
"clear the loc list for the buffer "clear the loc list for the buffer
function! s:ClearCache(buf) abort " {{{2 function! s:ClearCache(buf) abort " {{{2
call s:notifiers.reset(g:SyntasticLoclist.current()) let loclist = g:SyntasticLoclist.current(a:buf)
let loclist = getbufvar(a:buf, 'syntastic_loclist') call s:notifiers.reset(loclist)
if type(loclist) == type({})
call loclist.destroy() call loclist.destroy()
endif
endfunction " }}}2 endfunction " }}}2
"detect and cache all syntax errors in this buffer "detect and cache all syntax errors in this buffer
@ -451,6 +453,7 @@ function! s:CacheErrors(buf, checker_names) abort " {{{2
\ (len(a:checker_names) ? join(a:checker_names) : 'default checkers')) \ (len(a:checker_names) ? join(a:checker_names) : 'default checkers'))
call s:ClearCache(a:buf) call s:ClearCache(a:buf)
let newLoclist = g:SyntasticLoclist.New([]) let newLoclist = g:SyntasticLoclist.New([])
call newLoclist.setOwner(a:buf)
if !s:_skip_file(a:buf) if !s:_skip_file(a:buf)
" debug logging {{{3 " debug logging {{{3
@ -494,7 +497,7 @@ function! s:CacheErrors(buf, checker_names) abort " {{{2
call syntastic#log#debug(g:_SYNTASTIC_DEBUG_LOCLIST, 'sorted:', loclist) call syntastic#log#debug(g:_SYNTASTIC_DEBUG_LOCLIST, 'sorted:', loclist)
endif endif
let newLoclist = newLoclist.extend(loclist) call newLoclist.extend(loclist)
if !aggregate_errors if !aggregate_errors
break break
@ -627,6 +630,12 @@ function! SyntasticMake(options) abort " {{{2
catch /\m^Vim\%((\a\+)\)\=:E380/ catch /\m^Vim\%((\a\+)\)\=:E380/
" E380: At bottom of quickfix stack " E380: At bottom of quickfix stack
call setloclist(0, [], 'r') call setloclist(0, [], 'r')
try
" Vim 7.4.2200 or later
call setloclist(0, [], 'r', { 'title': '' })
catch /\m^Vim\%((\a\+)\)\=:E118/
" do nothing
endtry
catch /\m^Vim\%((\a\+)\)\=:E776/ catch /\m^Vim\%((\a\+)\)\=:E776/
" E776: No location list " E776: No location list
" do nothing " do nothing

View File

@ -25,10 +25,10 @@ function! g:SyntasticAutoloclistNotifier.AutoToggle(loclist) abort " {{{2
call a:loclist.show() call a:loclist.show()
endif endif
else else
if auto_loc_list == 1 || auto_loc_list == 2 if (auto_loc_list == 1 || auto_loc_list == 2) && !empty(get(w:, 'syntastic_loclist_set', []))
"TODO: this will close the loc list window if one was opened by "TODO: this will close the loc list window if one was opened by
"something other than syntastic "something other than syntastic
lclose call SyntasticLoclistHide()
endif endif
endif endif
endfunction " }}}2 endfunction " }}}2

View File

@ -27,17 +27,18 @@ function! g:SyntasticLoclist.New(rawLoclist) abort " {{{2
return newObj return newObj
endfunction " }}}2 endfunction " }}}2
function! g:SyntasticLoclist.current() abort " {{{2 function! g:SyntasticLoclist.current(...) abort " {{{2
if !exists('b:syntastic_loclist') || empty(b:syntastic_loclist) let buf = a:0 > 1 ? a:1 : bufnr('')
let b:syntastic_loclist = g:SyntasticLoclist.New([]) let loclist = getbufvar(buf, 'syntastic_loclist')
if type(loclist) != type({}) || empty(loclist)
unlet! loclist
let loclist = g:SyntasticLoclist.New([])
endif endif
return b:syntastic_loclist return loclist
endfunction " }}}2 endfunction " }}}2
function! g:SyntasticLoclist.extend(other) abort " {{{2 function! g:SyntasticLoclist.extend(other) abort " {{{2
let list = self.copyRaw() call extend(self._rawLoclist, a:other.copyRaw())
call extend(list, a:other.copyRaw())
return g:SyntasticLoclist.New(list)
endfunction " }}}2 endfunction " }}}2
function! g:SyntasticLoclist.sort() abort " {{{2 function! g:SyntasticLoclist.sort() abort " {{{2
@ -167,7 +168,6 @@ function! g:SyntasticLoclist.setOwner(buffer) abort " {{{2
endfunction " }}}2 endfunction " }}}2
function! g:SyntasticLoclist.deploy() abort " {{{2 function! g:SyntasticLoclist.deploy() abort " {{{2
call self.setOwner(bufnr(''))
let self._stamp = syntastic#util#stamp() let self._stamp = syntastic#util#stamp()
for buf in self.getBuffers() for buf in self.getBuffers()
call setbufvar(buf, 'syntastic_loclist', self) call setbufvar(buf, 'syntastic_loclist', self)
@ -289,24 +289,29 @@ function! g:SyntasticLoclist.filter(filters) abort " {{{2
return filter(copy(self._rawLoclist), filter) return filter(copy(self._rawLoclist), filter)
endfunction " }}}2 endfunction " }}}2
function! g:SyntasticLoclist.setloclist() abort " {{{2 function! g:SyntasticLoclist.setloclist(new) abort " {{{2
if !exists('w:syntastic_loclist_set') if !exists('w:syntastic_loclist_set')
let w:syntastic_loclist_set = [] let w:syntastic_loclist_set = []
endif endif
let buf = bufnr('') if a:new || empty(w:syntastic_loclist_set) || w:syntastic_loclist_set != [self._owner, getbufvar(self._owner, 'changedtick')]
if empty(w:syntastic_loclist_set) || w:syntastic_loclist_set != [buf, getbufvar(buf, 'changedtick')] let replace = !a:new && g:syntastic_reuse_loc_lists && !empty(w:syntastic_loclist_set)
let replace = g:syntastic_reuse_loc_lists && !empty(w:syntastic_loclist_set)
call syntastic#log#debug(g:_SYNTASTIC_DEBUG_NOTIFICATIONS, 'loclist: setloclist ' . (replace ? '(replace)' : '(new)')) call syntastic#log#debug(g:_SYNTASTIC_DEBUG_NOTIFICATIONS, 'loclist: setloclist ' . (replace ? '(replace)' : '(new)'))
call setloclist(0, self.getRaw(), replace ? 'r' : ' ') call setloclist(0, self.getRaw(), replace ? 'r' : ' ')
call syntastic#util#setChangedtick(buf) try
let w:syntastic_loclist_set = [buf, getbufvar(buf, 'syntastic_changedtick')] " Vim 7.4.2200 or later
call setloclist(0, [], 'r', { 'title': (self.isEmpty() ? '' : ':SyntasticCheck ' . self._name) })
catch /\m^Vim\%((\a\+)\)\=:E118/
" do nothing
endtry
call syntastic#util#setLastTick(self._owner)
let w:syntastic_loclist_set = [self._owner, getbufvar(self._owner, 'syntastic_lasttick')]
endif endif
endfunction " }}}2 endfunction " }}}2
"display the cached errors for this buf in the location list "display the cached errors for this buf in the location list
function! g:SyntasticLoclist.show() abort " {{{2 function! g:SyntasticLoclist.show() abort " {{{2
call syntastic#log#debug(g:_SYNTASTIC_DEBUG_NOTIFICATIONS, 'loclist: show') call syntastic#log#debug(g:_SYNTASTIC_DEBUG_NOTIFICATIONS, 'loclist: show')
call self.setloclist() call self.setloclist(0)
if !self.isEmpty() if !self.isEmpty()
let num = winnr() let num = winnr()

View File

@ -23,7 +23,7 @@ function! g:SyntasticNotifiers.Instance() abort " {{{2
endfunction " }}}2 endfunction " }}}2
function! g:SyntasticNotifiers.refresh(loclist) abort " {{{2 function! g:SyntasticNotifiers.refresh(loclist) abort " {{{2
if !a:loclist.isEmpty() && !a:loclist.isNewerThan([]) if !syntastic#util#bufIsActive(bufnr('')) || (!a:loclist.isEmpty() && !a:loclist.isNewerThan([]))
" loclist not fully constructed yet " loclist not fully constructed yet
return return
endif endif