All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
1 " Author: Yann Fery <yann@fery.me>
4 Save g:ale_set_quickfix
6 Save g:ale_keep_list_window_open
7 Save g:ale_list_window_size
8 Save g:ale_list_vertical
10 Save g:ale_set_lists_synchronously
12 let g:ale_set_loclist = 1
13 let g:ale_set_quickfix = 0
14 let g:ale_open_list = 0
15 let g:ale_keep_list_window_open = 0
16 let g:ale_list_window_size = 10
17 let g:ale_list_vertical = 0
18 let g:ale_set_lists_synchronously = 1
21 \ {'bufnr': bufnr(''), 'lnum': 5, 'col': 5, 'text': 'x'},
22 \ {'bufnr': bufnr(''), 'lnum': 5, 'col': 4, 'text': 'x'},
23 \ {'bufnr': bufnr(''), 'lnum': 2, 'col': 10, 'text': 'x'},
24 \ {'bufnr': bufnr(''), 'lnum': 3, 'col': 2, 'text': 'x'},
26 let g:ale_buffer_info = {bufnr(''): {'loclist': g:loclist}}
28 function GetQuickfixHeight() abort
29 for l:win in range(1, winnr('$'))
30 if getwinvar(l:win, '&buftype') ==# 'quickfix'
31 return winheight(l:win)
38 " If the window is vertical, window size should match column size/width
39 function GetQuickfixIsVertical(cols) abort
40 for l:win in range(1, winnr('$'))
41 if getwinvar(l:win, '&buftype') is# 'quickfix'
42 return winwidth(l:win) == a:cols
53 unlet! b:ale_list_vertical
54 unlet! b:ale_list_window_size
55 unlet! b:ale_open_list
56 unlet! b:ale_keep_list_window_open
57 unlet! b:ale_save_event_fired
59 delfunction GetQuickfixHeight
60 delfunction GetQuickfixIsVertical
62 " Close quickfix window after every execute block
65 call setloclist(0, [])
68 Execute(IsQuickfixOpen should return the right output):
69 AssertEqual 0, ale#list#IsQuickfixOpen()
70 call setloclist(0, g:loclist)
72 AssertEqual 1, ale#list#IsQuickfixOpen()
74 AssertEqual 0, ale#list#IsQuickfixOpen()
75 call setqflist(g:loclist)
77 AssertEqual 1, ale#list#IsQuickfixOpen()
79 AssertEqual 0, ale#list#IsQuickfixOpen()
81 Execute(The quickfix window should not open by default for the loclist):
82 call ale#list#SetLists(bufnr('%'), g:loclist)
83 Assert !ale#list#IsQuickfixOpen()
85 Execute(The quickfix window should open for just the loclist):
86 let g:ale_open_list = 1
88 " It should not open for an empty list.
89 call ale#list#SetLists(bufnr('%'), [])
90 Assert !ale#list#IsQuickfixOpen()
92 " With a non-empty loclist, the window must open.
93 call ale#list#SetLists(bufnr('%'), g:loclist)
94 Assert ale#list#IsQuickfixOpen()
96 " Clear the list and it should close again.
97 call ale#list#SetLists(bufnr('%'), [])
98 Assert !ale#list#IsQuickfixOpen()
100 Execute(The quickfix window should open on the correct threshold):
101 " The window should open for a value lower than number of entries.
102 let g:ale_open_list = len(g:loclist) - 1
103 call ale#list#SetLists(bufnr('%'), g:loclist)
104 Assert ale#list#IsQuickfixOpen()
106 " Clear the list to be ready for a new value.
107 call ale#list#SetLists(bufnr('%'), [])
108 Assert !ale#list#IsQuickfixOpen()
110 " It should also open for a value equal to the number of entries.
111 let g:ale_open_list = len(g:loclist)
112 call ale#list#SetLists(bufnr('%'), g:loclist)
113 Assert ale#list#IsQuickfixOpen()
115 " Clear the list again, preparing for a final value.
116 call ale#list#SetLists(bufnr('%'), [])
117 Assert !ale#list#IsQuickfixOpen()
119 " Window should not open for values higher than number of loclist entries.
120 let g:ale_open_list = len(g:loclist) + 1
121 call ale#list#SetLists(bufnr('%'), g:loclist)
122 Assert !ale#list#IsQuickfixOpen()
124 " Clear the list just to clean up.
125 call ale#list#SetLists(bufnr('%'), [])
126 Assert !ale#list#IsQuickfixOpen()
128 Execute(The quickfix window height should be correct for the loclist):
129 let g:ale_open_list = 1
130 let g:ale_list_window_size = 7
132 call ale#list#SetLists(bufnr('%'), g:loclist)
134 AssertEqual 7, GetQuickfixHeight()
136 Execute(The quickfix window height should be correct for the loclist with buffer variables):
137 let g:ale_open_list = 1
138 let b:ale_list_window_size = 8
140 call ale#list#SetLists(bufnr('%'), g:loclist)
142 AssertEqual 8, GetQuickfixHeight()
144 Execute(The quickfix window should be vertical for the loclist with appropriate variables):
145 let g:ale_open_list = 1
146 let b:ale_list_window_size = 8
147 let b:ale_list_vertical = 1
149 call ale#list#SetLists(bufnr('%'), g:loclist)
151 AssertEqual 1, GetQuickfixIsVertical(8)
153 Execute(The quickfix window should be horizontal for the loclist with appropriate variables):
154 let g:ale_open_list = 1
155 let b:ale_list_window_size = 8
156 let b:ale_list_vertical = 0
158 call ale#list#SetLists(bufnr('%'), g:loclist)
160 AssertEqual 0, GetQuickfixIsVertical(8)
162 Execute(The quickfix window should stay open for just the loclist):
163 let g:ale_open_list = 1
164 let g:ale_keep_list_window_open = 1
166 " The window should stay open after even after it is made blank again.
167 call ale#list#SetLists(bufnr('%'), g:loclist)
168 call ale#list#SetLists(bufnr('%'), [])
169 Assert ale#list#IsQuickfixOpen()
171 Execute(The quickfix window should not open by default when quickfix is on):
172 let g:ale_set_quickfix = 1
174 call ale#list#SetLists(bufnr('%'), g:loclist)
175 Assert !ale#list#IsQuickfixOpen()
177 Execute(The quickfix window should open for the quickfix list):
178 let g:ale_set_quickfix = 1
179 let g:ale_open_list = 1
181 let g:ale_buffer_info[bufnr('') + 1] = {
182 \ 'loclist': [{'bufnr': -1, 'filename': '/foo/bar', 'lnum': 5, 'col': 5, 'text': 'x'}],
185 " It should not open for an empty list.
186 call ale#list#SetLists(bufnr('%'), [])
187 Assert !ale#list#IsQuickfixOpen(), 'The quickfix window was opened when the list was empty'
189 " With a non-empty quickfix list, the window must open.
190 call ale#list#SetLists(bufnr('%'), g:loclist)
191 Assert ale#list#IsQuickfixOpen(), 'The quickfix window was closed when the list was not empty'
193 " Clear this List. The window should stay open, as there are other items.
194 let g:ale_buffer_info[bufnr('')].loclist = []
195 call ale#list#SetLists(bufnr('%'), [])
196 Assert ale#list#IsQuickfixOpen(), 'The quickfix window closed even though there are items in another buffer'
198 " Clear the other List now. Now the window should close.
199 call remove(g:ale_buffer_info, bufnr('') + 1)
200 call ale#list#SetLists(bufnr('%'), [])
201 Assert !ale#list#IsQuickfixOpen(), 'The quickfix window was not closed'
203 Execute(The quickfix window should stay open for the quickfix list):
204 let g:ale_set_quickfix = 1
205 let g:ale_open_list = 1
206 let g:ale_keep_list_window_open = 1
208 " The window should stay open after even after it is made blank again.
209 call ale#list#SetLists(bufnr('%'), g:loclist)
210 call ale#list#SetLists(bufnr('%'), [])
211 Assert ale#list#IsQuickfixOpen()
213 Execute(The quickfix window height should be correct for the quickfix list):
214 let g:ale_set_quickfix = 1
215 let g:ale_open_list = 1
216 let g:ale_list_window_size = 7
218 call ale#list#SetLists(bufnr('%'), g:loclist)
220 AssertEqual 7, GetQuickfixHeight()
222 Execute(The quickfix window height should be correct for the quickfix list with buffer variables):
223 let g:ale_set_quickfix = 1
224 let g:ale_open_list = 1
225 let b:ale_list_window_size = 8
227 call ale#list#SetLists(bufnr('%'), g:loclist)
229 AssertEqual 8, GetQuickfixHeight()
231 Execute(The quickfix window should be vertical for the quickfix with appropriate variables):
232 let g:ale_open_list = 1
233 let b:ale_list_window_size = 8
234 let b:ale_list_vertical = 1
236 call ale#list#SetLists(bufnr('%'), g:loclist)
238 AssertEqual 1, GetQuickfixIsVertical(8)
240 Execute(The quickfix window should be horizontal for the quickfix with appropriate variables):
241 let g:ale_open_list = 1
242 let b:ale_list_window_size = 8
243 let b:ale_list_vertical = 0
245 call ale#list#SetLists(bufnr('%'), g:loclist)
247 AssertEqual 0, GetQuickfixIsVertical(8)
249 Execute(buffer-local options should be respected):
250 let b:ale_open_list = 1
251 let b:ale_keep_list_window_open = 1
253 call ale#list#SetLists(bufnr('%'), g:loclist)
254 call ale#list#SetLists(bufnr('%'), [])
256 Assert ale#list#IsQuickfixOpen()
258 Execute(The ale_open_list='on_save' option should work):
259 let b:ale_open_list = 'on_save'
261 call ale#list#SetLists(bufnr('%'), g:loclist)
262 " The list shouldn't open yet, the event wasn't fired.
263 Assert !ale#list#IsQuickfixOpen()
265 " Turn this option off, to ensure that we update lists immediately when we
267 let g:ale_set_lists_synchronously = 0
268 let b:ale_save_event_fired = 1
270 call ale#list#SetLists(bufnr('%'), g:loclist)
271 " Now the list should have opened.
272 Assert ale#list#IsQuickfixOpen()
274 call ale#list#SetLists(bufnr('%'), [])
275 " The window should close again when the loclist is empty.
276 Assert !ale#list#IsQuickfixOpen()
278 Execute(The window shouldn't open on save when ale_open_list=0):
279 let b:ale_open_list = 0
280 let b:ale_save_event_fired = 1
282 call ale#list#SetLists(bufnr('%'), g:loclist)
283 " Now the list should have opened.
284 Assert !ale#list#IsQuickfixOpen()