From 7cf3ddf6c4354db406a19104f352565d42a827d2 Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 8 Apr 2018 19:04:07 +0100 Subject: [PATCH] Close #1439 - Add an :ALEInfoToFile command --- .gitignore | 7 ++++--- autoload/ale/debugging.vim | 11 +++++++++++ doc/ale.txt | 3 +++ plugin/ale.vim | 2 ++ test/test_ale_info.vader | 31 +++++++++++++++++++++++++++++++ 5 files changed, 51 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 2a99180812..edb6293e9c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ -/init.vim -/doc/tags -.* !.editorconfig *.obj +.* +/doc/tags +/init.vim +/test/ale-info-test-file tags diff --git a/autoload/ale/debugging.vim b/autoload/ale/debugging.vim index cb93ec161c..bcfd467da6 100644 --- a/autoload/ale/debugging.vim +++ b/autoload/ale/debugging.vim @@ -211,3 +211,14 @@ function! ale#debugging#InfoToClipboard() abort call s:Echo('ALEInfo copied to your clipboard') endfunction + +function! ale#debugging#InfoToFile(filename) abort + let l:expanded_filename = expand(a:filename) + + redir => l:output + silent call ale#debugging#Info() + redir END + + call writefile(split(l:output, "\n"), l:expanded_filename) + call s:Echo('ALEInfo written to ' . l:expanded_filename) +endfunction diff --git a/doc/ale.txt b/doc/ale.txt index 97f1b59481..0d3053e246 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -1869,6 +1869,9 @@ ALEInfoToClipboard *ALEInfoToClipboard* The command `:ALEInfoToClipboard` can be used to output ALEInfo directly to your clipboard. This might not work on every machine. + `:ALEInfoToFile` will write the ALE runtime information to a given filename. + The filename works just like |:w|. + ALEReset *ALEReset* ALEResetBuffer *ALEResetBuffer* diff --git a/plugin/ale.vim b/plugin/ale.vim index 1aa3582698..56d5c4477c 100644 --- a/plugin/ale.vim +++ b/plugin/ale.vim @@ -259,6 +259,8 @@ command! -bar ALELint :call ale#Queue(0, 'lint_file') command! -bar ALEInfo :call ale#debugging#Info() " The same, but copy output to your clipboard. command! -bar ALEInfoToClipboard :call ale#debugging#InfoToClipboard() +" Copy ALE information to a file. +command! -bar -nargs=1 ALEInfoToFile :call ale#debugging#InfoToFile() " Fix problems in files. command! -bar ALEFix :call ale#fix#Fix() diff --git a/test/test_ale_info.vader b/test/test_ale_info.vader index 05c045bb80..8914507aca 100644 --- a/test/test_ale_info.vader +++ b/test/test_ale_info.vader @@ -105,6 +105,8 @@ Before: AssertEqual a:expected_list, split(l:output, "\n") endfunction + call ale#test#SetDirectory('/testplugin/test') + After: Restore @@ -123,6 +125,8 @@ After: unlet! g:ale_testft2_testlinter2_bar delfunction CheckInfo + call ale#test#RestoreDirectory() + Given nolintersft (Empty buffer with no linters): Execute (ALEInfo with no linters should return the right output): call CheckInfo([ @@ -251,6 +255,33 @@ Execute (ALEInfo should return appropriately named global variables): \ 'let g:ale_testft_testlinter1_foo = ''abc''', \] + g:globals_lines + g:command_header) +Execute (ALEInfoToFile should write to a file correctly): + if filereadable(g:dir . '/ale-info-test-file') + call delete(g:dir . '/ale-info-test-file') + endif + + 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) + + execute 'ALEInfoToFile ' . fnameescape(g:dir . '/ale-info-test-file') + + AssertEqual [ + \ ' Current Filetype: testft.testft2', + \ 'Available Linters: [''testlinter1'', ''testlinter2'']', + \ ' Enabled Linters: [''testlinter1'', ''testlinter2'']', + \ ' Linter Variables:', + \ '', + \ 'let g:ale_testft2_testlinter2_bar = {''x'': ''y''}', + \ 'let g:ale_testft2_testlinter2_foo = 123', + \ 'let g:ale_testft_testlinter1_bar = [''abc'']', + \ 'let g:ale_testft_testlinter1_foo = ''abc''', + \] + g:globals_lines + g:command_header, readfile(g:dir . '/ale-info-test-file') + Given testft.testft2 (Empty buffer with two filetypes): Execute (ALEInfo should buffer-local linter variables): let g:ale_testft2_testlinter2_foo = 123