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

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

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initializeSyntaxTreeFormatter

: -> void



19
20
21
22
23
24
25
# File 'lib/ruby_lsp/requests/support/syntax_tree_formatter.rb', line 19

def initialize
  @options = 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

: (URI::Generic uri, RubyDocument document) -> Array?



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

def run_diagnostic(uri, document)
  nil
end

#run_formatting(uri, document) ⇒ Object

: (URI::Generic uri, RubyDocument document) -> String?



29
30
31
32
33
34
# File 'lib/ruby_lsp/requests/support/syntax_tree_formatter.rb', line 29

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

#run_range_formatting(uri, source, base_indentation) ⇒ Object

: (URI::Generic uri, String source, Integer base_indentation) -> String?



38
39
40
41
42
43
# File 'lib/ruby_lsp/requests/support/syntax_tree_formatter.rb', line 38

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

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