Class: Solargraph::Location

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

Constructor Details

#initialize(filename, range) ⇒ Location

Returns a new instance of Location.

Parameters:



16
17
18
19
# File 'lib/solargraph/location.rb', line 16

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

Instance Attribute Details

#filenameString (readonly)

Returns:

  • (String)


9
10
11
# File 'lib/solargraph/location.rb', line 9

def filename
  @filename
end

#rangeSolargraph::Range (readonly)

Returns:



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

def range
  @range
end

Class Method Details

.from_node(node) ⇒ Object

Parameters:

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


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

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)


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

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)


22
23
24
# File 'lib/solargraph/location.rb', line 22

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

#inspectObject



47
48
49
# File 'lib/solargraph/location.rb', line 47

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

#to_hashHash

Returns:

  • (Hash)


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

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