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/data.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 single Source that can be queried.
Defined Under Namespace
Classes: Clip, Completion, Data, Mapper
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(source) ⇒ SourceMap
Returns a new instance of SourceMap.
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/solargraph/source_map.rb', line 35
def initialize source
@source = source
conventions_environ.merge Convention.for_local(self) unless filename.nil?
@document_symbols = nil
self.convention_pins = conventions_environ.pins
@pin_select_cache = {}
end
|
Instance Attribute Details
17
18
19
|
# File 'lib/solargraph/source_map.rb', line 17
def source
@source
end
|
Class Method Details
.load_string(code, filename = nil) ⇒ SourceMap
169
170
171
|
# File 'lib/solargraph/source_map.rb', line 169
def map source
new(source)
end
|
Instance Method Details
#all_pins ⇒ Array<Pin::Base>
25
26
27
|
# File 'lib/solargraph/source_map.rb', line 25
def all_pins
pins + convention_pins
end
|
#api_hash ⇒ Integer
A hash representing the state of the source map’s API.
ApiMap#catalog uses this value to determine whether it needs to clear its cache.
62
63
64
|
# File 'lib/solargraph/source_map.rb', line 62
def api_hash
@api_hash ||= (pins_by_class(Pin::Constant) + pins_by_class(Pin::Namespace).select { |pin| pin.namespace.to_s > '' } + pins_by_class(Pin::Reference) + pins_by_class(Pin::Method).map(&:node) + locals).hash
end
|
#code ⇒ String
72
73
74
|
# File 'lib/solargraph/source_map.rb', line 72
def code
source.code
end
|
#conventions_environ ⇒ Environ
82
83
84
|
# File 'lib/solargraph/source_map.rb', line 82
def conventions_environ
@conventions_environ ||= Environ.new
end
|
102
103
104
|
# File 'lib/solargraph/source_map.rb', line 102
def cursor_at position
Source::Cursor.new(source, position)
end
|
#document_symbols ⇒ Array<Pin::Base>
all pins except Solargraph::Pin::Reference::Reference
88
89
90
91
92
|
# File 'lib/solargraph/source_map.rb', line 88
def document_symbols
@document_symbols ||= (pins + convention_pins).select do |pin|
pin.path && !pin.path.empty?
end
end
|
#filename ⇒ String
67
68
69
|
# File 'lib/solargraph/source_map.rb', line 67
def filename
source.filename
end
|
#first_pin(path) ⇒ Pin::Base
108
109
110
|
# File 'lib/solargraph/source_map.rb', line 108
def first_pin path
pins.select { |p| p.path == path }.first
end
|
30
31
32
|
# File 'lib/solargraph/source_map.rb', line 30
def locals
data.locals
end
|
144
145
146
147
148
|
# File 'lib/solargraph/source_map.rb', line 144
def locals_at(location)
return [] if location.filename != filename
closure = locate_named_path_pin(location.range.start.line, location.range.start.character)
locals.select { |pin| pin.visible_at?(closure, location) }
end
|
#locate_closure_pin(line, character) ⇒ Pin::Namespace, ...
Also known as:
locate_block_pin
129
130
131
|
# File 'lib/solargraph/source_map.rb', line 129
def locate_closure_pin line, character
_locate_pin line, character, Pin::Closure
end
|
122
123
124
|
# File 'lib/solargraph/source_map.rb', line 122
def locate_named_path_pin line, character
_locate_pin line, character, Pin::Namespace, Pin::Method
end
|
114
115
116
117
|
# File 'lib/solargraph/source_map.rb', line 114
def locate_pins location
(pins + locals).select { |pin| pin.location == location }
end
|
20
21
22
|
# File 'lib/solargraph/source_map.rb', line 20
def pins
data.pins
end
|
#pins_by_class(klass) ⇒ Array<generic<T>>
52
53
54
|
# File 'lib/solargraph/source_map.rb', line 52
def pins_by_class klass
@pin_select_cache[klass] ||= pin_class_hash.select { |key, _| key <= klass }.values.flatten
end
|
#query_symbols(query) ⇒ Array<Pin::Base>
96
97
98
|
# File 'lib/solargraph/source_map.rb', line 96
def query_symbols query
Pin::Search.new(document_symbols, query).results
end
|
#references(name) ⇒ Array<Location>
138
139
140
|
# File 'lib/solargraph/source_map.rb', line 138
def references name
source.references name
end
|
77
78
79
|
# File 'lib/solargraph/source_map.rb', line 77
def requires
pins_by_class(Pin::Reference::Require)
end
|