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.
2 function! CheckAutocmd(group)
6 execute 'silent! autocmd ' . a:group
11 " Some event names have aliases, and NeoVim and Vim produce
12 " different output. The names are remapped to fix this.
13 let l:event_name_corrections = {
14 \ 'BufWrite': 'BufWritePre',
15 \ 'BufRead': 'BufReadPost',
18 " autocmd commands are split across two lines in output, so we
19 " must merge the lines back into one simple line.
20 for l:line in split(l:output, "\n")
21 if l:line =~# '^ALE' && split(l:line)[0] ==# a:group
22 let l:header = split(l:line)[1]
23 let l:header = get(l:event_name_corrections, l:header, l:header)
24 elseif !empty(l:header)
25 " There's an extra line for buffer events, and we should only look
26 " for the one matching the current buffer.
27 if l:line =~# '<buffer=' . bufnr('') . '>'
28 let l:header .= ' <buffer>'
29 elseif l:line[:0] is# ' '
30 call add(l:matches, join(split(l:header . l:line)))
42 Save g:ale_completion_enabled
43 Save g:ale_echo_cursor
45 Save g:ale_fix_on_save
46 Save g:ale_lint_on_enter
47 Save g:ale_lint_on_filetype_changed
48 Save g:ale_lint_on_insert_leave
49 Save g:ale_lint_on_save
50 Save g:ale_lint_on_text_changed
51 Save g:ale_pattern_options_enabled
52 Save g:ale_hover_cursor
53 Save g:ale_close_preview_on_insert
55 " Turn everything on by default for these tests.
56 let g:ale_completion_enabled = 1
57 let g:ale_echo_cursor = 1
59 let g:ale_fix_on_save = 1
60 let g:ale_lint_on_enter = 1
61 let g:ale_lint_on_filetype_changed = 1
62 let g:ale_lint_on_insert_leave = 1
63 let g:ale_lint_on_save = 1
64 let g:ale_lint_on_text_changed = 1
65 let g:ale_pattern_options_enabled = 1
66 let g:ale_hover_cursor = 1
67 let g:ale_close_preview_on_insert = 0
70 delfunction CheckAutocmd
73 if g:ale_completion_enabled
74 call ale#completion#Enable()
76 call ale#completion#Disable()
79 call ale#events#Init()
81 Execute (All events should be set up when everything is on):
82 let g:ale_echo_cursor = 1
84 " The InsertEnter event is only added when a mapping is not set.
87 \ 'BufEnter * call ale#events#ReadOrEnterEvent(str2nr(expand(''<abuf>'')))',
88 \ 'BufReadPost * call ale#events#ReadOrEnterEvent(str2nr(expand(''<abuf>'')))',
89 \ 'BufWinEnter * call ale#events#LintOnEnter(str2nr(expand(''<abuf>'')))',
90 \ 'BufWritePost * call ale#events#SaveEvent(str2nr(expand(''<abuf>'')))',
91 \ 'CursorHold * if exists(''*ale#engine#Cleanup'') | call ale#cursor#EchoCursorWarningWithDelay() | endif',
92 \ 'CursorHold if exists(''*ale#lsp#Send'') | call ale#hover#ShowTruncatedMessageAtCursor() | endif',
93 \ 'CursorMoved * if exists(''*ale#engine#Cleanup'') | call ale#cursor#EchoCursorWarningWithDelay() | endif',
94 \ 'FileChangedShellPost * call ale#events#FileChangedEvent(str2nr(expand(''<abuf>'')))',
95 \ 'FileType * call ale#events#FileTypeEvent( str2nr(expand(''<abuf>'')), expand(''<amatch>''))',
97 \ maparg("\<C-c>", 'i') isnot# '<Esc>' && !exists('##ModeChanged')
99 \ 'InsertEnter * call ale#events#InsertEnterEvent(str2nr(expand(''<abuf>'')))',
100 \ 'InsertLeave * call ale#events#InsertLeaveEvent(str2nr(expand(''<abuf>'')))',
104 \ exists('##ModeChanged')
105 \ ? ['ModeChanged i*:* call ale#events#InsertLeaveEvent(str2nr(expand(''<abuf>'')))']
108 \ 'TextChanged * call ale#Queue(ale#Var(str2nr(expand(''<abuf>'')), ''lint_delay''))',
109 \ 'TextChangedI * call ale#Queue(ale#Var(str2nr(expand(''<abuf>'')), ''lint_delay''))',
111 \ CheckAutocmd('ALEEvents')
113 Execute (Only the required events should be bound even if various settings are off):
114 let g:ale_enabled = 1
115 let g:ale_completion_enabled = 0
116 let g:ale_echo_cursor = 0
117 let g:ale_fix_on_save = 0
118 let g:ale_lint_on_enter = 0
119 let g:ale_lint_on_filetype_changed = 0
120 let g:ale_lint_on_insert_leave = 0
121 let g:ale_lint_on_save = 0
122 let g:ale_lint_on_text_changed = 0
123 let g:ale_pattern_options_enabled = 0
124 let g:ale_hover_cursor = 0
128 \ 'BufEnter * call ale#events#ReadOrEnterEvent(str2nr(expand(''<abuf>'')))',
129 \ 'BufReadPost * call ale#events#ReadOrEnterEvent(str2nr(expand(''<abuf>'')))',
130 \ 'BufWritePost * call ale#events#SaveEvent(str2nr(expand(''<abuf>'')))',
132 \ CheckAutocmd('ALEEvents')
134 Execute (The cursor hover event should be enabled with g:ale_hover_cursor = 1):
135 let g:ale_enabled = 1
136 let g:ale_completion_enabled = 0
137 let g:ale_echo_cursor = 0
138 let g:ale_fix_on_save = 0
139 let g:ale_lint_on_enter = 0
140 let g:ale_lint_on_filetype_changed = 0
141 let g:ale_lint_on_insert_leave = 0
142 let g:ale_lint_on_save = 0
143 let g:ale_lint_on_text_changed = 0
144 let g:ale_pattern_options_enabled = 0
145 let g:ale_hover_cursor = 1
149 \ 'BufEnter * call ale#events#ReadOrEnterEvent(str2nr(expand(''<abuf>'')))',
150 \ 'BufReadPost * call ale#events#ReadOrEnterEvent(str2nr(expand(''<abuf>'')))',
151 \ 'BufWritePost * call ale#events#SaveEvent(str2nr(expand(''<abuf>'')))',
152 \ 'CursorHold * if exists(''*ale#lsp#Send'') | call ale#hover#ShowTruncatedMessageAtCursor() | endif',
154 \ CheckAutocmd('ALEEvents')
156 Execute (g:ale_lint_on_text_changed = 1 bind both events):
157 let g:ale_lint_on_text_changed = 1
161 \ 'TextChanged * call ale#Queue(ale#Var(str2nr(expand(''<abuf>'')), ''lint_delay''))',
162 \ 'TextChangedI * call ale#Queue(ale#Var(str2nr(expand(''<abuf>'')), ''lint_delay''))',
164 \ filter(CheckAutocmd('ALEEvents'), 'v:val =~ ''^TextChanged''')
166 Execute (g:ale_lint_on_text_changed = 'always' should bind both events):
167 let g:ale_lint_on_text_changed = 'always'
171 \ 'TextChanged * call ale#Queue(ale#Var(str2nr(expand(''<abuf>'')), ''lint_delay''))',
172 \ 'TextChangedI * call ale#Queue(ale#Var(str2nr(expand(''<abuf>'')), ''lint_delay''))',
174 \ filter(CheckAutocmd('ALEEvents'), 'v:val =~ ''^TextChanged''')
176 Execute (g:ale_lint_on_text_changed = 'normal' should bind only TextChanged):
177 let g:ale_lint_on_text_changed = 'normal'
181 \ 'TextChanged * call ale#Queue(ale#Var(str2nr(expand(''<abuf>'')), ''lint_delay''))',
183 \ filter(CheckAutocmd('ALEEvents'), 'v:val =~ ''^TextChanged''')
185 Execute (g:ale_lint_on_text_changed = 'insert' should bind only TextChangedI):
186 let g:ale_lint_on_text_changed = 'insert'
190 \ 'TextChangedI * call ale#Queue(ale#Var(str2nr(expand(''<abuf>'')), ''lint_delay''))',
192 \ filter(CheckAutocmd('ALEEvents'), 'v:val =~ ''^TextChanged''')
194 Execute (g:ale_lint_on_insert_leave = 1 should bind InsertLeave or ModeChanged if available):
195 let g:ale_lint_on_insert_leave = 1
196 let g:ale_echo_cursor = 0
198 " CI at least should run this check.
199 " There isn't an easy way to save an restore a mapping during running the test.
200 if maparg("\<C-c>", 'i') isnot# '<Esc>' && !exists('##ModeChanged')
203 \ 'InsertEnter * call ale#events#InsertEnterEvent(str2nr(expand(''<abuf>'')))',
205 \ filter(CheckAutocmd('ALEEvents'), 'v:val =~ ''^InsertEnter''')
207 " If the ModeChanged event is available, starting the timer in InsertEnter is not necessary.
211 \ filter(CheckAutocmd('ALEEvents'), 'v:val =~ ''^InsertEnter''')
214 if !exists('##ModeChanged')
215 " If the ModeChanged event is not available, bind InsertLeave.
218 \ 'InsertLeave * call ale#events#InsertLeaveEvent(str2nr(expand(''<abuf>'')))',
220 \ filter(CheckAutocmd('ALEEvents'), 'v:val =~ ''^InsertLeave''')
224 \ 'ModeChanged i*:* call ale#events#InsertLeaveEvent(str2nr(expand(''<abuf>'')))',
226 \ filter(CheckAutocmd('ALEEvents'), 'v:val =~ ''^ModeChanged''')
229 Execute (g:ale_lint_on_filetype_changed = 1 should bind the FileType event):
230 let g:ale_lint_on_filetype_changed = 1
234 \ 'FileType * call ale#events#FileTypeEvent( '
235 \ . 'str2nr(expand(''<abuf>'')), '
236 \ . 'expand(''<amatch>'')'
239 \ filter(CheckAutocmd('ALEEvents'), 'v:val =~ ''\v^FileType''')
241 Execute (ALECleanupGroup should include the right commands):
242 if exists('##VimSuspend')
244 \ 'BufDelete * if exists(''*ale#engine#Cleanup'') | call ale#engine#Cleanup(str2nr(expand(''<abuf>''))) | endif',
245 \ 'QuitPre * call ale#events#QuitEvent(str2nr(expand(''<abuf>'')))',
246 \ 'VimSuspend * if exists(''*ale#engine#CleanupEveryBuffer'') | call ale#engine#CleanupEveryBuffer() | endif',
247 \], CheckAutocmd('ALECleanupGroup')
250 \ 'BufDelete * if exists(''*ale#engine#Cleanup'') | call ale#engine#Cleanup(str2nr(expand(''<abuf>''))) | endif',
251 \ 'QuitPre * call ale#events#QuitEvent(str2nr(expand(''<abuf>'')))',
252 \], CheckAutocmd('ALECleanupGroup')
255 Execute(ALECompletionActions should always be set up):
257 \ 'CompleteDone * call ale#completion#HandleUserData(v:completed_item)',
258 \], CheckAutocmd('ALECompletionActions')
260 Execute(Enabling completion should set up autocmd events correctly):
261 let g:ale_completion_enabled = 0
262 call ale#completion#Enable()
265 \ 'CompleteDone * call ale#completion#Done()',
266 \ 'TextChangedI * call ale#completion#Queue()',
267 \], CheckAutocmd('ALECompletionGroup')
268 AssertEqual 1, g:ale_completion_enabled
270 Execute(Disabling completion should remove autocmd events correctly):
271 let g:ale_completion_enabled = 1
272 call ale#completion#Enable()
273 call ale#completion#Disable()
275 AssertEqual [], CheckAutocmd('ALECompletionGroup')
276 AssertEqual 0, g:ale_completion_enabled
278 Execute(ALE should try to close the preview window on InsertEnter):
279 let g:ale_lint_on_insert_leave = 0
280 let g:ale_close_preview_on_insert = 1
284 \ 'InsertEnter * call ale#events#InsertEnterEvent(str2nr(expand(''<abuf>'')))',
286 \ filter(CheckAutocmd('ALEEvents'), 'v:val =~ ''^InsertEnter''')