summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/fixers/syntax_tree.vim19
-rw-r--r--doc/ale-ruby.txt20
-rw-r--r--doc/ale-supported-languages-and-tools.txt1
-rw-r--r--doc/ale.txt1
-rw-r--r--supported-tools.md1
-rw-r--r--test/fixers/test_syntax_tree_fixer_callback.vader37
7 files changed, 84 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index 85fef81d..9281ec61 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -221,6 +221,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['swift'],
\ 'description': 'Apply SwiftFormat to a file.',
\ },
+\ 'syntax_tree': {
+\ 'function': 'ale#fixers#syntax_tree#Fix',
+\ 'suggested_filetypes': ['ruby'],
+\ 'description': 'Fix ruby files with stree write',
+\ },
\ 'apple-swift-format': {
\ 'function': 'ale#fixers#appleswiftformat#Fix',
\ 'suggested_filetypes': ['swift'],
diff --git a/autoload/ale/fixers/syntax_tree.vim b/autoload/ale/fixers/syntax_tree.vim
new file mode 100644
index 00000000..7ae03373
--- /dev/null
+++ b/autoload/ale/fixers/syntax_tree.vim
@@ -0,0 +1,19 @@
+call ale#Set('ruby_syntax_tree_options', '')
+call ale#Set('ruby_syntax_tree_executable', 'stree')
+
+function! ale#fixers#syntax_tree#GetCommand(buffer) abort
+ let l:executable = ale#Var(a:buffer, 'ruby_syntax_tree_executable')
+ let l:options = ale#Var(a:buffer, 'ruby_syntax_tree_options')
+
+ return ale#ruby#EscapeExecutable(l:executable, 'stree')
+ \ . ' write'
+ \ . (!empty(l:options) ? ' ' . l:options : '')
+ \ . ' %t'
+endfunction
+
+function! ale#fixers#syntax_tree#Fix(buffer) abort
+ return {
+ \ 'command': ale#fixers#syntax_tree#GetCommand(a:buffer),
+ \ 'read_temporary_file': 1,
+ \}
+endfunction
diff --git a/doc/ale-ruby.txt b/doc/ale-ruby.txt
index 4bc25b1a..bd7bd57d 100644
--- a/doc/ale-ruby.txt
+++ b/doc/ale-ruby.txt
@@ -220,4 +220,24 @@ g:ale_ruby_standardrb_options *g:ale_ruby_standardrb_options*
===============================================================================
+syntax_tree *ale-ruby-syntax_tree*
+
+g:ale_ruby_syntax_tree_executable *g:ale_ruby_syntax_tree_executable*
+ *b:ale_ruby_syntax_tree_executable*
+ Type: String
+ Default: `'stree'`
+
+ Override the invoked SyntaxTree binary. Set this to `'bundle'` to invoke
+ `'bundle` `exec` stree'.
+
+
+g:ale_ruby_syntax_tree_options *g:ale_ruby_syntax_tree_options*
+ *b:ale_ruby_syntax_tree_options*
+ Type: |String|
+ Default: `''`
+
+ This variable can be changed to modify flags given to SyntaxTree.
+
+
+===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt
index a0a20c7e..4f90ecb6 100644
--- a/doc/ale-supported-languages-and-tools.txt
+++ b/doc/ale-supported-languages-and-tools.txt
@@ -529,6 +529,7 @@ Notes:
* `solargraph`
* `sorbet`
* `standardrb`
+ * `syntax_tree`
* Rust
* `cargo`!!
* `cspell`
diff --git a/doc/ale.txt b/doc/ale.txt
index ff1af720..48088e62 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -3167,6 +3167,7 @@ documented in additional help files.
solargraph............................|ale-ruby-solargraph|
sorbet................................|ale-ruby-sorbet|
standardrb............................|ale-ruby-standardrb|
+ syntax_tree...........................|ale-ruby-syntax_tree|
rust....................................|ale-rust-options|
analyzer..............................|ale-rust-analyzer|
cargo.................................|ale-rust-cargo|
diff --git a/supported-tools.md b/supported-tools.md
index bdad2b3b..61f16b09 100644
--- a/supported-tools.md
+++ b/supported-tools.md
@@ -538,6 +538,7 @@ formatting.
* [solargraph](https://solargraph.org)
* [sorbet](https://github.com/sorbet/sorbet)
* [standardrb](https://github.com/testdouble/standard)
+ * [syntax_tree](https://github.com/ruby-syntax-tree/syntax_tree)
* Rust
* [cargo](https://github.com/rust-lang/cargo) :floppy_disk: (see `:help ale-integration-rust` for configuration instructions)
* [cspell](https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell)
diff --git a/test/fixers/test_syntax_tree_fixer_callback.vader b/test/fixers/test_syntax_tree_fixer_callback.vader
new file mode 100644
index 00000000..46450985
--- /dev/null
+++ b/test/fixers/test_syntax_tree_fixer_callback.vader
@@ -0,0 +1,37 @@
+Before:
+ Save g:ale_ruby_syntax_tree_executable
+ Save g:ale_ruby_syntax_tree_options
+
+ " Use an invalid global executable, so we don't match it.
+ let g:ale_ruby_syntax_tree_executable = 'xxxinvalid'
+ let g:ale_ruby_syntax_tree_options = ''
+
+ call ale#test#SetDirectory('/testplugin/test/fixers')
+
+After:
+ Restore
+
+ call ale#test#RestoreDirectory()
+
+Execute(The syntax_tree callback should return the correct default values):
+ call ale#test#SetFilename('../test-files/ruby/dummy.rb')
+
+ AssertEqual
+ \ {
+ \ 'read_temporary_file': 1,
+ \ 'command': ale#Escape(g:ale_ruby_syntax_tree_executable)
+ \ . ' write %t',
+ \ },
+ \ ale#fixers#syntax_tree#Fix(bufnr(''))
+
+Execute(The syntax_tree callback should include custom options):
+ let g:ale_ruby_syntax_tree_options = '--print-width=100 --plugins=plugin/trailing_comma'
+ call ale#test#SetFilename('../test-files/ruby/with_config/dummy.rb')
+
+ AssertEqual
+ \ {
+ \ 'read_temporary_file': 1,
+ \ 'command': ale#Escape(g:ale_ruby_syntax_tree_executable)
+ \ . ' write --print-width=100 --plugins=plugin/trailing_comma %t',
+ \ },
+ \ ale#fixers#syntax_tree#Fix(bufnr(''))