From 7f881f66a845ed8f056e5246e7cbbfc2e95bea07 Mon Sep 17 00:00:00 2001 From: jhlink Date: Fri, 10 Jul 2020 17:46:01 -0400 Subject: [PATCH 01/30] feat: Add ALE fixer for astyle --- autoload/ale/fixers/astyle.vim | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 autoload/ale/fixers/astyle.vim diff --git a/autoload/ale/fixers/astyle.vim b/autoload/ale/fixers/astyle.vim new file mode 100644 index 00000000..3ee48031 --- /dev/null +++ b/autoload/ale/fixers/astyle.vim @@ -0,0 +1,14 @@ +" Author: James Kim +" Description: Fix C/C++ files with astyle. + +call ale#Set('c_astyle_executable', 'astyle') + +function! ale#fixers#astyle#Fix(buffer) abort + let l:executable = ale#Var(a:buffer, 'c_astyle_executable') + + return { + \ 'command': ale#Escape(l:executable) + \ . ' %t', + \ 'read_temporary_file': 1, + \} +endfunction From 6c58164094ec5b2a4304af8f132d4eecb8e6ff5d Mon Sep 17 00:00:00 2001 From: jhlink Date: Fri, 10 Jul 2020 17:47:01 -0400 Subject: [PATCH 02/30] feat: Add astyle to fix/register.vim --- autoload/ale/fix/registry.vim | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index 1b3ca1a8..02b02699 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -160,6 +160,11 @@ let s:default_registry = { \ 'suggested_filetypes': ['php'], \ 'description': 'Fix PHP files with php-cs-fixer.', \ }, +\ 'astyle': { +\ 'function': 'ale#fixers#astyle#Fix', +\ 'suggested_filetypes': ['c', 'cpp'], +\ 'description': 'Fix C/C++ with astyle.', +\ }, \ 'clangtidy': { \ 'function': 'ale#fixers#clangtidy#Fix', \ 'suggested_filetypes': ['c', 'cpp', 'objc'], From 4394084d998397f3cc2203eb82b72affa3481645 Mon Sep 17 00:00:00 2001 From: jhlink Date: Fri, 10 Jul 2020 17:54:27 -0400 Subject: [PATCH 03/30] doc: Add astyle entry to ALE c integration --- doc/ale-c.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/doc/ale-c.txt b/doc/ale-c.txt index c9eb79db..7a6e71ea 100644 --- a/doc/ale-c.txt +++ b/doc/ale-c.txt @@ -59,6 +59,18 @@ g:ale_c_parse_makefile *g:ale_c_parse_makefile* build flags to use for different files. + +=============================================================================== +astyle *ale-c-astyle* + +g:ale_c_astyle_executable *g:ale_c_astyle_executable* + *b:ale_c_astyle_executable* + Type: |String| + Default: `'astyle'` + + This variable can be changed to use a different executable for astyle. + + =============================================================================== clang *ale-c-clang* From 8c0b9ecdfd8d91a76459e6dc7ccd0638f081a82f Mon Sep 17 00:00:00 2001 From: jhlink Date: Fri, 10 Jul 2020 17:56:02 -0400 Subject: [PATCH 04/30] doc: Add astyle to ale-c-options in ale-contents --- doc/ale.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/ale.txt b/doc/ale.txt index 724da57e..d5799f02 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -2284,6 +2284,7 @@ documented in additional help files. bib.....................................|ale-bib-options| bibclean..............................|ale-bib-bibclean| c.......................................|ale-c-options| + astyle................................|ale-c-astyle| clang.................................|ale-c-clang| clangd................................|ale-c-clangd| clang-format..........................|ale-c-clangformat| From 5dbbd2d18b0c06fca7590e4362d24c0494428e68 Mon Sep 17 00:00:00 2001 From: jhlink Date: Fri, 10 Jul 2020 17:59:14 -0400 Subject: [PATCH 05/30] doc: Add astyle to supported-tools.md --- supported-tools.md | 1 + 1 file changed, 1 insertion(+) diff --git a/supported-tools.md b/supported-tools.md index 7d2f5287..3c9f9ccb 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -53,6 +53,7 @@ formatting. * [shellcheck](https://www.shellcheck.net/) * [shfmt](https://github.com/mvdan/sh) * C + * [astyle](http://astyle.sourceforge.net/) * [ccls](https://github.com/MaskRay/ccls) * [clang](http://clang.llvm.org/) * [clangd](https://clang.llvm.org/extra/clangd.html) From 56b92544c2ec310165c9a6d504051a77042b1855 Mon Sep 17 00:00:00 2001 From: jhlink Date: Fri, 10 Jul 2020 18:16:12 -0400 Subject: [PATCH 06/30] doc: Add astyle to supported lang & tools --- doc/ale-supported-languages-and-tools.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index 45252294..7babf590 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -44,6 +44,7 @@ Notes: * `shellcheck` * `shfmt` * C + * `astyle` * `ccls` * `clang` * `clangd` From fecffeee91eb4670810d314ac5f97b2d776a675c Mon Sep 17 00:00:00 2001 From: jhlink Date: Fri, 10 Jul 2020 18:26:15 -0400 Subject: [PATCH 07/30] test: Add astyle vader test --- test/fixers/test_astyle_fixer_callback.vader | 23 ++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 test/fixers/test_astyle_fixer_callback.vader diff --git a/test/fixers/test_astyle_fixer_callback.vader b/test/fixers/test_astyle_fixer_callback.vader new file mode 100644 index 00000000..2fc57ad0 --- /dev/null +++ b/test/fixers/test_astyle_fixer_callback.vader @@ -0,0 +1,23 @@ +Before: + Save g:ale_c_astyle_executable + + " Use an invalid global executable, so we don't match it. + let g:ale_c_astyle_executable = 'xxxinvalid' + + call ale#test#SetDirectory('/testplugin/test/fixers') + +After: + Restore + + call ale#test#RestoreDirectory() + +Execute(The astyle callback should return the correct default values): + call ale#test#SetFilename('../c_files/testfile.c') + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': ale#Escape('xxxinvalid') + \ . ' %t', + \ }, + \ ale#fixers#astyle#Fix(bufnr('')) From 57423f13ecf066b7bc184405193f8b33883385df Mon Sep 17 00:00:00 2001 From: jhlink Date: Fri, 10 Jul 2020 18:59:29 -0400 Subject: [PATCH 08/30] style: Adjust spacing --- doc/ale-c.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/ale-c.txt b/doc/ale-c.txt index 7a6e71ea..1daf1256 100644 --- a/doc/ale-c.txt +++ b/doc/ale-c.txt @@ -59,7 +59,6 @@ g:ale_c_parse_makefile *g:ale_c_parse_makefile* build flags to use for different files. - =============================================================================== astyle *ale-c-astyle* From d0b7a6e71fb6293c104ff3a56cabcb5cfde9f065 Mon Sep 17 00:00:00 2001 From: jhlink Date: Fri, 10 Jul 2020 19:06:22 -0400 Subject: [PATCH 09/30] doc: Remove c++ from astyle --- autoload/ale/fix/registry.vim | 4 ++-- autoload/ale/fixers/astyle.vim | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index 02b02699..84da181e 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -162,8 +162,8 @@ let s:default_registry = { \ }, \ 'astyle': { \ 'function': 'ale#fixers#astyle#Fix', -\ 'suggested_filetypes': ['c', 'cpp'], -\ 'description': 'Fix C/C++ with astyle.', +\ 'suggested_filetypes': ['c'], +\ 'description': 'Fix C with astyle.', \ }, \ 'clangtidy': { \ 'function': 'ale#fixers#clangtidy#Fix', diff --git a/autoload/ale/fixers/astyle.vim b/autoload/ale/fixers/astyle.vim index 3ee48031..9a837396 100644 --- a/autoload/ale/fixers/astyle.vim +++ b/autoload/ale/fixers/astyle.vim @@ -1,5 +1,5 @@ " Author: James Kim -" Description: Fix C/C++ files with astyle. +" Description: Fix C files with astyle. call ale#Set('c_astyle_executable', 'astyle') From 076f9efbd951c91a36cb0b3c7421277746c1f3fd Mon Sep 17 00:00:00 2001 From: jhlink Date: Sat, 25 Jul 2020 20:20:47 -0400 Subject: [PATCH 10/30] feat: Add cpp support to astyle fixer --- autoload/ale/fixers/astyle.vim | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/autoload/ale/fixers/astyle.vim b/autoload/ale/fixers/astyle.vim index 9a837396..aea5cc8a 100644 --- a/autoload/ale/fixers/astyle.vim +++ b/autoload/ale/fixers/astyle.vim @@ -1,14 +1,27 @@ " Author: James Kim -" Description: Fix C files with astyle. +" Description: Fix C/C++ files with astyle. -call ale#Set('c_astyle_executable', 'astyle') +function! s:set_variables() abort + for l:ft in ['c', 'cpp'] + call ale#Set(l:ft . '_astyle_executable', 'astyle') + endfor +endfunction + +call s:set_variables() + +function! ale#fixers#astyle#Var(buffer, name) abort + let l:ft = getbufvar(str2nr(a:buffer), '&filetype') + let l:ft = l:ft =~# 'cpp' ? 'cpp' : 'c' + + return ale#Var(a:buffer, l:ft . '_astyle_' . a:name) +endfunction function! ale#fixers#astyle#Fix(buffer) abort - let l:executable = ale#Var(a:buffer, 'c_astyle_executable') + let l:executable = ale#fixers#astyle#Var(a:buffer, 'executable') + let l:command = ' %t' return { - \ 'command': ale#Escape(l:executable) - \ . ' %t', + \ 'command': ale#Escape(l:executable) . l:command, \ 'read_temporary_file': 1, \} endfunction From 488df0fa41be2c8d47a642b65964db7cba267d24 Mon Sep 17 00:00:00 2001 From: jhlink Date: Sat, 25 Jul 2020 20:22:10 -0400 Subject: [PATCH 11/30] feat: Add cpp to registry.vim --- autoload/ale/fix/registry.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index 84da181e..c5b4751b 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -162,7 +162,7 @@ let s:default_registry = { \ }, \ 'astyle': { \ 'function': 'ale#fixers#astyle#Fix', -\ 'suggested_filetypes': ['c'], +\ 'suggested_filetypes': ['c', 'cpp'], \ 'description': 'Fix C with astyle.', \ }, \ 'clangtidy': { From a2d172c4572e7805c14d71eedaed4b681db84d80 Mon Sep 17 00:00:00 2001 From: jhlink Date: Sat, 25 Jul 2020 20:32:06 -0400 Subject: [PATCH 12/30] doc: Add astyle to ale-cpp --- doc/ale-cpp.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/doc/ale-cpp.txt b/doc/ale-cpp.txt index ead3be28..ba7ea7fc 100644 --- a/doc/ale-cpp.txt +++ b/doc/ale-cpp.txt @@ -13,6 +13,17 @@ The following C options also apply to some C++ linters too. * |g:ale_c_parse_compile_commands| +=============================================================================== +astyle *ale-cpp-astyle* + +g:ale_cpp_astyle_executable *g:ale_cpp_astyle_executable* + *b:ale_cpp_astyle_executable* + Type: |String| + Default: `'astyle'` + + This variable can be changed to use a different executable for astyle. + + =============================================================================== clang *ale-cpp-clang* From 2987ebcfae5fe88888709a2a7cb3c4ce629fc0ed Mon Sep 17 00:00:00 2001 From: jhlink Date: Sat, 25 Jul 2020 20:34:03 -0400 Subject: [PATCH 13/30] feat: Add astyle to c++ in supported lang & tools --- doc/ale-supported-languages-and-tools.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index 7babf590..6e69b53b 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -62,6 +62,7 @@ Notes: * `mcsc`!! * `uncrustify` * C++ (filetype cpp) + * `astyle` * `ccls` * `clang` * `clangcheck`!! From ee466de7335e7b3d1cd78108a1a62f5b615f5807 Mon Sep 17 00:00:00 2001 From: jhlink Date: Sat, 25 Jul 2020 20:35:28 -0400 Subject: [PATCH 14/30] feat: Add astyle in c++ section in supported-tool --- supported-tools.md | 1 + 1 file changed, 1 insertion(+) diff --git a/supported-tools.md b/supported-tools.md index 3c9f9ccb..c6d9f795 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -71,6 +71,7 @@ formatting. * [mcsc](http://www.mono-project.com/docs/about-mono/languages/csharp/) :floppy_disk: see:`help ale-cs-mcsc` for details and configuration * [uncrustify](https://github.com/uncrustify/uncrustify) * C++ (filetype cpp) + * [astyle](http://astyle.sourceforge.net/) * [ccls](https://github.com/MaskRay/ccls) * [clang](http://clang.llvm.org/) * [clangcheck](http://clang.llvm.org/docs/ClangCheck.html) :floppy_disk: From 9316b7b3f2468035b5bd92fb47cb8fc840b88333 Mon Sep 17 00:00:00 2001 From: jhlink Date: Sat, 25 Jul 2020 20:34:03 -0400 Subject: [PATCH 15/30] doc: Add astyle to c++ in supported lang & tools --- doc/ale-supported-languages-and-tools.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index 7babf590..6e69b53b 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -62,6 +62,7 @@ Notes: * `mcsc`!! * `uncrustify` * C++ (filetype cpp) + * `astyle` * `ccls` * `clang` * `clangcheck`!! From 4fc59ccace281e80e5c688de2e4f805ddd9c5fec Mon Sep 17 00:00:00 2001 From: jhlink Date: Sat, 25 Jul 2020 20:35:28 -0400 Subject: [PATCH 16/30] doc: Add astyle in c++ section in supported-tool --- supported-tools.md | 1 + 1 file changed, 1 insertion(+) diff --git a/supported-tools.md b/supported-tools.md index 3c9f9ccb..c6d9f795 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -71,6 +71,7 @@ formatting. * [mcsc](http://www.mono-project.com/docs/about-mono/languages/csharp/) :floppy_disk: see:`help ale-cs-mcsc` for details and configuration * [uncrustify](https://github.com/uncrustify/uncrustify) * C++ (filetype cpp) + * [astyle](http://astyle.sourceforge.net/) * [ccls](https://github.com/MaskRay/ccls) * [clang](http://clang.llvm.org/) * [clangcheck](http://clang.llvm.org/docs/ClangCheck.html) :floppy_disk: From f26b2e7f011061ce08c659b3912f2025b804eb8b Mon Sep 17 00:00:00 2001 From: jhlink Date: Sat, 25 Jul 2020 20:37:19 -0400 Subject: [PATCH 17/30] doc: Add astyle to ale-cpp-options in ale.txt --- doc/ale.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/ale.txt b/doc/ale.txt index d5799f02..a9b39034 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -2307,6 +2307,7 @@ documented in additional help files. cmakelint.............................|ale-cmake-cmakelint| cmake-format..........................|ale-cmake-cmakeformat| cpp.....................................|ale-cpp-options| + astyle................................|ale-cpp-astyle| clang.................................|ale-cpp-clang| clangd................................|ale-cpp-clangd| clangcheck............................|ale-cpp-clangcheck| From a9799fe90e95468ce4d176206e3a59dd7f881fa7 Mon Sep 17 00:00:00 2001 From: jhlink Date: Sat, 25 Jul 2020 21:25:11 -0400 Subject: [PATCH 18/30] test: Add cpp test case for astyle --- test/fixers/test_astyle_fixer_callback.vader | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/fixers/test_astyle_fixer_callback.vader b/test/fixers/test_astyle_fixer_callback.vader index 2fc57ad0..9eb52788 100644 --- a/test/fixers/test_astyle_fixer_callback.vader +++ b/test/fixers/test_astyle_fixer_callback.vader @@ -21,3 +21,16 @@ Execute(The astyle callback should return the correct default values): \ . ' %t', \ }, \ ale#fixers#astyle#Fix(bufnr('')) + +Execute(The astyle callback should support cpp files): + call ale#test#SetFilename('../cpp_files/dummy.cpp') + let g:ale_cpp_astyle_executable = 'xxxinvalid' + set filetype=cpp " The test fails without this + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': ale#Escape('xxxinvalid') + \ . ' %t', + \ }, + \ ale#fixers#astyle#Fix(bufnr('')) From b25bb64a4d31a343ec210c01146791a5acd3bb99 Mon Sep 17 00:00:00 2001 From: jhlink Date: Sun, 26 Jul 2020 20:51:41 -0400 Subject: [PATCH 19/30] feat: Use stdin/redirection for astyle --- autoload/ale/fixers/astyle.vim | 6 +++--- test/fixers/test_astyle_fixer_callback.vader | 15 ++++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/autoload/ale/fixers/astyle.vim b/autoload/ale/fixers/astyle.vim index aea5cc8a..236c97f1 100644 --- a/autoload/ale/fixers/astyle.vim +++ b/autoload/ale/fixers/astyle.vim @@ -18,10 +18,10 @@ endfunction function! ale#fixers#astyle#Fix(buffer) abort let l:executable = ale#fixers#astyle#Var(a:buffer, 'executable') - let l:command = ' %t' + let l:filename = ale#Escape(bufname(a:buffer)) + let l:command = ' --stdin=' . l:filename return { - \ 'command': ale#Escape(l:executable) . l:command, - \ 'read_temporary_file': 1, + \ 'command': ale#Escape(l:executable) . l:command \} endfunction diff --git a/test/fixers/test_astyle_fixer_callback.vader b/test/fixers/test_astyle_fixer_callback.vader index 9eb52788..fc481d95 100644 --- a/test/fixers/test_astyle_fixer_callback.vader +++ b/test/fixers/test_astyle_fixer_callback.vader @@ -3,6 +3,7 @@ Before: " Use an invalid global executable, so we don't match it. let g:ale_c_astyle_executable = 'xxxinvalid' + let g:ale_cpp_astyle_executable = 'invalidpp' call ale#test#SetDirectory('/testplugin/test/fixers') @@ -13,24 +14,24 @@ After: Execute(The astyle callback should return the correct default values): call ale#test#SetFilename('../c_files/testfile.c') + let targetfile = '/testplugin/test/c_files/testfile.c' AssertEqual \ { - \ 'read_temporary_file': 1, - \ 'command': ale#Escape('xxxinvalid') - \ . ' %t', + \ 'command': ale#Escape(g:ale_c_astyle_executable) + \ . ' --stdin=' . ale#Escape(targetfile) \ }, \ ale#fixers#astyle#Fix(bufnr('')) Execute(The astyle callback should support cpp files): call ale#test#SetFilename('../cpp_files/dummy.cpp') - let g:ale_cpp_astyle_executable = 'xxxinvalid' + let targetfile = '/testplugin/test/cpp_files/dummy.cpp' set filetype=cpp " The test fails without this AssertEqual \ { - \ 'read_temporary_file': 1, - \ 'command': ale#Escape('xxxinvalid') - \ . ' %t', + \ 'command': ale#Escape(g:ale_cpp_astyle_executable) + \ . ' --stdin=' . ale#Escape(targetfile) \ }, \ ale#fixers#astyle#Fix(bufnr('')) + From 78295024e1ecb01990eb87c702e0c8565865e898 Mon Sep 17 00:00:00 2001 From: jhlink Date: Sun, 26 Jul 2020 21:11:37 -0400 Subject: [PATCH 20/30] feat: Add project option file support for astyle --- autoload/ale/fixers/astyle.vim | 3 +++ test/fixers/test_astyle_fixer_callback.vader | 28 ++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/autoload/ale/fixers/astyle.vim b/autoload/ale/fixers/astyle.vim index 236c97f1..f5133eb6 100644 --- a/autoload/ale/fixers/astyle.vim +++ b/autoload/ale/fixers/astyle.vim @@ -4,6 +4,7 @@ function! s:set_variables() abort for l:ft in ['c', 'cpp'] call ale#Set(l:ft . '_astyle_executable', 'astyle') + call ale#Set(l:ft . '_astyle_options', '') endfor endfunction @@ -19,9 +20,11 @@ endfunction function! ale#fixers#astyle#Fix(buffer) abort let l:executable = ale#fixers#astyle#Var(a:buffer, 'executable') let l:filename = ale#Escape(bufname(a:buffer)) + let l:options = ale#fixers#astyle#Var(a:buffer, 'options') let l:command = ' --stdin=' . l:filename return { \ 'command': ale#Escape(l:executable) . l:command + \ . (empty(l:options) ? '' : ' --project=' . l:options) \} endfunction diff --git a/test/fixers/test_astyle_fixer_callback.vader b/test/fixers/test_astyle_fixer_callback.vader index fc481d95..2cbbcacd 100644 --- a/test/fixers/test_astyle_fixer_callback.vader +++ b/test/fixers/test_astyle_fixer_callback.vader @@ -1,5 +1,6 @@ Before: Save g:ale_c_astyle_executable + Save g:ale_c_astyle_options " Use an invalid global executable, so we don't match it. let g:ale_c_astyle_executable = 'xxxinvalid' @@ -35,3 +36,30 @@ Execute(The astyle callback should support cpp files): \ }, \ ale#fixers#astyle#Fix(bufnr('')) +Execute(The astyle callback should support cpp files with option file set): + call ale#test#SetFilename('../cpp_files/dummy.cpp') + let g:ale_cpp_astyle_options = '.astylerc_cpp' + let targetfile = '/testplugin/test/cpp_files/dummy.cpp' + set filetype=cpp " The test fails without this + + AssertEqual + \ { + \ 'command': ale#Escape('invalidpp') + \ . ' --stdin=' . ale#Escape(targetfile) + \ . ' --project=' . g:ale_cpp_astyle_options + \ }, + \ ale#fixers#astyle#Fix(bufnr('')) + + +Execute(The astyle callback should return the correct default values with an option file set): + call ale#test#SetFilename('../c_files/testfile.c') + let targetfile = '/testplugin/test/c_files/testfile.c' + let g:ale_c_astyle_options = '.astylerc' + + AssertEqual + \ { + \ 'command': ale#Escape('xxxinvalid') + \ . ' --stdin=' . ale#Escape(targetfile) + \ . ' --project=' . g:ale_c_astyle_options + \ }, + \ ale#fixers#astyle#Fix(bufnr('')) From c38b2a652489eec31dc6674e4c090364c3e437fa Mon Sep 17 00:00:00 2001 From: jhlink Date: Sun, 26 Jul 2020 21:21:38 -0400 Subject: [PATCH 21/30] doc: Add ale_c_astyle_options in ale-c --- doc/ale-c.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/doc/ale-c.txt b/doc/ale-c.txt index 1daf1256..599a726f 100644 --- a/doc/ale-c.txt +++ b/doc/ale-c.txt @@ -70,6 +70,19 @@ g:ale_c_astyle_executable *g:ale_c_astyle_executable* This variable can be changed to use a different executable for astyle. +g:ale_c_astyle_options *g:ale_c_astyle_options* + *b:ale_c_astyle_options* + Type: |String| + Default: `''` + + This variable can be changed to use an option file for project level + configurations. Provide only the filename of the option file that should be + present at the project's root directory. + + For example, if .astylrc is specified, the file is searched in the parent + directories of the source file's directory. + + =============================================================================== clang *ale-c-clang* From 028485b4dee89d3a81a7b414d44b9864f7396cbb Mon Sep 17 00:00:00 2001 From: jhlink Date: Sun, 26 Jul 2020 21:22:17 -0400 Subject: [PATCH 22/30] doc: Add ale_cpp_astyle_options in ale-cpp --- doc/ale-cpp.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/doc/ale-cpp.txt b/doc/ale-cpp.txt index ba7ea7fc..206a1a87 100644 --- a/doc/ale-cpp.txt +++ b/doc/ale-cpp.txt @@ -24,6 +24,19 @@ g:ale_cpp_astyle_executable *g:ale_cpp_astyle_executable* This variable can be changed to use a different executable for astyle. +g:ale_cpp_astyle_options *g:ale_cpp_astyle_options* + *b:ale_cpp_astyle_options* + Type: |String| + Default: `''` + + This variable can be changed to use an option file for project level + configurations. Provide only the filename of the option file that should be + present at the project's root directory. + + For example, if .astylrc is specified, the file is searched in the parent + directories of the source file's directory. + + =============================================================================== clang *ale-cpp-clang* From 75723e4522a7787c3c5893ffa58ed3dc493c0bbc Mon Sep 17 00:00:00 2001 From: jhlink Date: Sun, 26 Jul 2020 21:25:17 -0400 Subject: [PATCH 23/30] doc: Add C++ desc in astyle entry in registry --- autoload/ale/fix/registry.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index c5b4751b..02b02699 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -163,7 +163,7 @@ let s:default_registry = { \ 'astyle': { \ 'function': 'ale#fixers#astyle#Fix', \ 'suggested_filetypes': ['c', 'cpp'], -\ 'description': 'Fix C with astyle.', +\ 'description': 'Fix C/C++ with astyle.', \ }, \ 'clangtidy': { \ 'function': 'ale#fixers#clangtidy#Fix', From 0e6578cf65a747ab6f8443493374a52b7d9060a8 Mon Sep 17 00:00:00 2001 From: jhlink Date: Sun, 26 Jul 2020 22:02:32 -0400 Subject: [PATCH 24/30] fix: Remove explicit calls to file path in astyle --- autoload/ale/fixers/astyle.vim | 5 +++-- test/fixers/test_astyle_fixer_callback.vader | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/autoload/ale/fixers/astyle.vim b/autoload/ale/fixers/astyle.vim index f5133eb6..304c2f24 100644 --- a/autoload/ale/fixers/astyle.vim +++ b/autoload/ale/fixers/astyle.vim @@ -21,10 +21,11 @@ function! ale#fixers#astyle#Fix(buffer) abort let l:executable = ale#fixers#astyle#Var(a:buffer, 'executable') let l:filename = ale#Escape(bufname(a:buffer)) let l:options = ale#fixers#astyle#Var(a:buffer, 'options') - let l:command = ' --stdin=' . l:filename + let l:command = ' --stdin=' return { - \ 'command': ale#Escape(l:executable) . l:command + \ 'command': ale#Escape(l:executable) \ . (empty(l:options) ? '' : ' --project=' . l:options) + \ . l:command \} endfunction diff --git a/test/fixers/test_astyle_fixer_callback.vader b/test/fixers/test_astyle_fixer_callback.vader index 2cbbcacd..d3520932 100644 --- a/test/fixers/test_astyle_fixer_callback.vader +++ b/test/fixers/test_astyle_fixer_callback.vader @@ -20,7 +20,7 @@ Execute(The astyle callback should return the correct default values): AssertEqual \ { \ 'command': ale#Escape(g:ale_c_astyle_executable) - \ . ' --stdin=' . ale#Escape(targetfile) + \ . ' --stdin=' \ }, \ ale#fixers#astyle#Fix(bufnr('')) @@ -32,7 +32,7 @@ Execute(The astyle callback should support cpp files): AssertEqual \ { \ 'command': ale#Escape(g:ale_cpp_astyle_executable) - \ . ' --stdin=' . ale#Escape(targetfile) + \ . ' --stdin=' \ }, \ ale#fixers#astyle#Fix(bufnr('')) @@ -45,8 +45,8 @@ Execute(The astyle callback should support cpp files with option file set): AssertEqual \ { \ 'command': ale#Escape('invalidpp') - \ . ' --stdin=' . ale#Escape(targetfile) \ . ' --project=' . g:ale_cpp_astyle_options + \ . ' --stdin=' \ }, \ ale#fixers#astyle#Fix(bufnr('')) @@ -59,7 +59,7 @@ Execute(The astyle callback should return the correct default values with an opt AssertEqual \ { \ 'command': ale#Escape('xxxinvalid') - \ . ' --stdin=' . ale#Escape(targetfile) \ . ' --project=' . g:ale_c_astyle_options + \ . ' --stdin=' \ }, \ ale#fixers#astyle#Fix(bufnr('')) From 5377272d2068b78f357795ebf1e0895cfbf0cfaf Mon Sep 17 00:00:00 2001 From: jhlink Date: Tue, 28 Jul 2020 19:48:27 -0400 Subject: [PATCH 25/30] fix: Change _options to _project_options --- autoload/ale/fixers/astyle.vim | 5 +++-- doc/ale-c.txt | 8 ++++---- doc/ale-cpp.txt | 8 ++++---- test/fixers/test_astyle_fixer_callback.vader | 12 ++++++------ 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/autoload/ale/fixers/astyle.vim b/autoload/ale/fixers/astyle.vim index 304c2f24..ba4ddceb 100644 --- a/autoload/ale/fixers/astyle.vim +++ b/autoload/ale/fixers/astyle.vim @@ -4,12 +4,13 @@ function! s:set_variables() abort for l:ft in ['c', 'cpp'] call ale#Set(l:ft . '_astyle_executable', 'astyle') - call ale#Set(l:ft . '_astyle_options', '') + call ale#Set(l:ft . '_astyle_project_options', '') endfor endfunction call s:set_variables() + function! ale#fixers#astyle#Var(buffer, name) abort let l:ft = getbufvar(str2nr(a:buffer), '&filetype') let l:ft = l:ft =~# 'cpp' ? 'cpp' : 'c' @@ -20,7 +21,7 @@ endfunction function! ale#fixers#astyle#Fix(buffer) abort let l:executable = ale#fixers#astyle#Var(a:buffer, 'executable') let l:filename = ale#Escape(bufname(a:buffer)) - let l:options = ale#fixers#astyle#Var(a:buffer, 'options') + let l:options = ale#fixers#astyle#Var(a:buffer, 'project_options') let l:command = ' --stdin=' return { diff --git a/doc/ale-c.txt b/doc/ale-c.txt index 599a726f..efc26f93 100644 --- a/doc/ale-c.txt +++ b/doc/ale-c.txt @@ -70,17 +70,17 @@ g:ale_c_astyle_executable *g:ale_c_astyle_executable* This variable can be changed to use a different executable for astyle. -g:ale_c_astyle_options *g:ale_c_astyle_options* - *b:ale_c_astyle_options* +g:ale_c_astyle_project_options *g:ale_c_astyle_project_options* + *b:ale_c_astyle_project_options* Type: |String| Default: `''` This variable can be changed to use an option file for project level configurations. Provide only the filename of the option file that should be - present at the project's root directory. + present at the project's root directory. For example, if .astylrc is specified, the file is searched in the parent - directories of the source file's directory. + directories of the source file's directory. =============================================================================== diff --git a/doc/ale-cpp.txt b/doc/ale-cpp.txt index 206a1a87..fbe31370 100644 --- a/doc/ale-cpp.txt +++ b/doc/ale-cpp.txt @@ -24,17 +24,17 @@ g:ale_cpp_astyle_executable *g:ale_cpp_astyle_executable* This variable can be changed to use a different executable for astyle. -g:ale_cpp_astyle_options *g:ale_cpp_astyle_options* - *b:ale_cpp_astyle_options* +g:ale_cpp_astyle_project_options *g:ale_cpp_astyle_project_options* + *b:ale_cpp_astyle_project_options* Type: |String| Default: `''` This variable can be changed to use an option file for project level configurations. Provide only the filename of the option file that should be - present at the project's root directory. + present at the project's root directory. For example, if .astylrc is specified, the file is searched in the parent - directories of the source file's directory. + directories of the source file's directory. =============================================================================== diff --git a/test/fixers/test_astyle_fixer_callback.vader b/test/fixers/test_astyle_fixer_callback.vader index d3520932..d2886202 100644 --- a/test/fixers/test_astyle_fixer_callback.vader +++ b/test/fixers/test_astyle_fixer_callback.vader @@ -1,11 +1,11 @@ Before: Save g:ale_c_astyle_executable - Save g:ale_c_astyle_options + Save g:ale_c_astyle_project_options " Use an invalid global executable, so we don't match it. let g:ale_c_astyle_executable = 'xxxinvalid' let g:ale_cpp_astyle_executable = 'invalidpp' - + call ale#test#SetDirectory('/testplugin/test/fixers') After: @@ -38,14 +38,14 @@ Execute(The astyle callback should support cpp files): Execute(The astyle callback should support cpp files with option file set): call ale#test#SetFilename('../cpp_files/dummy.cpp') - let g:ale_cpp_astyle_options = '.astylerc_cpp' + let g:ale_cpp_astyle_project_options = '.astylerc_cpp' let targetfile = '/testplugin/test/cpp_files/dummy.cpp' set filetype=cpp " The test fails without this AssertEqual \ { \ 'command': ale#Escape('invalidpp') - \ . ' --project=' . g:ale_cpp_astyle_options + \ . ' --project=' . g:ale_cpp_astyle_project_options \ . ' --stdin=' \ }, \ ale#fixers#astyle#Fix(bufnr('')) @@ -54,12 +54,12 @@ Execute(The astyle callback should support cpp files with option file set): Execute(The astyle callback should return the correct default values with an option file set): call ale#test#SetFilename('../c_files/testfile.c') let targetfile = '/testplugin/test/c_files/testfile.c' - let g:ale_c_astyle_options = '.astylerc' + let g:ale_c_astyle_project_options = '.astylerc' AssertEqual \ { \ 'command': ale#Escape('xxxinvalid') - \ . ' --project=' . g:ale_c_astyle_options + \ . ' --project=' . g:ale_c_astyle_project_options \ . ' --stdin=' \ }, \ ale#fixers#astyle#Fix(bufnr('')) From a9b2f6362d45bef8cd05de29dd83ebb6c148f408 Mon Sep 17 00:00:00 2001 From: jhlink Date: Tue, 28 Jul 2020 23:26:49 -0400 Subject: [PATCH 26/30] chore: Delete dead test code --- test/fixers/test_astyle_fixer_callback.vader | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/fixers/test_astyle_fixer_callback.vader b/test/fixers/test_astyle_fixer_callback.vader index d2886202..f67ab5e2 100644 --- a/test/fixers/test_astyle_fixer_callback.vader +++ b/test/fixers/test_astyle_fixer_callback.vader @@ -15,7 +15,6 @@ After: Execute(The astyle callback should return the correct default values): call ale#test#SetFilename('../c_files/testfile.c') - let targetfile = '/testplugin/test/c_files/testfile.c' AssertEqual \ { @@ -26,7 +25,6 @@ Execute(The astyle callback should return the correct default values): Execute(The astyle callback should support cpp files): call ale#test#SetFilename('../cpp_files/dummy.cpp') - let targetfile = '/testplugin/test/cpp_files/dummy.cpp' set filetype=cpp " The test fails without this AssertEqual @@ -39,7 +37,6 @@ Execute(The astyle callback should support cpp files): Execute(The astyle callback should support cpp files with option file set): call ale#test#SetFilename('../cpp_files/dummy.cpp') let g:ale_cpp_astyle_project_options = '.astylerc_cpp' - let targetfile = '/testplugin/test/cpp_files/dummy.cpp' set filetype=cpp " The test fails without this AssertEqual @@ -50,10 +47,8 @@ Execute(The astyle callback should support cpp files with option file set): \ }, \ ale#fixers#astyle#Fix(bufnr('')) - Execute(The astyle callback should return the correct default values with an option file set): call ale#test#SetFilename('../c_files/testfile.c') - let targetfile = '/testplugin/test/c_files/testfile.c' let g:ale_c_astyle_project_options = '.astylerc' AssertEqual From 7d40d0a16f29370f68fafe4c4814796e4eb260a0 Mon Sep 17 00:00:00 2001 From: jhlink Date: Tue, 28 Jul 2020 23:28:25 -0400 Subject: [PATCH 27/30] chore: Distinguish test value name --- test/fixers/test_astyle_fixer_callback.vader | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fixers/test_astyle_fixer_callback.vader b/test/fixers/test_astyle_fixer_callback.vader index f67ab5e2..f64c6784 100644 --- a/test/fixers/test_astyle_fixer_callback.vader +++ b/test/fixers/test_astyle_fixer_callback.vader @@ -49,7 +49,7 @@ Execute(The astyle callback should support cpp files with option file set): Execute(The astyle callback should return the correct default values with an option file set): call ale#test#SetFilename('../c_files/testfile.c') - let g:ale_c_astyle_project_options = '.astylerc' + let g:ale_c_astyle_project_options = '.astylerc_c' AssertEqual \ { From f4cff3bc06e35a1d5861972d9e1cea615255e989 Mon Sep 17 00:00:00 2001 From: jhlink Date: Tue, 28 Jul 2020 23:29:19 -0400 Subject: [PATCH 28/30] test: Set empty values for astyle project_options --- test/fixers/test_astyle_fixer_callback.vader | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/fixers/test_astyle_fixer_callback.vader b/test/fixers/test_astyle_fixer_callback.vader index f64c6784..60a18213 100644 --- a/test/fixers/test_astyle_fixer_callback.vader +++ b/test/fixers/test_astyle_fixer_callback.vader @@ -1,10 +1,13 @@ Before: Save g:ale_c_astyle_executable Save g:ale_c_astyle_project_options + Save g:ale_cpp_astyle_project_options " Use an invalid global executable, so we don't match it. let g:ale_c_astyle_executable = 'xxxinvalid' let g:ale_cpp_astyle_executable = 'invalidpp' + let g:ale_c_astyle_project_options = '' + let g:ale_cpp_astyle_project_options = '' call ale#test#SetDirectory('/testplugin/test/fixers') @@ -14,6 +17,8 @@ After: call ale#test#RestoreDirectory() Execute(The astyle callback should return the correct default values): + " Because this file doesn't exist, no astylrc config + " exists near it. Therefore, project_options is empty. call ale#test#SetFilename('../c_files/testfile.c') AssertEqual @@ -24,6 +29,8 @@ Execute(The astyle callback should return the correct default values): \ ale#fixers#astyle#Fix(bufnr('')) Execute(The astyle callback should support cpp files): + " Because this file doesn't exist, no astylrc config + " exists near it. Therefore, project_options is empty. call ale#test#SetFilename('../cpp_files/dummy.cpp') set filetype=cpp " The test fails without this From 428c5f94dab423d4d1af0ef46d51999d2142e1eb Mon Sep 17 00:00:00 2001 From: jhlink Date: Wed, 29 Jul 2020 01:36:45 -0400 Subject: [PATCH 29/30] fix: Use ALE to reliably find project options --- autoload/ale/fixers/astyle.vim | 33 +++++++++++++++++-- test/fixers/test_astyle_fixer_callback.vader | 11 +++++++ .../makefile_project/_astylerc | 0 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 test/test_c_projects/makefile_project/_astylerc diff --git a/autoload/ale/fixers/astyle.vim b/autoload/ale/fixers/astyle.vim index ba4ddceb..0abceb10 100644 --- a/autoload/ale/fixers/astyle.vim +++ b/autoload/ale/fixers/astyle.vim @@ -18,15 +18,42 @@ function! ale#fixers#astyle#Var(buffer, name) abort return ale#Var(a:buffer, l:ft . '_astyle_' . a:name) endfunction +" Try to find a project options file. +function! ale#fixers#astyle#FindProjectOptions(buffer) abort + let l:proj_options = ale#fixers#astyle#Var(a:buffer, 'project_options') + + " If user has set project options variable then use it and skip any searching. + " This would allow users to use project files named differently than .astylerc. + if !empty(l:proj_options) + return l:proj_options + endif + + " Try to find nearest .astylerc file. + let l:proj_options = fnamemodify(ale#path#FindNearestFile(a:buffer, '.astylerc'), ':t') + + if !empty(l:proj_options) + return l:proj_options + endif + + " Try to find nearest _astylerc file. + let l:proj_options = fnamemodify(ale#path#FindNearestFile(a:buffer, '_astylerc'), ':t') + + if !empty(l:proj_options) + return l:proj_options + endif + + " If no project options file is found return an empty string. + return '' +endfunction + function! ale#fixers#astyle#Fix(buffer) abort let l:executable = ale#fixers#astyle#Var(a:buffer, 'executable') - let l:filename = ale#Escape(bufname(a:buffer)) - let l:options = ale#fixers#astyle#Var(a:buffer, 'project_options') + let l:proj_options = ale#fixers#astyle#FindProjectOptions(a:buffer) let l:command = ' --stdin=' return { \ 'command': ale#Escape(l:executable) - \ . (empty(l:options) ? '' : ' --project=' . l:options) + \ . (empty(l:proj_options) ? '' : ' --project=' . l:proj_options) \ . l:command \} endfunction diff --git a/test/fixers/test_astyle_fixer_callback.vader b/test/fixers/test_astyle_fixer_callback.vader index 60a18213..cbec4493 100644 --- a/test/fixers/test_astyle_fixer_callback.vader +++ b/test/fixers/test_astyle_fixer_callback.vader @@ -65,3 +65,14 @@ Execute(The astyle callback should return the correct default values with an opt \ . ' --stdin=' \ }, \ ale#fixers#astyle#Fix(bufnr('')) + +Execute(The astyle callback should find nearest default option file _astylrc): + call ale#test#SetFilename('../test_c_projects/makefile_project/subdir/file.c') + + AssertEqual + \ { + \ 'command': ale#Escape('xxxinvalid') + \ . ' --project=_astylerc' + \ . ' --stdin=' + \ }, + \ ale#fixers#astyle#Fix(bufnr('')) diff --git a/test/test_c_projects/makefile_project/_astylerc b/test/test_c_projects/makefile_project/_astylerc new file mode 100644 index 00000000..e69de29b From cef64424ceaede7093bb2837d572b8c5fc0de121 Mon Sep 17 00:00:00 2001 From: jhlink Date: Wed, 29 Jul 2020 01:52:36 -0400 Subject: [PATCH 30/30] style: Resolve lint issue --- autoload/ale/fixers/astyle.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/ale/fixers/astyle.vim b/autoload/ale/fixers/astyle.vim index 0abceb10..04e4b69a 100644 --- a/autoload/ale/fixers/astyle.vim +++ b/autoload/ale/fixers/astyle.vim @@ -25,7 +25,7 @@ function! ale#fixers#astyle#FindProjectOptions(buffer) abort " If user has set project options variable then use it and skip any searching. " This would allow users to use project files named differently than .astylerc. if !empty(l:proj_options) - return l:proj_options + return l:proj_options endif " Try to find nearest .astylerc file.