syntastic icon indicating copy to clipboard operation
syntastic copied to clipboard

splits cause multiple visible-but-out-of-sync error lists

Open novas0x2a opened this issue 12 years ago • 2 comments

This is kind of tricky, and I don't know the best way to handle it. To reproduce what I'm talking about:

let g:syntastic_check_on_open=1 let g:syntastic_auto_loc_list=1

  1. open file that has errors (error list pops up)
  2. vsplit file window
  3. save file

After step 3, a second loc list pops up within the split, leaving the original loc list bridging the split (so, two visible loc lists).

I thought that this should be a partial solution (inside ShowLocList):

-        call setloclist(0, s:LocList())
+        call setloclist(bufwinnr(""), s:LocList())

the idea being, to only ever attach the loc list to the lowest-numbered window that views the current buffer. It doesn't seem to work that way, though, so I've probably done something wrong (my vimscript is a little weak). Any ideas?

novas0x2a avatar Nov 09 '12 23:11 novas0x2a

I did have the same issue. I don't really care about the outdated second loclist, as I usually open a vertical split only to open a new buffer inside, not to have twice the same file However, the bridging loclist was the main issue for me, and having to manually close the previous loclist was a pain.

This small fix will use cabbrev to add small function after :vs. This function will go back to the previous window, lclose and lopen, and come back to the current window.

As a consequence, there's however no way to remove the loclist anymore with this.

  " Fix loclist on vertical split
  function! SyntasticSplitFix()
    let currwin = winnr()
    wincmd p
    if !empty(getloclist(0))
      lclose
      lopen
    endif
    execute currwin . 'wincmd w'
  endfunction

  cabbrev vs vs\|call SyntasticSplitFix()
  " You might want to call it also on other commands applying a split
  cabbrev Gdiff Gdiff\|call SyntasticSplitFix()

Jerska avatar Apr 23 '18 22:04 Jerska

I've also been struggling with the bridging/out-of-date loclist issue. Based on the fix provided by @Jerska, I hacked together my own that runs anytime a new window is entered (which also happens when running vs):

  " When switching windows, ensures the old window's loclist is closed. This
  " prevents bad split behavior (the loclist bridging multiple windows) and
  " out of date content.

  " File types for which out-of-date loclists should be closed
  let g:syntasticfix_whitelisted_filetypes = ['javascript', 'typescript']

  function! IsWhitelisted(fileType)
    for whitelisted in g:syntasticfix_whitelisted_filetypes
      if a:fileType == whitelisted
        return 1
      endif
    endfor
    return 0
  endfunction

  function! SyntasticFix()
    let newFileType = &ft
    wincmd p " Return to old window
    let oldFileType = &ft
    " whitelisted file -> whitelisted file
    if IsWhitelisted(oldFileType) && IsWhitelisted(newFileType)
      lclose
    " loclist -> whitelisted file
    elseif oldFileType == 'qf' && IsWhitelisted(newFileType)
      quit
    endif
    wincmd p " Return to new window
  endfunction

  autocmd WinEnter * call SyntasticFix()

As for the new window, Syntastic will open the loclist automatically (at least based on my settings), but only if it's up to date.

Brinsky avatar May 26 '19 21:05 Brinsky