From 8846a8860f39027c0c2a7aba9e49ad2fdacd5428 Mon Sep 17 00:00:00 2001 From: w0rp Date: Wed, 28 Jun 2017 16:20:01 +0100 Subject: [PATCH] Use a new window for the ALEFixSuggest command, and document it better --- autoload/ale/fix/registry.vim | 60 ++++++++++++++++++++------------- doc/ale.txt | 14 +++++++- ftplugin/ale-fix-suggest.vim | 2 ++ syntax/ale-fix-suggest.vim | 13 +++++++ test/test_ale_fix_suggest.vader | 37 +++++++++++++++++--- 5 files changed, 96 insertions(+), 30 deletions(-) create mode 100644 ftplugin/ale-fix-suggest.vim create mode 100644 syntax/ale-fix-suggest.vim diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index 7219410d..0dbbc0c5 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -116,44 +116,56 @@ endfunction " Suggest functions to use from the registry. function! ale#fix#registry#Suggest(filetype) abort let l:type_list = split(a:filetype, '\.') - let l:first_for_filetype = 1 - let l:first_generic = 1 + let l:filetype_fixer_list = [] for l:key in sort(keys(s:entries)) let l:suggested_filetypes = s:entries[l:key].suggested_filetypes if s:ShouldSuggestForType(l:suggested_filetypes, l:type_list) - if l:first_for_filetype - let l:first_for_filetype = 0 - echom 'Try the following fixers appropriate for the filetype:' - echom '' - endif - - echom printf('%s - %s', string(l:key), s:entries[l:key].description) + call add( + \ l:filetype_fixer_list, + \ printf('%s - %s', string(l:key), s:entries[l:key].description), + \) endif endfor + let l:generic_fixer_list = [] for l:key in sort(keys(s:entries)) if empty(s:entries[l:key].suggested_filetypes) - if l:first_generic - if !l:first_for_filetype - echom '' - endif - - let l:first_generic = 0 - echom 'Try the following generic fixers:' - echom '' - endif - - echom printf('%s - %s', string(l:key), s:entries[l:key].description) + call add( + \ l:generic_fixer_list, + \ printf('%s - %s', string(l:key), s:entries[l:key].description), + \) endif endfor - if l:first_for_filetype && l:first_generic - echom 'There is nothing in the registry to suggest.' + let l:filetype_fixer_header = !empty(l:filetype_fixer_list) + \ ? ['Try the following fixers appropriate for the filetype:', ''] + \ : [] + let l:generic_fixer_header = !empty(l:generic_fixer_list) + \ ? ['Try the following generic fixers:', ''] + \ : [] + + let l:has_both_lists = !empty(l:filetype_fixer_list) && !empty(l:generic_fixer_list) + + let l:lines = + \ l:filetype_fixer_header + \ + l:filetype_fixer_list + \ + (l:has_both_lists ? [''] : []) + \ + l:generic_fixer_header + \ + l:generic_fixer_list + + if empty(l:lines) + let l:lines = ['There is nothing in the registry to suggest.'] else - echom '' - echom 'See :help ale-fix-configuration' + let l:lines += ['', 'See :help ale-fix-configuration'] endif + + let l:lines += ['', 'Press q to close this window'] + + new +set\ filetype=ale-fix-suggest + call setline(1, l:lines) + setlocal nomodified + setlocal nomodifiable endfunction diff --git a/doc/ale.txt b/doc/ale.txt index 88046227..81999ab0 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -131,7 +131,9 @@ ALE supports the following key features for linting: 7. Setting syntax highlights for errors. ALE can fix problems with files with the |ALEFix| command, using the same job -control functionality used for checking for problems. +control functionality used for checking for problems. Try using the +|ALEFixSuggest| command for browsing tools that can be used to fix problems +for the current buffer. =============================================================================== 2. Supported Languages & Tools *ale-support* @@ -915,6 +917,9 @@ run, the variable |g:ale_fixers| will be read for getting a |List| of commands for filetypes, split on `.`, and the functions named in |g:ale_fixers| will be executed for fixing the errors. +The |ALEFixSuggest| command can be used to suggest tools that be used to +fix problems for the current buffer. + The values for `g:ale_fixers` can be a list of |String|, |Funcref|, or |lambda| values. String values must either name a function, or a short name for a function set in the ALE fixer registry. @@ -1019,6 +1024,13 @@ ALEFix *ALEFix* A plug mapping `(ale_fix)` is defined for this command. +ALEFixSuggest *ALEFixSuggest* + + Suggest tools that can be used to fix problems in the current buffer. + + See |ale-fix| for more information. + + ALELint *ALELint* Run ALE once for the current buffer. This command can be used to run ALE diff --git a/ftplugin/ale-fix-suggest.vim b/ftplugin/ale-fix-suggest.vim new file mode 100644 index 00000000..189a4dc2 --- /dev/null +++ b/ftplugin/ale-fix-suggest.vim @@ -0,0 +1,2 @@ +" Close the ALEFixSuggest window with the q key. +noremap q :q! diff --git a/syntax/ale-fix-suggest.vim b/syntax/ale-fix-suggest.vim new file mode 100644 index 00000000..be3d45ee --- /dev/null +++ b/syntax/ale-fix-suggest.vim @@ -0,0 +1,13 @@ +if exists('b:current_syntax') + finish +endif + +syn match aleFixerComment /^.*$/ +syn match aleFixerName /^'[^']*'/ +syn match aleFixerHelp /^See :help ale-fix-configuration/ + +hi def link aleFixerComment Comment +hi def link aleFixerName String +hi def link aleFixerHelp Statement + +let b:current_syntax = 'ale-fix-suggest' diff --git a/test/test_ale_fix_suggest.vader b/test/test_ale_fix_suggest.vader index 9a7aecbf..97227b4f 100644 --- a/test/test_ale_fix_suggest.vader +++ b/test/test_ale_fix_suggest.vader @@ -1,15 +1,27 @@ Before: call ale#fix#registry#Clear() - function GetSuggestions() - redir => l:output - silent ALEFixSuggest - redir END + let g:buffer = bufnr('') - return split(l:output, "\n") + function GetSuggestions() + silent ALEFixSuggest + + if bufnr('') != g:buffer + let l:lines = getline(1, '$') + else + let l:lines = [] + endif + + return l:lines endfunction After: + if bufnr('') != g:buffer + :q! + endif + + unlet! g:buffer + call ale#fix#registry#ResetToDefaults() delfunction GetSuggestions @@ -17,9 +29,18 @@ Execute(ALEFixSuggest should return something sensible with no suggestions): AssertEqual \ [ \ 'There is nothing in the registry to suggest.', + \ '', + \ 'Press q to close this window', \ ], \ GetSuggestions() +Execute(ALEFixSuggest should set the appropriate settings): + silent ALEFixSuggest + + AssertEqual 'ale-fix-suggest', &filetype + Assert !&modified, 'The buffer was marked as modified' + Assert !&modifiable, 'The buffer was modifiable' + Execute(ALEFixSuggest output should be correct for only generic handlers): call ale#fix#registry#Add('zed', 'XYZ', [], 'Zedify things.') call ale#fix#registry#Add('alpha', 'XYZ', [], 'Alpha things.') @@ -32,6 +53,8 @@ Execute(ALEFixSuggest output should be correct for only generic handlers): \ '''zed'' - Zedify things.', \ '', \ 'See :help ale-fix-configuration', + \ '', + \ 'Press q to close this window', \ ], \ GetSuggestions() @@ -49,6 +72,8 @@ Execute(ALEFixSuggest output should be correct for only filetype handlers): \ '''zed'' - Zedify things.', \ '', \ 'See :help ale-fix-configuration', + \ '', + \ 'Press q to close this window', \ ], \ GetSuggestions() @@ -71,5 +96,7 @@ Execute(ALEFixSuggest should suggest filetype and generic handlers): \ '''generic'' - Generic things.', \ '', \ 'See :help ale-fix-configuration', + \ '', + \ 'Press q to close this window', \ ], \ GetSuggestions()