Skip to content

Commit

Permalink
Update location list by window id
Browse files Browse the repository at this point in the history
Fixes #12

Separate out diagnostic highlighting from updating the location list.
Since location lists can be updated by window id, unlike `matchaddpos`,
it does not need to happen in a `windo`.

Open issues:

- The location list is (still) not cleared when the window changes to a
  new buffer
- There seems to be a bug with setloclist where it only updates for the
  current tab.
  • Loading branch information
natebosch committed May 14, 2017
1 parent a5d923c commit d1824b0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Avoid completion requests while already giving suggestions
- Improve heuristics for start of completion range
- Flush file changes after completion
- Bug fix: Don't change window highlights when in select mode

# 0.1.1

Expand Down
18 changes: 9 additions & 9 deletions autoload/lsc/diagnostics.vim
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,22 @@ function! lsc#diagnostics#setForFile(file_path, diagnostics) abort
call add(diagnostics_by_line[diagnostic.range[0]], diagnostic)
endfor
let s:file_diagnostics[a:file_path] = diagnostics_by_line
call lsc#util#winDo('call lsc#diagnostics#update("'.a:file_path.'")')
call lsc#highlights#updateDisplayed()
call lsc#diagnostics#updateLocationList(a:file_path)
endfunction

" Updates highlighting and location list for the current window if it matches
" [file_path]
function! lsc#diagnostics#update(file_path) abort
if a:file_path != expand('%:p') | return | endif
call lsc#highlights#update()
let bufnr = bufnr('%')
" Updates location list for all windows showing [file_path].
function! lsc#diagnostics#updateLocationList(file_path) abort
let bufnr = bufnr(a:file_path)
let items = []
for line in values(lsc#diagnostics#forFile(a:file_path))
for line in values(lsc#diagnostics#forFile(expand('%:p')))
for diagnostic in line
call add(items, s:locationListItem(bufnr, diagnostic))
endfor
endfor
call setloclist(0, items)
for window in lsc#util#windowsForFile(a:file_path)
call setloclist(window, items)
endfor
endfunction

" Finds the first diagnostic which is under the cursor on the current line. If
Expand Down
7 changes: 7 additions & 0 deletions autoload/lsc/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,10 @@ function! s:Callback(group)
call s:callbacks[a:group][0]()
unlet s:callbacks[a:group]
endfunction

" Returns the window IDs of the windows showing the buffer opened for
" [file_path].
function! lsc#util#windowsForFile(file_path) abort
let bufinfo = getbufinfo(a:file_path)[0]
return copy(bufinfo.windows)
endfunction

0 comments on commit d1824b0

Please sign in to comment.