Skip to content

Commit

Permalink
Close #3368 - Supercharge :ALEInfo
Browse files Browse the repository at this point in the history
Make a series of sweeping changes to make :ALEInfo more useful.

1. Deprecate :ALEInfoToClipboard and support :ALEInfo -clipboard
2. Permit :ALEInfo -clip as a shorthand for :ALEInfo -clipboard
3. Support :ALEInfo -preview to render in the preview window
4. Support :ALEInfo -echo for the classic :ALEInfo mode
5. Change the default mode to 'preview', and make it configurable
6. Add syntax highlighting for ALEInfo in preview mode
7. Add a convenience to look up documentatation that explains itself
8. Don't show an empty 'Linter Variables' section
  • Loading branch information
w0rp committed Sep 5, 2023
1 parent 551fbcf commit 14350db
Show file tree
Hide file tree
Showing 9 changed files with 225 additions and 103 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/report-a-bug.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Are you having trouble configuring ALE? Try asking for help on [Stack Exchange](
### :ALEInfo
<details>
<summary>Expand</summary>
<!-- Paste the output of :ALEInfo here. Try :ALEInfoToClipboard -->
<!-- Paste the output of :ALEInfo here. Try :ALEInfo -clipboard -->
<!-- Make sure to run :ALEInfo from the buffer where the bug occurred. -->
<!-- Read the output. You might figure out what went wrong yourself. -->
</details>
74 changes: 68 additions & 6 deletions autoload/ale/debugging.vim
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
" Author: w0rp <[email protected]>
" Description: This file implements debugging information for ALE

let g:ale_info_default_mode = get(g:, 'ale_info_default_mode', 'preview')

let s:global_variable_list = [
\ 'ale_cache_executable_check_failures',
\ 'ale_change_sign_column_color',
Expand All @@ -18,6 +20,7 @@ let s:global_variable_list = [
\ 'ale_fix_on_save',
\ 'ale_fixers',
\ 'ale_history_enabled',
\ 'ale_info_default_mode',
\ 'ale_history_log_output',
\ 'ale_keep_list_window_open',
\ 'ale_lint_delay',
Expand Down Expand Up @@ -199,7 +202,10 @@ function! s:EchoLSPErrorMessages(all_linter_names) abort
endfor
endfunction

function! ale#debugging#Info() abort
function! ale#debugging#Info(...) abort
let l:options = (a:0 > 0) ? a:1 : {}
let l:show_preview_info = get(l:options, 'preview')

let l:buffer = bufnr('')
let l:filetype = &filetype

Expand Down Expand Up @@ -241,13 +247,31 @@ function! ale#debugging#Info() abort
call s:EchoLinterAliases(l:all_linters)
call s:Echo(' Enabled Linters: ' . string(l:enabled_names))
call s:Echo(' Ignored Linters: ' . string(l:ignored_names))
call s:Echo(' Suggested Fixers: ' . l:fixers_string)
call s:Echo(' Linter Variables:')
call s:Echo('')
call s:EchoLinterVariables(l:variable_list)
call s:Echo(' Suggested Fixers:' . l:fixers_string)
" We use this line with only a space to know where to end highlights.
call s:Echo(' ')

" Only show Linter Variables directive if there are any.
if !empty(l:variable_list)
call s:Echo(' Linter Variables:')

if l:show_preview_info
call s:Echo('" Press Space to read :help for a setting')
endif

call s:EchoLinterVariables(l:variable_list)
" We use this line with only a space to know where to end highlights.
call s:Echo(' ')
endif

call s:Echo(' Global Variables:')
call s:Echo('')

if l:show_preview_info
call s:Echo('" Press Space to read :help for a setting')
endif

call s:EchoGlobalVariables()
call s:Echo(' ')
call s:EchoLSPErrorMessages(l:all_names)
call s:Echo(' Command History:')
call s:Echo('')
Expand Down Expand Up @@ -275,3 +299,41 @@ function! ale#debugging#InfoToFile(filename) abort
call writefile(split(l:output, "\n"), l:expanded_filename)
call s:Echo('ALEInfo written to ' . l:expanded_filename)
endfunction

function! ale#debugging#InfoToPreview() abort
let l:output = execute('call ale#debugging#Info({''preview'': 1})')

call ale#preview#Show(split(l:output, "\n"), {
\ 'filetype': 'ale-info',
\})
endfunction

function! ale#debugging#InfoCommand(...) abort
if len(a:000) > 1
" no-custom-checks
echom 'Invalid ALEInfo arguments!'

return
endif

" Get 'echo' from '-echo', if there's an argument.
let l:mode = get(a:000, '')[1:]

if empty(l:mode)
let l:mode = ale#Var(bufnr(''), 'info_default_mode')
endif

if l:mode is# 'echo'
call ale#debugging#Info()
elseif l:mode is# 'clip' || l:mode is# 'clipboard'
call ale#debugging#InfoToClipboard()
else
call ale#debugging#InfoToPreview()
endif
endfunction

function! ale#debugging#InfoToClipboardDeprecatedCommand() abort
" no-custom-checks
echom 'ALEInfoToClipboard is deprecated. Use ALEInfo -clipboard instead.'
call ale#debugging#InfoToClipboard()
endfunction
24 changes: 21 additions & 3 deletions doc/ale.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,15 @@ g:ale_hover_to_floating_preview *g:ale_hover_to_floating_preview*
hover messages.


g:ale_info_default_mode *g:ale_info_default_mode*
*b:ale_info_default_mode*
Type: |String|
Default: `'preview'`

Changes the default mode used for |ALEInfo|. See documentation for |ALEInfo|
for more information.


g:ale_keep_list_window_open *g:ale_keep_list_window_open*
*b:ale_keep_list_window_open*
Type: |Number|
Expand Down Expand Up @@ -3836,7 +3845,7 @@ ALEDetail *ALEDetail*

*:ALEInfo*
ALEInfo *ALEInfo*
ALEInfoToClipboard *ALEInfoToClipboard*
*ALEInfoToFile*

Print runtime information about ALE, including the values of global and
buffer-local settings for ALE, the linters that are enabled, the commands
Expand All @@ -3848,8 +3857,17 @@ ALEInfoToClipboard *ALEInfoToClipboard*
|g:ale_history_log_output| to `1` to enable logging of output for commands.
ALE will only log the output captured for parsing problems, etc.

The command `:ALEInfoToClipboard` can be used to output ALEInfo directly to
your clipboard. This might not work on every machine.
You can pass options to the command to control how ALE displays the
information, such as `:ALEInfo -echo`, etc. >
-preview Show the info in a preview window.
-clip OR -clipboard Copy the information to your clipboard.
-echo echo all of the information with :echo
<
The default mode can be configured with |g:ale_info_default_mode|.

When shown in a preview window, syntax highlights can be defined for the
`ale-info` filetype.

`:ALEInfoToFile` will write the ALE runtime information to a given filename.
The filename works just like |:w|.
Expand Down
16 changes: 16 additions & 0 deletions ftplugin/ale-info.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
" Close the ALEInfo preview window with the q key.
noremap <buffer> q :q!<CR>
" Explicitly use the default synmaxcol for ale-info.
setlocal synmaxcol=3000

function! ALEInfoOpenHelp() abort
let l:variable = matchstr(getline('.'), '\v[gb]:ale_[a-z0-9_]+')

if !empty(l:variable)
execute('help ' . l:variable)
endif
endfunction

" Press space to open :help for an ALE Variable
nnoremap <buffer> <silent> <space> :call ALEInfoOpenHelp()<CR>
10 changes: 7 additions & 3 deletions plugin/ale.vim
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ command! -bar ALEPopulateQuickfix :call ale#list#ForcePopulateErrorList(1)
command! -bar ALEPopulateLocList :call ale#list#ForcePopulateErrorList(0)

" Define a command to get information about current filetype.
command! -bar ALEInfo :call ale#debugging#Info()
" The same, but copy output to your clipboard.
command! -bar ALEInfoToClipboard :call ale#debugging#InfoToClipboard()
command! -bar -nargs=* ALEInfo :call ale#debugging#InfoCommand(<f-args>)
" Deprecated and scheduled for removal in 4.0.0.
command! -bar ALEInfoToClipboard :call ale#debugging#InfoToClipboardDeprecatedCommand()
" Copy ALE information to a file.
command! -bar -nargs=1 ALEInfoToFile :call ale#debugging#InfoToFile(<f-args>)

Expand Down Expand Up @@ -352,6 +352,10 @@ nnoremap <silent> <Plug>(ale_rename) :ALERename<Return>
nnoremap <silent> <Plug>(ale_filerename) :ALEFileRename<Return>
nnoremap <silent> <Plug>(ale_code_action) :ALECodeAction<Return>
nnoremap <silent> <Plug>(ale_repeat_selection) :ALERepeatSelection<Return>
nnoremap <silent> <Plug>(ale_info) :ALEInfo<Return>
nnoremap <silent> <Plug>(ale_info_echo) :ALEInfo -echo<Return>
nnoremap <silent> <Plug>(ale_info_clipboard) :ALEInfo -clipboard<Return>
nnoremap <silent> <Plug>(ale_info_preview) :ALEInfo -preview<Return>
" Set up autocmd groups now.
call ale#events#Init()
Expand Down
2 changes: 1 addition & 1 deletion syntax/ale-fix-suggest.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ if exists('b:current_syntax')
endif

syn match aleFixerComment /^.*$/
syn match aleFixerName /\(^\|, \)'[^']*'/
syn match aleFixerName /\(^ *\|, \)'[^']*'/
syn match aleFixerHelp /^See :help ale-fix-configuration/

