Class: Solargraph::Location
- Inherits:
-
Object
- Object
- Solargraph::Location
- Includes:
- Comparable, Equality
- Defined in:
- lib/solargraph/location.rb
Overview
A pointer to a section of source text identified by its filename and Range.
Instance Attribute Summary collapse
- #filename ⇒ String readonly
- #range ⇒ Solargraph::Range readonly
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #contain?(location) ⇒ Boolean
-
#initialize(filename, range) ⇒ Location
constructor
A new instance of Location.
- #inspect ⇒ Object
- #rbs? ⇒ Boolean
- #to_hash ⇒ Hash
- #to_s ⇒ Object
Methods included from Equality
Constructor Details
#initialize(filename, range) ⇒ Location
Returns a new instance of Location.
19 20 21 22 23 24 |
# File 'lib/solargraph/location.rb', line 19 def initialize filename, range raise 'Use nil to represent no-file' if filename&.empty? @filename = filename @range = range end |
Instance Attribute Details
#filename ⇒ String (readonly)
12 13 14 |
# File 'lib/solargraph/location.rb', line 12 def filename @filename end |
#range ⇒ Solargraph::Range (readonly)
15 16 17 |
# File 'lib/solargraph/location.rb', line 15 def range @range end |
Class Method Details
.from_node(node) ⇒ Location?
59 60 61 62 63 64 65 66 67 |
# File 'lib/solargraph/location.rb', line 59 def self.from_node node return nil if node.nil? || node.loc.nil? filename = node.loc.expression.source_buffer.name # @sg-ignore flow sensitive typing needs to create separate ranges for postfix if filename = nil if filename.empty? range = Range.from_node(node) # @sg-ignore Need to add nil check here new(filename, range) end |
Instance Method Details
#<=>(other) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/solargraph/location.rb', line 27 def <=> other return nil unless other.is_a?(Location) if filename == other.filename range <=> other.range else filename <=> other.filename end end |
#==(other) ⇒ Object
70 71 72 73 |
# File 'lib/solargraph/location.rb', line 70 def == other return false unless other.is_a?(Location) filename == other.filename and range == other.range end |
#contain?(location) ⇒ Boolean
41 42 43 |
# File 'lib/solargraph/location.rb', line 41 def contain? location range.contain?(location.range.start) && range.contain?(location.range.ending) && filename == location.filename end |
#inspect ⇒ Object
75 76 77 |
# File 'lib/solargraph/location.rb', line 75 def inspect "#<#{self.class} #{filename}, #{range.inspect}>" end |
#rbs? ⇒ Boolean
36 37 38 |
# File 'lib/solargraph/location.rb', line 36 def rbs? filename.end_with?('.rbs') end |
#to_hash ⇒ Hash
50 51 52 53 54 55 |
# File 'lib/solargraph/location.rb', line 50 def to_hash { filename: filename, range: range.to_hash } end |
#to_s ⇒ Object
45 46 47 |
# File 'lib/solargraph/location.rb', line 45 def to_s inspect end |