From 233b68102990ee016f08614291ae92c6a0e2b90f Mon Sep 17 00:00:00 2001 From: Mo Lawson Date: Tue, 9 Aug 2022 07:11:20 -0500 Subject: Add support for syntax_tree fixer (#4268) This is the library that now powers prettier/plugin-ruby but is also stands on its own: https://github.com/ruby-syntax-tree/syntax_tree --- autoload/ale/fix/registry.vim | 5 +++++ autoload/ale/fixers/syntax_tree.vim | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 autoload/ale/fixers/syntax_tree.vim (limited to 'autoload') 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 -- cgit v1.2.3