Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Close #1439 - Add an :ALEInfoToFile command
  • Loading branch information
w0rp committed Apr 8, 2018
1 parent 1123669 commit 7cf3ddf
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
7 changes: 4 additions & 3 deletions .gitignore
@@ -1,6 +1,7 @@
/init.vim
/doc/tags
.*
!.editorconfig
*.obj
.*
/doc/tags
/init.vim
/test/ale-info-test-file
tags
11 changes: 11 additions & 0 deletions autoload/ale/debugging.vim
Expand Up @@ -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
3 changes: 3 additions & 0 deletions doc/ale.txt
Expand Up @@ -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*
Expand Down
2 changes: 2 additions & 0 deletions plugin/ale.vim
Expand Up @@ -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(<f-args>)

" Fix problems in files.
command! -bar ALEFix :call ale#fix#Fix()
Expand Down
31 changes: 31 additions & 0 deletions test/test_ale_info.vader
Expand Up @@ -105,6 +105,8 @@ Before:
AssertEqual a:expected_list, split(l:output, "\n")
endfunction

call ale#test#SetDirectory('/testplugin/test')

After:
Restore

Expand All @@ -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([
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7cf3ddf

Please sign in to comment.