hi def link aleFixerComment Comment
Expand Down
30 changes: 30 additions & 0 deletions syntax/ale-info.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
if exists('b:current_syntax')
finish
endif

" Exhaustively list different ALE Info directives to match here.
" This should hopefully avoid matching too eagerly.
syn match aleInfoDirective /^ *Current Filetype:/
syn match aleInfoDirective /^ *Available Linters:/
syn match aleInfoDirective /^ *Enabled Linters:/
syn match aleInfoDirective /^ *Ignored Linters:/
syn match aleInfoDirective /^ *Suggested Fixers:/
syn match aleInfoDirective /^ *Command History:/

syn match aleCommandNoOutput /^<<<NO OUTPUT RETURNED>>>$/

hi def link aleInfoDirective Title
hi def link aleInfoDirective Title
hi def link aleCommandNoOutput Comment

" Use Vim syntax highlighting for Vim options.
unlet! b:current_syntax
syntax include @srcVim syntax/vim.vim
syntax region aleInfoVimRegionLinter matchgroup=aleInfoDirective start="^ *Linter Variables:$" end="^ $" contains=@srcVim
syntax region aleInfoVimRegionGlobal matchgroup=aleInfoDirective start="^ *Global Variables:$" end="^ $" contains=@srcVim

unlet! b:current_syntax
syntax include @srcAleFixSuggest syntax/ale-fix-suggest.vim
syntax region aleInfoFixSuggestRegion matchgroup=aleInfoDirective start="^ *Suggested Fixers:$" end="^ $" contains=@srcAleFixSuggest

let b:current_syntax = 'ale-info'
Loading

0 comments on commit 14350db

Please sign in to comment.