Class: RubyLsp::Requests::Support::SyntaxTreeFormattingRunner

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Includes:
FormatterRunner, Singleton
Defined in:
lib/ruby_lsp/requests/support/syntax_tree_formatting_runner.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initializeSyntaxTreeFormattingRunner

Returns a new instance of SyntaxTreeFormattingRunner.



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ruby_lsp/requests/support/syntax_tree_formatting_runner.rb', line 23

def initialize
  @options =
    T.let(
      begin
        opts = SyntaxTree::CLI::Options.new
        opts.parse(SyntaxTree::CLI::ConfigFile.new.arguments)
        opts
      end,
      SyntaxTree::CLI::Options,
    )
end

Instance Method Details

#run(uri, document) ⇒ Object



36
37
38
39
40
41
# File 'lib/ruby_lsp/requests/support/syntax_tree_formatting_runner.rb', line 36

def run(uri, document)
  path = uri.to_standardized_path
  return if path && @options.ignore_files.any? { |pattern| File.fnmatch?("*/#{pattern}", path) }

  SyntaxTree.format(document.source, @options.print_width, options: @options.formatter_options)
end