Class: Rubydex::Location
- Inherits:
-
Object
- Object
- Rubydex::Location
- Includes:
- Comparable
- Defined in:
- lib/rubydex/location.rb,
ext/rubydex/location.c
Overview
A zero based internal location. Intended to be used for tool-to-tool communication, such as a language server communicating with an editor.
Direct Known Subclasses
Defined Under Namespace
Classes: NotFileUriError
Instance Attribute Summary collapse
-
#end_column ⇒ Object
readonly
: Integer.
-
#end_line ⇒ Object
readonly
: Integer.
-
#start_column ⇒ Object
readonly
: Integer.
-
#start_line ⇒ Object
readonly
: Integer.
-
#uri ⇒ Object
readonly
: String.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
: (other: BasicObject) -> Integer.
-
#comparable_values ⇒ Object
: () -> [String, Integer, Integer, Integer, Integer].
-
#initialize(uri:, start_line:, end_line:, start_column:, end_column:) ⇒ Location
constructor
: (?uri: String, ?start_line: Integer, ?end_line: Integer, ?start_column: Integer, ?end_column: Integer) -> void.
-
#to_display ⇒ Object
Turns this zero based location into a one based location for display purposes.
-
#to_file_path ⇒ Object
: () -> String.
-
#to_s ⇒ Object
: -> String.
Constructor Details
#initialize(uri:, start_line:, end_line:, start_column:, end_column:) ⇒ Location
: (?uri: String, ?start_line: Integer, ?end_line: Integer, ?start_column: Integer, ?end_column: Integer) -> void
18 19 20 21 22 23 24 |
# File 'lib/rubydex/location.rb', line 18 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 |
Instance Attribute Details
#end_column ⇒ Object (readonly)
: Integer
15 16 17 |
# File 'lib/rubydex/location.rb', line 15 def end_column @end_column end |
#end_line ⇒ Object (readonly)
: Integer
15 16 17 |
# File 'lib/rubydex/location.rb', line 15 def end_line @end_line end |
#start_column ⇒ Object (readonly)
: Integer
15 16 17 |
# File 'lib/rubydex/location.rb', line 15 def start_column @start_column end |
#start_line ⇒ Object (readonly)
: Integer
15 16 17 |
# File 'lib/rubydex/location.rb', line 15 def start_line @start_line end |
#uri ⇒ Object (readonly)
: String
12 13 14 |
# File 'lib/rubydex/location.rb', line 12 def uri @uri end |
Instance Method Details
#<=>(other) ⇒ Object
: (other: BasicObject) -> Integer
38 39 40 41 42 |
# File 'lib/rubydex/location.rb', line 38 def <=>(other) return -1 unless other.is_a?(Location) comparable_values <=> other.comparable_values end |
#comparable_values ⇒ Object
: () -> [String, Integer, Integer, Integer, Integer]
45 46 47 |
# File 'lib/rubydex/location.rb', line 45 def comparable_values [@uri, @start_line, @start_column, @end_line, @end_column] end |
#to_display ⇒ Object
Turns this zero based location into a one based location for display purposes.
: () -> DisplayLocation
52 53 54 55 56 57 58 59 60 |
# File 'lib/rubydex/location.rb', line 52 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 |
#to_file_path ⇒ Object
: () -> String
27 28 29 30 31 32 33 34 35 |
# File 'lib/rubydex/location.rb', line 27 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 |
#to_s ⇒ Object
: -> String
63 64 65 |
# File 'lib/rubydex/location.rb', line 63 def to_s "#{to_file_path}:#{@start_line + 1}:#{@start_column + 1}-#{@end_line + 1}:#{@end_column + 1}" end |