Class: RubyLsp::TypeInferrer

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_lsp/type_inferrer.rb

Overview

A minimalistic type checker to try to resolve types that can be inferred without requiring a type system or annotations

Defined Under Namespace

Classes: GuessedType, Type

Instance Method Summary collapse

Constructor Details

#initialize(index) ⇒ TypeInferrer

: (RubyIndexer::Index index) -> void



9
10
11
# File 'lib/ruby_lsp/type_inferrer.rb', line 9

def initialize(index)
  @index = index
end

Instance Method Details

#infer_receiver_type(node_context) ⇒ Object

: (NodeContext node_context) -> Type?



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ruby_lsp/type_inferrer.rb', line 14

def infer_receiver_type(node_context)
  node = node_context.node

  case node
  when Prism::CallNode
    infer_receiver_for_call_node(node, node_context)
  when Prism::InstanceVariableReadNode, Prism::InstanceVariableAndWriteNode, Prism::InstanceVariableWriteNode,
    Prism::InstanceVariableOperatorWriteNode, Prism::InstanceVariableOrWriteNode, Prism::InstanceVariableTargetNode,
    Prism::SuperNode, Prism::ForwardingSuperNode
    self_receiver_handling(node_context)
  when Prism::ClassVariableAndWriteNode, Prism::ClassVariableWriteNode, Prism::ClassVariableOperatorWriteNode,
    Prism::ClassVariableOrWriteNode, Prism::ClassVariableReadNode, Prism::ClassVariableTargetNode
    infer_receiver_for_class_variables(node_context)
  end
end