diff options
-rw-r--r-- | autoload/ale/debugging.vim | 59 | ||||
-rw-r--r-- | autoload/ale/linter.vim | 26 | ||||
-rw-r--r-- | plugin/ale.vim | 2 | ||||
-rw-r--r-- | test/test_ale_info.vader | 50 |
4 files changed, 105 insertions, 32 deletions
diff --git a/autoload/ale/debugging.vim b/autoload/ale/debugging.vim new file mode 100644 index 00000000..468b5038 --- /dev/null +++ b/autoload/ale/debugging.vim @@ -0,0 +1,59 @@ +" Author: w0rp <devw0rp@gmail.com> +" Description: This file implements debugging information for ALE + +function! s:GetLinterVariables(filetype, linter_names) abort + let l:variable_list = [] + let l:filetype_parts = split(a:filetype, '\.') + + for l:key in keys(g:) + " Extract variable names like: 'ale_python_flake8_executable' + let l:match = matchlist(l:key, '\v^ale_([^_]+)_([^_]+)_.+$') + + " Include matching variables. + if !empty(l:match) + \&& index(l:filetype_parts, l:match[1]) >= 0 + \&& index(a:linter_names, l:match[2]) >= 0 + call add(l:variable_list, l:key) + endif + endfor + + call sort(l:variable_list) + + return l:variable_list +endfunction + +function! s:EchoLinterVariables(variable_list) abort + for l:key in a:variable_list + echom 'let g:' . l:key . ' = ' . string(g:[l:key]) + endfor +endfunction + +function! ale#debugging#Info() abort + let l:filetype = &filetype + + " We get the list of enabled linters for free by the above function. + let l:enabled_linters = deepcopy(ale#linter#Get(l:filetype)) + + " But have to build the list of available linters ourselves. + let l:all_linters = [] + let l:linter_variable_list = [] + + for l:part in split(l:filetype, '\.') + let l:aliased_filetype = ale#linter#ResolveFiletype(l:part) + call extend(l:all_linters, ale#linter#GetAll(l:aliased_filetype)) + endfor + + let l:all_names = map(l:all_linters, 'v:val[''name'']') + let l:enabled_names = map(l:enabled_linters, 'v:val[''name'']') + + " Load linter variables to display + " This must be done after linters are loaded. + let l:variable_list = s:GetLinterVariables(l:filetype, l:enabled_names) + + echom ' Current Filetype: ' . l:filetype + echom 'Available Linters: ' . string(l:all_names) + echom ' Enabled Linters: ' . string(l:enabled_names) + echom ' Linter Variables:' + echom '' + call s:EchoLinterVariables(l:variable_list) +endfunction diff --git a/autoload/ale/linter.vim b/autoload/ale/linter.vim index 260c145b..e586c1f3 100644 --- a/autoload/ale/linter.vim +++ b/autoload/ale/linter.vim @@ -180,7 +180,7 @@ function! ale#linter#GetAll(filetype) abort return s:linters[a:filetype] endfunction -function! s:ResolveFiletype(original_filetype) abort +function! ale#linter#ResolveFiletype(original_filetype) abort " Try and get an aliased file type either from the user's Dictionary, or " our default Dictionary, otherwise use the filetype as-is. let l:filetype = get( @@ -201,7 +201,7 @@ function! ale#linter#Get(original_filetypes) abort " Handle dot-seperated filetypes. for l:original_filetype in split(a:original_filetypes, '\.') - let l:filetype = s:ResolveFiletype(l:original_filetype) + let l:filetype = ale#linter#ResolveFiletype(l:original_filetype) " Try and get a list of linters to run, using the original file type, " not the aliased filetype. We have some linters to limit by default, @@ -235,25 +235,3 @@ function! ale#linter#Get(original_filetypes) abort return l:combined_linters endfunction - -function! ale#linter#Info() abort - let l:original_filetypes = &filetype - - " We get the list of enabled linters for free by the above function. - let l:enabled_linters = deepcopy(ale#linter#Get(l:original_filetypes)) - - " But have to build the list of available linters ourselves. - let l:all_linters = [] - for l:original_filetype in split(l:original_filetypes, '\.') - let l:filetype = s:ResolveFiletype(l:original_filetype) - let l:filetype_linters = ale#linter#GetAll(l:filetype) - call extend(l:all_linters, l:filetype_linters) - endfor - - let l:all_names = map(l:all_linters, 'v:val[''name'']') - let l:enabled_names = map(l:enabled_linters, 'v:val[''name'']') - - echom ' Current Filetype: ' . l:original_filetypes - echom 'Available Linters: ' . string(l:all_names) - echom ' Enabled Linters: ' . string(l:enabled_names) -endfunction diff --git a/plugin/ale.vim b/plugin/ale.vim index 6afa603b..5f265c07 100644 --- a/plugin/ale.vim +++ b/plugin/ale.vim @@ -185,7 +185,7 @@ command! ALENextWrap :call ale#loclist_jumping#Jump('after', 1) command! ALEToggle :call s:ALEToggle() " Define command to get information about current filetype. -command! ALEInfo :call ale#linter#Info() +command! ALEInfo :call ale#debugging#Info() " <Plug> mappings for commands nnoremap <silent> <Plug>(ale_previous) :ALEPrevious<Return> diff --git a/test/test_ale_info.vader b/test/test_ale_info.vader index f8172c0c..3a319e12 100644 --- a/test/test_ale_info.vader +++ b/test/test_ale_info.vader @@ -17,7 +17,9 @@ Execute (ALEInfo with no linters should return the right output): AssertEqual "\n \ Current Filetype: nolintersft\n \Available Linters: []\n - \ Enabled Linters: []", g:output + \ Enabled Linters: []\n + \ Linter Variables:\n + \", g:output Given (Empty buffer with no filetype): Execute (ALEInfo with no filetype should return the right output): @@ -27,7 +29,9 @@ Execute (ALEInfo with no filetype should return the right output): AssertEqual "\n \ Current Filetype: \n \Available Linters: []\n - \ Enabled Linters: []", g:output + \ Enabled Linters: []\n + \ Linter Variables:\n + \", g:output Given testft (Empty buffer): Execute (ALEInfo with a single linter should return the right output): @@ -38,7 +42,9 @@ Execute (ALEInfo with a single linter should return the right output): AssertEqual "\n \ Current Filetype: testft\n \Available Linters: ['testlinter1']\n - \ Enabled Linters: ['testlinter1']", g:output + \ Enabled Linters: ['testlinter1']\n + \ Linter Variables:\n + \", g:output Given testft (Empty buffer): Execute (ALEInfo with two linters should return the right output): @@ -50,7 +56,9 @@ Execute (ALEInfo with two linters should return the right output): AssertEqual "\n \ Current Filetype: testft\n \Available Linters: ['testlinter1', 'testlinter2']\n - \ Enabled Linters: ['testlinter1', 'testlinter2']", g:output + \ Enabled Linters: ['testlinter1', 'testlinter2']\n + \ Linter Variables:\n + \", g:output Given testft (Empty buffer): Execute (ALEInfo should calculate enabled linters correctly): @@ -63,7 +71,9 @@ Execute (ALEInfo should calculate enabled linters correctly): AssertEqual "\n \ Current Filetype: testft\n \Available Linters: ['testlinter1', 'testlinter2']\n - \ Enabled Linters: ['testlinter2']", g:output + \ Enabled Linters: ['testlinter2']\n + \ Linter Variables:\n + \", g:output Given testft (Empty buffer): Execute (ALEInfo should only return linters for current filetype): @@ -75,7 +85,9 @@ Execute (ALEInfo should only return linters for current filetype): AssertEqual "\n \ Current Filetype: testft\n \Available Linters: ['testlinter1']\n - \ Enabled Linters: ['testlinter1']", g:output + \ Enabled Linters: ['testlinter1']\n + \ Linter Variables:\n + \", g:output Given testft.testft2 (Empty buffer with two filetypes): Execute (ALEInfo with compound filetypes should return linters for both of them): @@ -87,5 +99,29 @@ Execute (ALEInfo with compound filetypes should return linters for both of them) AssertEqual "\n \ Current Filetype: testft.testft2\n \Available Linters: ['testlinter1', 'testlinter2']\n - \ Enabled Linters: ['testlinter1', 'testlinter2']", g:output + \ Enabled Linters: ['testlinter1', 'testlinter2']\n + \ Linter Variables:\n + \", g:output +Given testft.testft2 (Empty buffer with two filetypes): +Execute (ALEInfo should return appropriately named global variables): + let g:ale_testft_testlinter1_foo = 'abc' + let g:ale_testft_testlinter1_bar = ['abc'] + let g:ale_testft2_testlinter2_foo = 123 + let g:ale_testft2_testlinter2_bar = {'x': 'y'} + + call ale#linter#Define('testft', g:testlinter1) + call ale#linter#Define('testft2', g:testlinter2) + redir => g:output + silent ALEInfo + redir END + AssertEqual "\n + \ Current Filetype: testft.testft2\n + \Available Linters: ['testlinter1', 'testlinter2']\n + \ Enabled Linters: ['testlinter1', 'testlinter2']\n + \ Linter Variables:\n + \\n + \let g:ale_testft2_testlinter2_bar = {'x': 'y'}\n + \let g:ale_testft2_testlinter2_foo = 123\n + \let g:ale_testft_testlinter1_bar = ['abc']\n + \let g:ale_testft_testlinter1_foo = 'abc'", g:output |