class RBS::Location
Location is the range on buffer, start_pos..end_pos. The index is based on characters.
A location can have child locations.
Constants
- WithChildren
Attributes
The raw index of character the range ends at.
The raw index of character the range starts from.
Buffer
The buffer this location points on.
Public Class Methods
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/location_aux.rb, line 16 def self.new(buffer_ = nil, start_pos_ = nil, end_pos_ = nil, buffer: nil, start_pos: nil, end_pos: nil) __skip__ = begin if buffer && start_pos && end_pos super(buffer, start_pos, end_pos) else super(buffer_, start_pos_, end_pos_) end end end
Object::new
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/location_aux.rb, line 102 def self.to_string(location, default: "*:*:*...*:*") location&.to_s || default end
Returns a string representation suitable for terminal output.
Location.to_string(loc) # => a.rb:1:0...3:4 Location.to_string(nil) # => *:*:*..*:*
Public Instance Methods
(untyped other) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/location_aux.rb, line 79 def ==(other) other.is_a?(Location) && other.buffer == buffer && other.start_pos == start_pos && other.end_pos == end_pos end
(RequiredChildKeys) → Location[bot, bot]
(OptionalChildKeys) → Location[bot, bot]?
(Symbol) → Location[bot, bot]?
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/sig/location.rbs, line 99
def []: (RequiredChildKeys) -> Location[bot, bot]
| (OptionalChildKeys) -> Location[bot, bot]?
| (Symbol) -> Location[bot, bot]?
Returns Location instance for given child name.
# @type var loc: Location::WithChildren[:name, :args] loc[:name] # => Location loc[:args] # => may be nil
Note that passing unknown symbol raises an error even if the child is optional. You need explicitly set nil for absent optional children.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/sig/location.rbs, line 128
def _add_optional_child: (OptionalChildKeys name, Integer start_pos, Integer end_pos) -> void
(OptionalChildKeys name) → void
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/sig/location.rbs, line 129
def _add_optional_no_child: (OptionalChildKeys name) -> void
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/sig/location.rbs, line 127
def _add_required_child: (RequiredChildKeys name, Integer start_pos, Integer end_pos) -> void
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/sig/location.rbs, line 130
def _optional_keys: () -> Array[Symbol]
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/sig/location.rbs, line 131
def _required_keys: () -> Array[Symbol]
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/location_aux.rb, line 110 def add_optional_child(name, range) if range _add_optional_child(name, range.begin, range.end) else _add_optional_no_child(name); end end
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/location_aux.rb, line 106 def add_required_child(name, range) _add_required_child(name, range.begin, range.end) end
() { (Symbol) → void } → void
() → Enumerator[Symbol, void]
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/location_aux.rb, line 118 def each_optional_key(&block) if block _optional_keys.uniq.each(&block) else enum_for(:each_optional_key) end end
() { (Symbol) → void } → void
() → Enumerator[Symbol, void]
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/location_aux.rb, line 126 def each_required_key(&block) if block _required_keys.uniq.each(&block) else enum_for(:each_required_key) end end
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/location_aux.rb, line 55 def end_column end_loc[1] end
Column of the end_pos (0 origin, absolute)
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/location_aux.rb, line 51 def end_line end_loc[0] end
Line of the end_pos (1 origin, absolute)
Buffer::loc
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/location_aux.rb, line 63 def end_loc @end_loc ||= buffer.top_buffer.pos_to_loc(end_pos) end
The absolute line-column pair of the end position
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/location_aux.rb, line 35 def end_pos buffer.absolute_position(_end_pos) || raise end
The absolute end index of character the range ends at
It returns the index in the buffer.top_buffer.
() → String
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/location_aux.rb, line 5 def inspect rks = each_required_key.to_a ops = each_optional_key.to_a.map {|x| "?#{x}" } src = if source.length <= 1 source.inspect else source.each_line.first&.chomp&.inspect end "#<#{self.class}:#{self.__id__} buffer=#{buffer.name}, start=#{start_line}:#{start_column}, pos=#{start_pos}...#{end_pos}, children=#{(rks + ops).join(",")} source=#{src}>" end
(Symbol) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/location_aux.rb, line 134 def key?(name) optional_key?(name) || required_key?(name) end
() → self
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/location_aux.rb, line 146 def local_location loc = Location.new(buffer.detach, _start_pos, _end_pos) each_optional_key do |key| value = self[key] if value loc.add_optional_child(key, value._start_pos...value._end_pos) else loc.add_optional_child(key, nil) end end each_required_key do |key| value = self[key] or raise loc.add_required_child(key, value._start_pos...value._end_pos) end loc #: self end
Returns the location of the buffer, but the buffer is detached from the parent buffer
() → String
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/location_aux.rb, line 166 def local_source local_location.source end
Returns the source of local_location
() → untyped
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/location_aux.rb, line 39 def name buffer.name end
Returns the name of the buffer.
(Symbol) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/location_aux.rb, line 138 def optional_key?(name) _optional_keys.include?(name) end
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/location_aux.rb, line 67 def range @range ||= start_pos...end_pos end
The absolute range of the start and end position
(Symbol) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/location_aux.rb, line 142 def required_key?(name) _required_keys.include?(name) end
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/location_aux.rb, line 71 def source @source ||= (buffer.top_buffer.content[range] || raise) end
A substring of buffer associated to the location.
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/location_aux.rb, line 47 def start_column start_loc[1] end
Column of the start_pos (0 origin, absolute)
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/location_aux.rb, line 43 def start_line start_loc[0] end
Line of the start_pos (1 origin, absolute)
Buffer::loc
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/location_aux.rb, line 59 def start_loc @start_loc ||= buffer.top_buffer.pos_to_loc(start_pos) end
The absolute line-column pair of the start position
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/location_aux.rb, line 31 def start_pos buffer.absolute_position(_start_pos) || raise end
The absolute start index of character the range starts from
It returns the index in the buffer.top_buffer.
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/location_aux.rb, line 86 def to_json(state = nil) { start: { line: start_line, column: start_column }, end: { line: end_line, column: end_column }, buffer: { name: name&.to_s } }.to_json(state) end