Class: RubyLsp::Requests::Support::SyntaxTreeFormatter

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Includes:
Formatter
Defined in:
lib/ruby_lsp/requests/support/syntax_tree_formatter.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initializeSyntaxTreeFormatter

Returns a new instance of SyntaxTreeFormatter.



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ruby_lsp/requests/support/syntax_tree_formatter.rb', line 20

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_diagnostic(uri, document) ⇒ Object



46
47
48
# File 'lib/ruby_lsp/requests/support/syntax_tree_formatter.rb', line 46

def run_diagnostic(uri, document)
  nil
end

#run_formatting(uri, document) ⇒ Object



33
34
35
36
37
38
# File 'lib/ruby_lsp/requests/support/syntax_tree_formatter.rb', line 33

def run_formatting(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