Class: SorbetView::SourceMap::SourceMap

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/sorbet_view/source_map/source_map.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template_path:, ruby_path:, entries:) ⇒ SourceMap

Returns a new instance of SourceMap.



25
26
27
28
29
# File 'lib/sorbet_view/source_map/source_map.rb', line 25

def initialize(template_path:, ruby_path:, entries:)
  @template_path = template_path
  @ruby_path = ruby_path
  @entries = entries
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



16
17
18
# File 'lib/sorbet_view/source_map/source_map.rb', line 16

def entries
  @entries
end

#ruby_pathObject (readonly)

Returns the value of attribute ruby_path.



13
14
15
# File 'lib/sorbet_view/source_map/source_map.rb', line 13

def ruby_path
  @ruby_path
end

#template_pathObject (readonly)

Returns the value of attribute template_path.



10
11
12
# File 'lib/sorbet_view/source_map/source_map.rb', line 10

def template_path
  @template_path
end

Class Method Details

.empty(template_path, ruby_path) ⇒ Object



63
64
65
# File 'lib/sorbet_view/source_map/source_map.rb', line 63

def self.empty(template_path, ruby_path)
  new(template_path: template_path, ruby_path: ruby_path, entries: [])
end

Instance Method Details

#ruby_range_to_template(ruby_range) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/sorbet_view/source_map/source_map.rb', line 54

def ruby_range_to_template(ruby_range)
  start_pos = ruby_to_template(ruby_range.start)
  end_pos = ruby_to_template(ruby_range.end_)
  return nil unless start_pos && end_pos

  Range.new(start: start_pos, end_: end_pos)
end

#ruby_to_template(position) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/sorbet_view/source_map/source_map.rb', line 43

def ruby_to_template(position)
  Perf.measure('sourcemap.ruby_to_template') do
    entry = find_entry_by_ruby(position)
    next nil unless entry
    next nil if entry.type == :boilerplate

    translate(position, entry.ruby_range, entry.template_range)
  end
end

#template_to_ruby(position) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/sorbet_view/source_map/source_map.rb', line 32

def template_to_ruby(position)
  Perf.measure('sourcemap.template_to_ruby') do
    entry = find_entry_by_template(position)
    next nil unless entry
    next nil if entry.type == :boilerplate

    translate(position, entry.template_range, entry.ruby_range)
  end
end