diff options
author | w0rp <devw0rp@gmail.com> | 2017-05-20 18:56:44 +0100 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2017-05-20 19:02:36 +0100 |
commit | 3530180a73ec53c6c029926173c34e0d78a8ac70 (patch) | |
tree | 5ae4f51684b1b0f9d00c03aec22e8afa899e6858 /autoload | |
parent | 59d9f5d458036bb6a2fbb0d3c3e301f4717eb916 (diff) | |
download | ale-3530180a73ec53c6c029926173c34e0d78a8ac70.zip |
Suggest functions for fixing issues for ALEFix
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/fix.vim | 2 | ||||
-rw-r--r-- | autoload/ale/fix/registry.vim | 60 |
2 files changed, 61 insertions, 1 deletions
diff --git a/autoload/ale/fix.vim b/autoload/ale/fix.vim index 4ff977b5..e329693d 100644 --- a/autoload/ale/fix.vim +++ b/autoload/ale/fix.vim @@ -249,7 +249,7 @@ function! s:GetCallbacks() abort endfor if empty(l:callback_list) - echoerr 'No fixers have been defined for filetype: ' . &filetype + echoerr 'No fixers have been defined. Try :ALEFixSuggest' return [] endif diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index e524e136..b85c5d76 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -37,6 +37,11 @@ endfunction " Set up entries now. call ale#fix#registry#ResetToDefaults() +" Remove everything from the registry, useful for tests. +function! ale#fix#registry#Clear() abort + let s:entries = {} +endfunction + " Add a function for fixing problems to the registry. function! ale#fix#registry#Add(name, func, filetypes, desc) abort if type(a:name) != type('') @@ -72,3 +77,58 @@ endfunction function! ale#fix#registry#GetFunc(name) abort return get(s:entries, a:name, {'function': ''}).function endfunction + +function! s:ShouldSuggestForType(suggested_filetypes, type_list) abort + for l:type in a:type_list + if index(a:suggested_filetypes, l:type) >= 0 + return 1 + endif + endfor + + return 0 +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 + + 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) + endif + endfor + + + 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) + endif + endfor + + if l:first_for_filetype && l:first_generic + echom 'There is nothing in the registry to suggest.' + else + echom '' + echom 'See :help ale-fix-configuration' + endif +endfunction |