class Rubydex::Location
A zero based internal location. Intended to be used for tool-to-tool communication, such as a language server communicating with an editor.
Attributes
end_column
[R]
Integer
end_line
[R]
Integer
start_column
[R]
Integer
start_line
[R]
Integer
uri
[R]
String
Public Class Methods
(Prism::Location prism_location, uri: String) → Location
Source
# File lib/rubydex/location.rb, line 19 def from_prism(prism_location, uri:) Location.new( uri: uri, start_line: prism_location.start_line - 1, start_column: prism_location.start_column, end_line: prism_location.end_line - 1, end_column: prism_location.end_column, ) end
(?uri: String, ?start_line: Integer, ?end_line: Integer, ?start_column: Integer, ?end_column: Integer) → void
Source
# File lib/rubydex/location.rb, line 31 def initialize(uri:, start_line:, end_line:, start_column:, end_column:) @uri = uri @start_line = start_line @end_line = end_line @start_column = start_column @end_column = end_column end
Public Instance Methods
(other: BasicObject) → Integer
Source
# File lib/rubydex/location.rb, line 51 def <=>(other) return -1 unless other.is_a?(Location) comparable_values <=> other.comparable_values end
() → [String, Integer, Integer, Integer, Integer]
Source
# File lib/rubydex/location.rb, line 58 def comparable_values [@uri, @start_line, @start_column, @end_line, @end_column] end
Source
# File lib/rubydex/location.rb, line 65 def to_display DisplayLocation.new( uri: @uri, start_line: @start_line + 1, end_line: @end_line + 1, start_column: @start_column + 1, end_column: @end_column + 1, ) end
Turns this zero based location into a one based location for display purposes.
() → String
Source
# File lib/rubydex/location.rb, line 40 def to_file_path uri = URI(@uri) raise NotFileUriError, "URI is not a file:// URI: #{@uri}" unless uri.scheme == "file" path = uri.path # TODO: This has to go away once we have a proper URI abstraction path.delete_prefix!("/") if Gem.win_platform? path end
→ String
Source
# File lib/rubydex/location.rb, line 76 def to_s "#{to_file_path}:#{@start_line + 1}:#{@start_column + 1}-#{@end_line + 1}:#{@end_column + 1}" end