Class: RubyLsp::TypeGuessr::TypeInferrer

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

Overview

Custom TypeInferrer that enhances ruby-lsp’s type inference with TypeGuessr’s IR-based heuristic inference. Used by Go to Definition and other features.

Instance Method Summary collapse

Constructor Details

#initialize(index, runtime_adapter) ⇒ TypeInferrer

Returns a new instance of TypeInferrer.



16
17
18
19
# File 'lib/ruby_lsp/type_guessr/type_inferrer.rb', line 16

def initialize(index, runtime_adapter)
  super(index)
  @runtime_adapter = runtime_adapter
end

Instance Method Details

#infer_receiver_type(node_context) ⇒ GuessedType?

Override to add TypeGuessr’s heuristic type inference Returns nil when type cannot be determined (no fallback to ruby-lsp’s default)

Parameters:

  • node_context (RubyLsp::NodeContext)

    The context of the node

Returns:

  • (GuessedType, nil)

    The inferred type or nil if unknown



26
27
28
# File 'lib/ruby_lsp/type_guessr/type_inferrer.rb', line 26

def infer_receiver_type(node_context)
  guess_type_from_ir(node_context)
end