Class: Solargraph::Location

Inherits:
Object
  • Object
show all
Includes:
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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Equality

#eql?, #freeze, #hash

Constructor Details

#initialize(filename, range) ⇒ Location

Returns a new instance of Location.

Parameters:



18
19
20
21
# File 'lib/solargraph/location.rb', line 18

def initialize filename, range
  @filename = filename
  @range = range
end

Instance Attribute Details

#filenameString (readonly)

Returns:

  • (String)


11
12
13
# File 'lib/solargraph/location.rb', line 11

def filename
  @filename
end

#rangeSolargraph::Range (readonly)

Returns:



14
15
16
# File 'lib/solargraph/location.rb', line 14

def range
  @range
end

Class Method Details

.from_node(node) ⇒ Object

Parameters:

  • node (Parser::AST::Node, nil)


50
51
52
53
54
# File 'lib/solargraph/location.rb', line 50

def self.from_node(node)
  return nil if node.nil? || node.loc.nil?
  range = Range.from_node(node)
  self.new(node.loc.expression.source_buffer.name, range)
end

Instance Method Details

#==(other) ⇒ Object

Parameters:

  • other (BasicObject)


57
58
59
60
# File 'lib/solargraph/location.rb', line 57

def == other
  return false unless other.is_a?(Location)
  filename == other.filename and range == other.range
end

#contain?(location) ⇒ Boolean

Parameters:

  • location (self)

Returns:

  • (Boolean)


29
30
31
# File 'lib/solargraph/location.rb', line 29

def contain? location
  range.contain?(location.range.start) && range.contain?(location.range.ending) && filename == location.filename
end

#inspectObject



33
34
35
# File 'lib/solargraph/location.rb', line 33

def inspect
  "<#{self.class.name}: filename=#{filename}, range=#{range.inspect}>"
end

#to_hashHash

Returns:

  • (Hash)


42
43
44
45
46
47
# File 'lib/solargraph/location.rb', line 42

def to_hash
  {
    filename: filename,
    range: range.to_hash
  }
end

#to_sObject



37
38
39
# File 'lib/solargraph/location.rb', line 37

def to_s
  inspect
end