mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-29 15:26:52 +08:00
Fix #271 - Add the ability to open the quickfix or loclist windows only after saving a file
This commit is contained in:
@@ -50,10 +50,11 @@ function! ale#cursor#TruncatedEcho(message) abort
|
||||
endfunction
|
||||
|
||||
function! s:FindItemAtCursor() abort
|
||||
let l:info = get(g:ale_buffer_info, bufnr('%'), {'loclist': []})
|
||||
let l:info = get(g:ale_buffer_info, bufnr(''), {})
|
||||
let l:loclist = get(l:info, 'loclist', [])
|
||||
let l:pos = getcurpos()
|
||||
let l:index = ale#util#BinarySearch(l:info.loclist, l:pos[1], l:pos[2])
|
||||
let l:loc = l:index >= 0 ? l:info.loclist[l:index] : {}
|
||||
let l:index = ale#util#BinarySearch(l:loclist, l:pos[1], l:pos[2])
|
||||
let l:loc = l:index >= 0 ? l:loclist[l:index] : {}
|
||||
|
||||
return [l:info, l:loc]
|
||||
endfunction
|
||||
|
||||
@@ -83,7 +83,7 @@ function! ale#engine#CreateDirectory(buffer) abort
|
||||
endfunction
|
||||
|
||||
function! ale#engine#RemoveManagedFiles(buffer) abort
|
||||
let l:info = get(g:ale_buffer_info, a:buffer)
|
||||
let l:info = get(g:ale_buffer_info, a:buffer, {})
|
||||
|
||||
" We can't delete anything in a sandbox, so wait until we escape from
|
||||
" it to delete temporary files and directories.
|
||||
@@ -298,6 +298,9 @@ function! ale#engine#SetResults(buffer, loclist) abort
|
||||
endif
|
||||
|
||||
if l:linting_is_done
|
||||
" Reset the save event marker, used for opening windows, etc.
|
||||
call setbufvar(a:buffer, 'ale_save_event_fired', 0)
|
||||
|
||||
" Automatically remove all managed temporary files and directories
|
||||
" now that all jobs have completed.
|
||||
call ale#engine#RemoveManagedFiles(a:buffer)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
" Author: w0rp <devw0rp@gmail.com>
|
||||
|
||||
function! ale#events#SaveEvent(buffer) abort
|
||||
call setbufvar(a:buffer, 'ale_save_event_fired', 1)
|
||||
let l:should_lint = ale#Var(a:buffer, 'enabled') && g:ale_lint_on_save
|
||||
|
||||
if g:ale_fix_on_save
|
||||
|
||||
@@ -11,6 +11,16 @@ function! ale#list#IsQuickfixOpen() abort
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
" Check if we should open the list, based on the save event being fired, and
|
||||
" that setting being on, or the setting just being set to `1`.
|
||||
function! s:ShouldOpen(buffer) abort
|
||||
let l:val = ale#Var(a:buffer, 'open_list')
|
||||
let l:saved = getbufvar(a:buffer, 'ale_save_event_fired', 0)
|
||||
|
||||
return (type(l:val) == type(1) && l:val == 1)
|
||||
\ || (l:val ==# 'on_save' && l:saved)
|
||||
endfunction
|
||||
|
||||
function! ale#list#SetLists(buffer, loclist) abort
|
||||
let l:title = expand('#' . a:buffer . ':p')
|
||||
|
||||
@@ -35,8 +45,10 @@ function! ale#list#SetLists(buffer, loclist) abort
|
||||
endif
|
||||
endif
|
||||
|
||||
" If we have errors in our list, open the list. Only if it isn't already open
|
||||
if (g:ale_open_list && !empty(a:loclist)) || g:ale_keep_list_window_open
|
||||
let l:keep_open = ale#Var(a:buffer, 'keep_list_window_open')
|
||||
|
||||
" Open a window to show the problems if we need to.
|
||||
if s:ShouldOpen(a:buffer) && (l:keep_open || !empty(a:loclist))
|
||||
let l:winnr = winnr()
|
||||
let l:mode = mode()
|
||||
let l:reset_visual_selection = l:mode ==? 'v' || l:mode ==# "\<c-v>"
|
||||
@@ -68,7 +80,7 @@ function! ale#list#SetLists(buffer, loclist) abort
|
||||
endfunction
|
||||
|
||||
function! ale#list#CloseWindowIfNeeded(buffer) abort
|
||||
if g:ale_keep_list_window_open || !g:ale_open_list
|
||||
if ale#Var(a:buffer, 'keep_list_window_open') || !s:ShouldOpen(a:buffer)
|
||||
return
|
||||
endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user