Class: RubyLsp::Ree::ReeFormatter

Inherits:
Object
  • Object
show all
Includes:
ReeLocaleUtils, ReeLspUtils, RubyLsp::Requests::Support::Formatter
Defined in:
lib/ruby_lsp/ruby_lsp_ree/ree_formatter.rb

Constant Summary collapse

MISSING_LOCALE_PLACEHOLDER =
'_MISSING_LOCALE_'

Constants included from ReeLspUtils

RubyLsp::Ree::ReeLspUtils::Entry

Instance Method Summary collapse

Methods included from ReeLocaleUtils

#find_locale_key_location, #find_locale_value, #package_locales_folder_path

Methods included from ReeLspUtils

#camelize, #find_local_file_path, #get_range_for_fn_insert, #get_ree_type, #get_uri_path, #package_name_from_spec_uri, #package_name_from_uri, #package_path_from_uri, #parameter_name, #path_from_package_folder, #signature_params_from_node, #spec_relative_file_path_from_uri, #underscore

Constructor Details

#initialize(message_queue, settings, index = nil) ⇒ ReeFormatter

Returns a new instance of ReeFormatter.



19
20
21
22
23
# File 'lib/ruby_lsp/ruby_lsp_ree/ree_formatter.rb', line 19

def initialize(message_queue, settings, index = nil)
  @message_queue = message_queue
  @settings = settings || {}
  @index = index
end

Instance Method Details

#run_diagnostic(uri, document) ⇒ Object



47
48
49
50
51
# File 'lib/ruby_lsp/ruby_lsp_ree/ree_formatter.rb', line 47

def run_diagnostic(uri, document)
  detect_missing_error_locales(uri, document)
rescue => e
  $stderr.puts("error in ree_formatter_diagnostic: #{e.message} : #{e.backtrace.first}")
end

#run_formatting(uri, document) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ruby_lsp/ruby_lsp_ree/ree_formatter.rb', line 25

def run_formatting(uri, document)
  source = document.source

  formatters = [
    RubyLsp::Ree::MissingErrorDefinitionsFormatter,
    RubyLsp::Ree::MissingErrorContractsFormatter,
    RubyLsp::Ree::MissingErrorLocalesFormatter,
    RubyLsp::Ree::UnusedLinksFormatter,
    RubyLsp::Ree::MissingImportsFormatter,
    RubyLsp::Ree::ImportPackagesFormatter,
    RubyLsp::Ree::SortLinksFormatter,
    RubyLsp::Ree::SyncDaoColumnsFormatter,
  ].select do |formatter|
    formatter_name = formatter.name.split('::').last.to_sym
    @settings[formatter_name] != false
  end

  formatters.reduce(source){ |s, formatter| formatter.call(s, uri, @message_queue, @index) }
rescue => e
  $stderr.puts("error in ree_formatter: #{e.message} : #{e.backtrace.first}")
end