| module RBS | |
| # Location is the range on buffer, `start_pos..end_pos`. | |
| # The index is based on characters. | |
| # | |
| # A location can have _child_ locations. | |
| # | |
| class Location[in RequiredChildKeys < Symbol = bot, in OptionalChildKeys < Symbol = bot] | |
| # The buffer this location points on. | |
| attr_reader buffer: Buffer | |
| # The absolute start index of character the range starts from | |
| # | |
| # It returns the index in the `buffer.top_buffer`. | |
| # | |
| attr_reader start_pos: Integer | |
| # The absolute end index of character the range ends at | |
| # | |
| # It returns the index in the `buffer.top_buffer`. | |
| # | |
| attr_reader end_pos: Integer | |
| attr_reader required_children: Hash[Symbol, Range[Integer]] | |
| attr_reader optional_children: Hash[Symbol, Range[Integer]?] | |
| def initialize: (Buffer, Integer start_pos, Integer end_pos) -> void | |
| def self.build: [RequiredChildKeys < Symbol, OptionalChildKeys < Symbol] (Buffer, Integer start_pos, Integer end_pos, Array[[RequiredChildKeys, Range[Integer]]], Array[[OptionalChildKeys, Range[Integer]?]]) -> Location[RequiredChildKeys, OptionalChildKeys] | |
| def inspect: () -> String | |
| # Returns the name of the buffer. | |
| def name: () -> Pathname | |
| # Line of the `start_pos` (1 origin, absolute) | |
| attr_reader start_line (): Integer | |
| # Column of the `start_pos` (0 origin, absolute) | |
| attr_reader start_column (): Integer | |
| # Line of the `end_pos` (1 origin, absolute) | |
| attr_reader end_line (): Integer | |
| # Column of the `end_pos` (0 origin, absolute) | |
| attr_reader end_column (): Integer | |
| # The absolute line-column pair of the start position | |
| # | |
| attr_reader start_loc (): Buffer::loc | |
| # The absolute line-column pair of the end position | |
| # | |
| attr_reader end_loc (): Buffer::loc | |
| # The absolute range of the start and end position | |
| attr_reader range (): Range[Integer] | |
| # A substring of buffer associated to the location. | |
| def source: () -> String | |
| def to_s: () -> String | |
| # Returns a string representation suitable for terminal output. | |
| # | |
| # Location.to_string(loc) # => a.rb:1:0...3:4 | |
| # Location.to_string(nil) # => *:*:*..*:* | |
| # | |
| def self.to_string: (Location[untyped, untyped]? location, ?default: ::String default) -> String | |
| def ==: (untyped other) -> bool | |
| include _ToJson | |
| def add_optional_child: (OptionalChildKeys name, Range[Integer]? range) -> void | |
| def add_required_child: (RequiredChildKeys name, Range[Integer] range) -> void | |
| # 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. | |
| # | |
| def []: (RequiredChildKeys) -> Location[bot, bot] | |
| | (OptionalChildKeys) -> Location[bot, bot]? | |
| | (Symbol) -> Location[bot, bot]? | |
| alias aref [] | |
| def each_optional_key: () { (Symbol) -> void } -> void | |
| | () -> Enumerator[Symbol, void] | |
| def each_required_key: () { (Symbol) -> void } -> void | |
| | () -> Enumerator[Symbol, void] | |
| def optional_key?: (Symbol) -> bool | |
| def required_key?: (Symbol) -> bool | |
| def key?: (Symbol) -> bool | |
| # Returns the location of the buffer, but the buffer is detached from the parent buffer | |
| # | |
| def local_location: () -> self | |
| # Returns the source of `#local_location` | |
| # | |
| def local_source: () -> String | |
| WithChildren: singleton(Location) | |
| end | |
| end |