class Orbacle::Engine
Attributes
logger[R]
stats_recorder[R]
Public Class Methods
new(logger)
click to toggle source
# File lib/orbacle/engine.rb, line 5 def initialize(logger) @logger = logger end
Public Instance Methods
completions_for_call_under_position(file_content, position)
click to toggle source
# File lib/orbacle/engine.rb, line 46 def completions_for_call_under_position(file_content, position) result = FindCallUnderPosition.new(RubyParser.new).process_file(file_content, position) case result when FindCallUnderPosition::SelfResult filtered_methods_from_class_name(result.nesting.to_scope.to_const_name.to_string, result.message_name) when FindCallUnderPosition::IvarResult ivar_node = @graph.get_ivar_definition_node(result.nesting.to_scope, result.ivar_name) ivar_type = @state.type_of(ivar_node) methods = [] ivar_type.each_possible_type do |type| methods.concat(filtered_methods_from_class_name(type.name, result.message_name)) end methods else [] end end
get_type_information(filepath, searched_position)
click to toggle source
# File lib/orbacle/engine.rb, line 17 def get_type_information(filepath, searched_position) relevant_nodes = @graph .vertices .select {|n| n.location && n.location.uri.eql?(filepath) && n.location.position_range.include_position?(searched_position) } .sort_by {|n| n.location.span } pretty_print_type(@state.type_of(relevant_nodes.at(0))) end
index(project_root)
click to toggle source
# File lib/orbacle/engine.rb, line 11 def index(project_root) @stats_recorder = Indexer::StatsRecorder.new service = Indexer.new(logger, stats_recorder) @state, @graph, @worklist = service.(project_root: project_root) end
locations_for_definition_under_position(file_path, file_content, position)
click to toggle source
# File lib/orbacle/engine.rb, line 26 def locations_for_definition_under_position(file_path, file_content, position) result = find_definition_under_position(file_content, position.line, position.character) case result when FindDefinitionUnderPosition::ConstantResult constants = @state.solve_reference2(result.const_ref) definitions_locations(constants) when FindDefinitionUnderPosition::MessageResult caller_type = get_type_of_caller_from_message_send(file_path, result.position_range) methods_definitions = get_methods_definitions_for_type(caller_type, result.name) methods_definitions = @state.get_methods(result.name) if methods_definitions.empty? definitions_locations(methods_definitions) when FindDefinitionUnderPosition::SuperResult method_surrounding_super = @state.find_method_including_position(file_path, result.keyword_position_range.start) return [] if method_surrounding_super.nil? super_method = @state.find_super_method(method_surrounding_super.id) return definitions_locations(@state.get_methods(method_surrounding_super.name) - [method_surrounding_super]) if super_method.nil? definitions_locations([super_method]) end end
Private Instance Methods
definitions_locations(collection)
click to toggle source
# File lib/orbacle/engine.rb, line 65 def definitions_locations(collection) collection.map(&:location).compact end
filtered_methods_from_class_name(class_name, message_name)
click to toggle source
# File lib/orbacle/engine.rb, line 100 def filtered_methods_from_class_name(class_name, message_name) all_methods = @state.get_all_instance_methods_from_class_name(class_name) starting_with = all_methods.select do |metod| metod.name.to_s.start_with?(message_name.to_s) end starting_with.map(&:name).map(&:to_s) end
find_definition_under_position(content, line, character)
click to toggle source
# File lib/orbacle/engine.rb, line 92 def find_definition_under_position(content, line, character) FindDefinitionUnderPosition.new(RubyParser.new).process_file(content, Position.new(line, character)) end
get_methods_definitions_for_type(type, method_name)
click to toggle source
# File lib/orbacle/engine.rb, line 76 def get_methods_definitions_for_type(type, method_name) case type when NominalType @state.get_deep_instance_methods_from_class_name(type.name, method_name) when ClassType @state.get_deep_class_methods_from_class_name(type.name, method_name) when UnionType type.types_set.flat_map {|t| get_methods_definitions_for_type(t, method_name) } else [] end end
get_type_of_caller_from_message_send(file_path, position_range)
click to toggle source
# File lib/orbacle/engine.rb, line 69 def get_type_of_caller_from_message_send(file_path, position_range) message_send = @worklist .message_sends .find {|ms| ms.location && ms.location.uri.eql?(file_path) && ms.location.position_range.include_position?(position_range.start) } @state.type_of(message_send.send_obj) end
pretty_print_type(type)
click to toggle source
# File lib/orbacle/engine.rb, line 96 def pretty_print_type(type) TypePrettyPrinter.new.(type) end