Core: cleanup buffer handling (stage 1).
This commit is contained in:
parent
0bedeb99c7
commit
557b52fb20
@ -372,8 +372,8 @@ function! syntastic#util#stamp() abort " {{{2
|
||||
return split( split(reltimestr(reltime(g:_SYNTASTIC_START)))[0], '\.' )
|
||||
endfunction " }}}2
|
||||
|
||||
function! syntastic#util#setChangedtick(buf) abort " {{{2
|
||||
call setbufvar(a:buf, 'syntastic_changedtick', getbufvar(a:buf, 'changedtick'))
|
||||
function! syntastic#util#setLastTick(buf) abort " {{{2
|
||||
call setbufvar(a:buf, 'syntastic_lasttick', getbufvar(a:buf, 'changedtick'))
|
||||
endfunction " }}}2
|
||||
|
||||
let s:_wid_base = 'syntastic_' . getpid() . '_' . reltimestr(g:_SYNTASTIC_START) . '_'
|
||||
|
@ -19,7 +19,7 @@ if has('reltime')
|
||||
lockvar! g:_SYNTASTIC_START
|
||||
endif
|
||||
|
||||
let g:_SYNTASTIC_VERSION = '3.7.0-216'
|
||||
let g:_SYNTASTIC_VERSION = '3.7.0-217'
|
||||
lockvar g:_SYNTASTIC_VERSION
|
||||
|
||||
" Sanity checks {{{1
|
||||
@ -233,6 +233,15 @@ endfunction " }}}2
|
||||
function! SyntasticReset() abort " {{{2
|
||||
call s:ClearCache(bufnr(''))
|
||||
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
|
||||
|
||||
function! SyntasticToggleMode() abort " {{{2
|
||||
@ -243,7 +252,7 @@ function! SyntasticToggleMode() abort " {{{2
|
||||
endfunction " }}}2
|
||||
|
||||
function! SyntasticSetLoclist() abort " {{{2
|
||||
call g:SyntasticLoclist.current().setloclist()
|
||||
call g:SyntasticLoclist.current().setloclist(0)
|
||||
endfunction " }}}2
|
||||
|
||||
" }}}1
|
||||
@ -305,7 +314,7 @@ function! s:BufEnterHook(fname) abort " {{{2
|
||||
call remove(s:_check_stack, -idx - 1)
|
||||
call s:UpdateErrors(buf, 1, [])
|
||||
endif
|
||||
else
|
||||
elseif &buftype ==# ''
|
||||
call s:notifiers.refresh(g:SyntasticLoclist.current())
|
||||
endif
|
||||
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()
|
||||
if run_checks
|
||||
call s:CacheErrors(a:buf, a:checker_names)
|
||||
call syntastic#util#setChangedtick(a:buf)
|
||||
call syntastic#util#setLastTick(a:buf)
|
||||
else
|
||||
if a:auto_invoked
|
||||
return
|
||||
endif
|
||||
endif
|
||||
|
||||
let loclist = g:SyntasticLoclist.current()
|
||||
let loclist = g:SyntasticLoclist.current(a:buf)
|
||||
|
||||
if exists('*SyntasticCheckHook')
|
||||
call SyntasticCheckHook(loclist.getRaw())
|
||||
@ -412,12 +421,7 @@ function! s:UpdateErrors(buf, auto_invoked, checker_names) abort " {{{2
|
||||
|
||||
let w:syntastic_loclist_set = []
|
||||
if syntastic#util#var('always_populate_loc_list') || do_jump
|
||||
call syntastic#log#debug(g:_SYNTASTIC_DEBUG_NOTIFICATIONS, 'loclist: setloclist (new)')
|
||||
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]
|
||||
call loclist.setloclist(1)
|
||||
if run_checks && do_jump && !loclist.isEmpty()
|
||||
call syntastic#log#debug(g:_SYNTASTIC_DEBUG_NOTIFICATIONS, 'loclist: jump')
|
||||
execute 'silent! lrewind ' . do_jump
|
||||
@ -438,11 +442,9 @@ endfunction " }}}2
|
||||
|
||||
"clear the loc list for the buffer
|
||||
function! s:ClearCache(buf) abort " {{{2
|
||||
call s:notifiers.reset(g:SyntasticLoclist.current())
|
||||
let loclist = getbufvar(a:buf, 'syntastic_loclist')
|
||||
if type(loclist) == type({})
|
||||
call loclist.destroy()
|
||||
endif
|
||||
let loclist = g:SyntasticLoclist.current(a:buf)
|
||||
call s:notifiers.reset(loclist)
|
||||
call loclist.destroy()
|
||||
endfunction " }}}2
|
||||
|
||||
"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'))
|
||||
call s:ClearCache(a:buf)
|
||||
let newLoclist = g:SyntasticLoclist.New([])
|
||||
call newLoclist.setOwner(a:buf)
|
||||
|
||||
if !s:_skip_file(a:buf)
|
||||
" 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)
|
||||
endif
|
||||
|
||||
let newLoclist = newLoclist.extend(loclist)
|
||||
call newLoclist.extend(loclist)
|
||||
|
||||
if !aggregate_errors
|
||||
break
|
||||
@ -627,6 +630,12 @@ function! SyntasticMake(options) abort " {{{2
|
||||
catch /\m^Vim\%((\a\+)\)\=:E380/
|
||||
" E380: At bottom of quickfix stack
|
||||
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/
|
||||
" E776: No location list
|
||||
" do nothing
|
||||
|
@ -25,10 +25,10 @@ function! g:SyntasticAutoloclistNotifier.AutoToggle(loclist) abort " {{{2
|
||||
call a:loclist.show()
|
||||
endif
|
||||
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
|
||||
"something other than syntastic
|
||||
lclose
|
||||
call SyntasticLoclistHide()
|
||||
endif
|
||||
endif
|
||||
endfunction " }}}2
|
||||
|
@ -27,17 +27,18 @@ function! g:SyntasticLoclist.New(rawLoclist) abort " {{{2
|
||||
return newObj
|
||||
endfunction " }}}2
|
||||
|
||||
function! g:SyntasticLoclist.current() abort " {{{2
|
||||
if !exists('b:syntastic_loclist') || empty(b:syntastic_loclist)
|
||||
let b:syntastic_loclist = g:SyntasticLoclist.New([])
|
||||
function! g:SyntasticLoclist.current(...) abort " {{{2
|
||||
let buf = a:0 > 1 ? a:1 : bufnr('')
|
||||
let loclist = getbufvar(buf, 'syntastic_loclist')
|
||||
if type(loclist) != type({}) || empty(loclist)
|
||||
unlet! loclist
|
||||
let loclist = g:SyntasticLoclist.New([])
|
||||
endif
|
||||
return b:syntastic_loclist
|
||||
return loclist
|
||||
endfunction " }}}2
|
||||
|
||||
function! g:SyntasticLoclist.extend(other) abort " {{{2
|
||||
let list = self.copyRaw()
|
||||
call extend(list, a:other.copyRaw())
|
||||
return g:SyntasticLoclist.New(list)
|
||||
call extend(self._rawLoclist, a:other.copyRaw())
|
||||
endfunction " }}}2
|
||||
|
||||
function! g:SyntasticLoclist.sort() abort " {{{2
|
||||
@ -167,7 +168,6 @@ function! g:SyntasticLoclist.setOwner(buffer) abort " {{{2
|
||||
endfunction " }}}2
|
||||
|
||||
function! g:SyntasticLoclist.deploy() abort " {{{2
|
||||
call self.setOwner(bufnr(''))
|
||||
let self._stamp = syntastic#util#stamp()
|
||||
for buf in self.getBuffers()
|
||||
call setbufvar(buf, 'syntastic_loclist', self)
|
||||
@ -289,24 +289,29 @@ function! g:SyntasticLoclist.filter(filters) abort " {{{2
|
||||
return filter(copy(self._rawLoclist), filter)
|
||||
endfunction " }}}2
|
||||
|
||||
function! g:SyntasticLoclist.setloclist() abort " {{{2
|
||||
function! g:SyntasticLoclist.setloclist(new) abort " {{{2
|
||||
if !exists('w:syntastic_loclist_set')
|
||||
let w:syntastic_loclist_set = []
|
||||
endif
|
||||
let buf = bufnr('')
|
||||
if empty(w:syntastic_loclist_set) || w:syntastic_loclist_set != [buf, getbufvar(buf, 'changedtick')]
|
||||
let replace = g:syntastic_reuse_loc_lists && !empty(w:syntastic_loclist_set)
|
||||
if a:new || empty(w:syntastic_loclist_set) || w:syntastic_loclist_set != [self._owner, getbufvar(self._owner, 'changedtick')]
|
||||
let replace = !a:new && g:syntastic_reuse_loc_lists && !empty(w:syntastic_loclist_set)
|
||||
call syntastic#log#debug(g:_SYNTASTIC_DEBUG_NOTIFICATIONS, 'loclist: setloclist ' . (replace ? '(replace)' : '(new)'))
|
||||
call setloclist(0, self.getRaw(), replace ? 'r' : ' ')
|
||||
call syntastic#util#setChangedtick(buf)
|
||||
let w:syntastic_loclist_set = [buf, getbufvar(buf, 'syntastic_changedtick')]
|
||||
try
|
||||
" 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
|
||||
endfunction " }}}2
|
||||
|
||||
"display the cached errors for this buf in the location list
|
||||
function! g:SyntasticLoclist.show() abort " {{{2
|
||||
call syntastic#log#debug(g:_SYNTASTIC_DEBUG_NOTIFICATIONS, 'loclist: show')
|
||||
call self.setloclist()
|
||||
call self.setloclist(0)
|
||||
|
||||
if !self.isEmpty()
|
||||
let num = winnr()
|
||||
|
@ -23,7 +23,7 @@ function! g:SyntasticNotifiers.Instance() abort " {{{2
|
||||
endfunction " }}}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
|
||||
return
|
||||
endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user