class Yoda::Evaluation::CodeCompletion::MethodProvider

Public Instance Methods

candidates() click to toggle source

@return [Array<Model::CompletionItem>]

# File lib/yoda/evaluation/code_completion/method_provider.rb, line 11
def candidates
  method_candidates.map do |method_candidate|
    Model::CompletionItem.new(
      description: Model::Descriptions::FunctionDescription.new(method_candidate),
      range: substitution_range,
      kind: :method,
    )
  end
end
providable?() click to toggle source

@return [true, false]

# File lib/yoda/evaluation/code_completion/method_provider.rb, line 6
def providable?
  !!(current_send)
end

Private Instance Methods

current_receiver_node() click to toggle source

@return [Parser::AST::Node, nil]

# File lib/yoda/evaluation/code_completion/method_provider.rb, line 70
def current_receiver_node
  current_send&.receiver_node
end
current_send() click to toggle source

@return [Parsing::NodeObjects::SendNode, nil]

# File lib/yoda/evaluation/code_completion/method_provider.rb, line 61
def current_send
  @current_send ||= begin
    node = source_analyzer.nodes_to_current_location_from_root.last
    return nil unless node.type == :send
    Parsing::NodeObjects::SendNode.new(node)
  end
end
index_word() click to toggle source

@return [String, nil]

# File lib/yoda/evaluation/code_completion/method_provider.rb, line 75
def index_word
  return nil unless providable?
  @index_word ||= current_send.on_selector?(location) ? current_send.selector_name.slice(0..current_send.offset_in_selector(location)) : ''
end
method_candidates() click to toggle source

@return [Array<Store::Objects::Method>]

# File lib/yoda/evaluation/code_completion/method_provider.rb, line 31
def method_candidates
  return [] unless providable?
  receiver_values
    .map { |value| Store::Query::FindSignature.new(registry).select(value, /\A#{Regexp.escape(index_word)}/, visibility: method_visibility_of_send_node(current_send)) }
    .flatten
end
method_visibility_of_send_node(send_node) click to toggle source

@param send_node [Parsing::NodeObjects::SendNode] @return [Array<Symbol>]

# File lib/yoda/evaluation/code_completion/method_provider.rb, line 40
def method_visibility_of_send_node(send_node)
  if send_node.receiver_node
    %i(public)
  else
    %i(public private protected)
  end
end
receiver_values() click to toggle source

@return [Array<Store::Objects::Base>]

# File lib/yoda/evaluation/code_completion/method_provider.rb, line 49
def receiver_values
  @receiver_values ||= begin
    if current_receiver_node
      evaluator.calculate_values(current_receiver_node)
    else
      # implicit call for self
      [evaluator.scope_constant]
    end
  end
end
substitution_range() click to toggle source

@return [Range]

# File lib/yoda/evaluation/code_completion/method_provider.rb, line 24
def substitution_range
  return current_send.selector_range if current_send.on_selector?(location)
  return Parsing::Range.new(current_send.next_location_to_dot, current_send.next_location_to_dot) if current_send.on_dot?(location)
  nil
end