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: w0rp <devw0rp@gmail.com>
2 " Description: This file implements debugging information for ALE
4 let g:ale_info_default_mode = get(g:, 'ale_info_default_mode', 'preview')
6 let s:global_variable_list = [
7 \ 'ale_cache_executable_check_failures',
8 \ 'ale_change_sign_column_color',
9 \ 'ale_command_wrapper',
10 \ 'ale_completion_delay',
11 \ 'ale_completion_enabled',
12 \ 'ale_completion_max_suggestions',
15 \ 'ale_echo_msg_error_str',
16 \ 'ale_echo_msg_format',
17 \ 'ale_echo_msg_info_str',
18 \ 'ale_echo_msg_warning_str',
22 \ 'ale_history_enabled',
23 \ 'ale_info_default_mode',
24 \ 'ale_history_log_output',
25 \ 'ale_keep_list_window_open',
27 \ 'ale_lint_on_enter',
28 \ 'ale_lint_on_filetype_changed',
29 \ 'ale_lint_on_insert_leave',
31 \ 'ale_lint_on_text_changed',
32 \ 'ale_linter_aliases',
34 \ 'ale_linters_explicit',
35 \ 'ale_linters_ignore',
36 \ 'ale_list_vertical',
37 \ 'ale_list_window_size',
38 \ 'ale_loclist_msg_format',
39 \ 'ale_max_buffer_history_size',
41 \ 'ale_maximum_file_size',
43 \ 'ale_pattern_options',
44 \ 'ale_pattern_options_enabled',
47 \ 'ale_set_highlights',
51 \ 'ale_sign_column_always',
55 \ 'ale_sign_style_error',
56 \ 'ale_sign_style_warning',
58 \ 'ale_sign_highlight_linenrs',
60 \ 'ale_use_neovim_diagnostics_api',
61 \ 'ale_use_global_executables',
62 \ 'ale_virtualtext_cursor',
63 \ 'ale_warn_about_trailing_blank_lines',
64 \ 'ale_warn_about_trailing_whitespace',
67 function! s:Echo(message) abort
72 function! s:GetLinterVariables(filetype, exclude_linter_names) abort
73 let l:variable_list = []
74 let l:filetype_parts = split(a:filetype, '\.')
77 " Extract variable names like: 'ale_python_flake8_executable'
78 let l:match = matchlist(l:key, '\v^ale_([^_]+)_([^_]+)_.+$')
80 " Include matching variables.
82 \&& index(l:filetype_parts, l:match[1]) >= 0
83 \&& index(a:exclude_linter_names, l:match[2]) == -1
84 call add(l:variable_list, l:key)
88 call sort(l:variable_list)
90 return l:variable_list
93 function! s:EchoLinterVariables(variable_list) abort
94 for l:key in a:variable_list
95 call s:Echo('let g:' . l:key . ' = ' . string(g:[l:key]))
98 call s:Echo('let b:' . l:key . ' = ' . string(b:[l:key]))
103 function! s:EchoGlobalVariables() abort
104 for l:key in s:global_variable_list
105 call s:Echo('let g:' . l:key . ' = ' . string(get(g:, l:key, v:null)))
107 if has_key(b:, l:key)
108 call s:Echo('let b:' . l:key . ' = ' . string(b:[l:key]))
113 " Echo a command that was run.
114 function! s:EchoCommand(item) abort
115 let l:status_message = a:item.status
117 " Include the exit code in output if we have it.
118 if a:item.status is# 'finished'
119 let l:status_message .= ' - exit code ' . a:item.exit_code
122 call s:Echo('(' . l:status_message . ') ' . string(a:item.command))
124 if g:ale_history_log_output && has_key(a:item, 'output')
125 if empty(a:item.output)
127 call s:Echo('<<<NO OUTPUT RETURNED>>>')
131 call s:Echo('<<<OUTPUT STARTS>>>')
133 for l:line in a:item.output
137 call s:Echo('<<<OUTPUT ENDS>>>')
143 " Echo the results of an executable check.
144 function! s:EchoExecutable(item) abort
146 \ '(executable check - %s) %s',
147 \ a:item.status ? 'success' : 'failure',
152 function! s:EchoCommandHistory() abort
153 let l:buffer = bufnr('%')
155 for l:item in ale#history#Get(l:buffer)
156 if l:item.job_id is# 'executable'
157 call s:EchoExecutable(l:item)
159 call s:EchoCommand(l:item)
164 function! s:EchoLinterAliases(all_linters) abort
167 for l:linter in a:all_linters
168 if !empty(l:linter.aliases)
170 call s:Echo(' Linter Aliases:')
175 call s:Echo(string(l:linter.name) . ' -> ' . string(l:linter.aliases))
180 function! s:EchoLSPErrorMessages(all_linter_names) abort
181 let l:lsp_error_messages = get(g:, 'ale_lsp_error_messages', {})
182 let l:header_echoed = 0
184 for l:linter_name in a:all_linter_names
185 let l:error_list = get(l:lsp_error_messages, l:linter_name, [])
187 if !empty(l:error_list)
189 call s:Echo(' LSP Error Messages:')
193 call s:Echo('(Errors for ' . l:linter_name . ')')
195 for l:message in l:error_list
196 for l:line in split(l:message, "\n")
204 function! s:GetIgnoredLinters(buffer, enabled_linters) abort
205 let l:filetype = &filetype
206 let l:ignore_config = ale#Var(a:buffer, 'linters_ignore')
207 let l:disable_lsp = ale#Var(a:buffer, 'disable_lsp')
210 \ !empty(l:ignore_config)
211 \ || l:disable_lsp is 1
212 \ || l:disable_lsp is v:true
213 \ || (l:disable_lsp is# 'auto' && get(g:, 'lspconfig', 0))
215 let l:non_ignored = ale#engine#ignore#Exclude(
222 let l:non_ignored = copy(a:enabled_linters)
225 call map(l:non_ignored, 'v:val.name')
228 \ copy(a:enabled_linters),
229 \ 'index(l:non_ignored, v:val.name) < 0'
233 function! ale#debugging#Info(...) abort
234 let l:options = (a:0 > 0) ? a:1 : {}
235 let l:show_preview_info = get(l:options, 'preview')
237 let l:buffer = bufnr('')
238 let l:filetype = &filetype
240 let l:enabled_linters = deepcopy(ale#linter#Get(l:filetype))
242 " But have to build the list of available linters ourselves.
243 let l:all_linters = []
244 let l:linter_variable_list = []
246 for l:part in split(l:filetype, '\.')
247 let l:aliased_filetype = ale#linter#ResolveFiletype(l:part)
248 call extend(l:all_linters, ale#linter#GetAll(l:aliased_filetype))
251 let l:all_names = map(copy(l:all_linters), 'v:val[''name'']')
252 let l:enabled_names = map(copy(l:enabled_linters), 'v:val[''name'']')
253 let l:exclude_names = filter(copy(l:all_names), 'index(l:enabled_names, v:val) == -1')
255 " Load linter variables to display
256 " This must be done after linters are loaded.
257 let l:variable_list = s:GetLinterVariables(l:filetype, l:exclude_names)
259 let l:fixers = ale#fix#registry#SuggestedFixers(l:filetype)
260 let l:fixers = uniq(sort(l:fixers[0] + l:fixers[1]))
261 let l:fixers_string = join(map(copy(l:fixers), '"\n " . v:val'), '')
263 " Get the names of ignored linters.
264 let l:ignored_names = map(
265 \ s:GetIgnoredLinters(l:buffer, l:enabled_linters),
269 call s:Echo(' Current Filetype: ' . l:filetype)
270 call s:Echo('Available Linters: ' . string(l:all_names))
271 call s:EchoLinterAliases(l:all_linters)
272 call s:Echo(' Enabled Linters: ' . string(l:enabled_names))
273 call s:Echo(' Ignored Linters: ' . string(l:ignored_names))
274 call s:Echo(' Suggested Fixers:' . l:fixers_string)
275 " We use this line with only a space to know where to end highlights.
278 " Only show Linter Variables directive if there are any.
279 if !empty(l:variable_list)
280 call s:Echo(' Linter Variables:')
282 if l:show_preview_info
283 call s:Echo('" Press Space to read :help for a setting')
286 call s:EchoLinterVariables(l:variable_list)
287 " We use this line with only a space to know where to end highlights.
291 call s:Echo(' Global Variables:')
293 if l:show_preview_info
294 call s:Echo('" Press Space to read :help for a setting')
297 call s:EchoGlobalVariables()
299 call s:EchoLSPErrorMessages(l:all_names)
300 call s:Echo(' Command History:')
302 call s:EchoCommandHistory()
305 function! ale#debugging#InfoToClipboard() abort
307 call s:Echo('clipboard not available. Try :ALEInfoToFile instead.')
312 let l:output = execute('call ale#debugging#Info()')
315 call s:Echo('ALEInfo copied to your clipboard')
318 function! ale#debugging#InfoToFile(filename) abort
319 let l:expanded_filename = expand(a:filename)
321 let l:output = execute('call ale#debugging#Info()')
323 call writefile(split(l:output, "\n"), l:expanded_filename)
324 call s:Echo('ALEInfo written to ' . l:expanded_filename)
327 function! ale#debugging#InfoToPreview() abort
328 let l:output = execute('call ale#debugging#Info({''preview'': 1})')
330 call ale#preview#Show(split(l:output, "\n"), {
331 \ 'filetype': 'ale-info',
335 function! ale#debugging#InfoCommand(...) abort
338 echom 'Invalid ALEInfo arguments!'
343 " Do not show info for the info window itself.
344 if &filetype is# 'ale-info'
348 " Get 'echo' from '-echo', if there's an argument.
349 let l:mode = get(a:000, '')[1:]
352 let l:mode = ale#Var(bufnr(''), 'info_default_mode')
356 call ale#debugging#Info()
357 elseif l:mode is# 'clip' || l:mode is# 'clipboard'
358 call ale#debugging#InfoToClipboard()
360 call ale#debugging#InfoToPreview()
364 function! ale#debugging#InfoToClipboardDeprecatedCommand() abort
366 echom 'ALEInfoToClipboard is deprecated. Use ALEInfo -clipboard instead.'
367 call ale#debugging#InfoToClipboard()