Class: Solargraph::SourceMap
- Inherits:
-
Object
- Object
- Solargraph::SourceMap
show all
- Defined in:
- lib/solargraph/source_map.rb,
lib/solargraph/source_map/clip.rb,
lib/solargraph/source_map/mapper.rb,
lib/solargraph/source_map/completion.rb
Overview
An index of pins and other ApiMap-related data for a Source.
Defined Under Namespace
Classes: Clip, Completion, Mapper
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(source, pins, locals) ⇒ SourceMap
Returns a new instance of SourceMap.
18
19
20
21
22
23
|
# File 'lib/solargraph/source_map.rb', line 18
def initialize source, pins, locals
@source = source.dup
@pins = pins
@locals = locals
end
|
Instance Attribute Details
16
17
18
|
# File 'lib/solargraph/source_map.rb', line 16
def locals
@locals
end
|
13
14
15
|
# File 'lib/solargraph/source_map.rb', line 13
def pins
@pins
end
|
10
11
12
|
# File 'lib/solargraph/source_map.rb', line 10
def source
@source
end
|
Class Method Details
.load_string(code, filename = nil) ⇒ SourceMap
118
119
120
121
|
# File 'lib/solargraph/source_map.rb', line 118
def map source
result = SourceMap::Mapper.map(source)
new(source, *result)
end
|
Instance Method Details
#code ⇒ Object
29
30
31
|
# File 'lib/solargraph/source_map.rb', line 29
def code
source.code
end
|
45
46
47
|
# File 'lib/solargraph/source_map.rb', line 45
def position
@source.(position)
end
|
#cursor_at(position) ⇒ Solargraph::SourceMap::Fragment
61
62
63
|
# File 'lib/solargraph/source_map.rb', line 61
def cursor_at position
Source::Cursor.new(source, position)
end
|
#document_symbols ⇒ Object
49
50
51
52
53
|
# File 'lib/solargraph/source_map.rb', line 49
def document_symbols
@document_symbols ||= pins.select { |pin|
[Pin::ATTRIBUTE, Pin::CONSTANT, Pin::METHOD, Pin::NAMESPACE].include?(pin.kind) and !pin.path.empty?
}
end
|
#filename ⇒ Object
25
26
27
|
# File 'lib/solargraph/source_map.rb', line 25
def filename
source.filename
end
|
#first_pin(path) ⇒ Object
65
66
67
|
# File 'lib/solargraph/source_map.rb', line 65
def first_pin path
pins.select { |p| p.path == path }.first
end
|
#locate_block_pin(line, character) ⇒ Object
80
81
82
|
# File 'lib/solargraph/source_map.rb', line 80
def locate_block_pin line, character
_locate_pin line, character, Pin::NAMESPACE, Pin::METHOD, Pin::BLOCK
end
|
#locate_named_path_pin(line, character) ⇒ Object
76
77
78
|
# File 'lib/solargraph/source_map.rb', line 76
def locate_named_path_pin line, character
_locate_pin line, character, Pin::NAMESPACE, Pin::METHOD
end
|
71
72
73
74
|
# File 'lib/solargraph/source_map.rb', line 71
def locate_pin location
pins.select{|pin| pin.location == location}.first
end
|
#query_symbols(query) ⇒ Object
55
56
57
|
# File 'lib/solargraph/source_map.rb', line 55
def query_symbols query
document_symbols.select{|pin| pin.path.include?(query)}
end
|
#references(name) ⇒ Array<Location>
99
100
101
|
# File 'lib/solargraph/source_map.rb', line 99
def references name
source.references name
end
|
#requires ⇒ Object
33
34
35
|
# File 'lib/solargraph/source_map.rb', line 33
def requires
@requires ||= pins.select{|p| p.kind == Pin::REQUIRE_REFERENCE}
end
|
#string_at?(position) ⇒ Boolean
39
40
41
|
# File 'lib/solargraph/source_map.rb', line 39
def string_at? position
@source.string_at?(position)
end
|
#try_merge!(other_map) ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/solargraph/source_map.rb', line 85
def try_merge! other_map
return false if pins.length != other_map.pins.length || locals.length != other_map.locals.length || requires.map(&:name).uniq.sort != other_map.requires.map(&:name).uniq.sort
pins.each_index do |i|
return false unless pins[i].try_merge!(other_map.pins[i])
end
locals.each_index do |i|
return false unless locals[i].try_merge!(other_map.locals[i])
end
@source = other_map.source
true
end
|