Class: Fast::PrismAdapter::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/fast/prism_adapter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buffer_name, source, start_offset, end_offset, prism_node: nil) ⇒ Location

Returns a new instance of Location.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fast/prism_adapter.rb', line 14

def initialize(buffer_name, source, start_offset, end_offset, prism_node: nil)
  @buffer_name = buffer_name
  @source = source
  @prism_node = prism_node
  buffer = Fast::Source.buffer(buffer_name, source: source)
  @expression = Fast::Source.range(
    buffer,
    character_offset(source, start_offset),
    character_offset(source, end_offset)
  )
end

Instance Attribute Details

#expressionObject (readonly)

Returns the value of attribute expression.



12
13
14
# File 'lib/fast/prism_adapter.rb', line 12

def expression
  @expression
end

#nodeObject

Returns the value of attribute node.



11
12
13
# File 'lib/fast/prism_adapter.rb', line 11

def node
  @node
end

Instance Method Details

#nameObject



26
27
28
29
30
# File 'lib/fast/prism_adapter.rb', line 26

def name
  return unless @prism_node&.respond_to?(:name_loc) && @prism_node.name_loc

  range_for(@prism_node.name_loc)
end

#operatorObject



38
39
40
41
42
# File 'lib/fast/prism_adapter.rb', line 38

def operator
  return unless @prism_node&.respond_to?(:operator_loc) && @prism_node.operator_loc

  range_for(@prism_node.operator_loc)
end

#selectorObject



32
33
34
35
36
# File 'lib/fast/prism_adapter.rb', line 32

def selector
  return unless @prism_node&.respond_to?(:message_loc) && @prism_node.message_loc

  range_for(@prism_node.message_loc)
end