solargraph 0.58.1 → 0.58.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +7 -1
- data/lib/solargraph/api_map/cache.rb +110 -110
- data/lib/solargraph/api_map/constants.rb +279 -279
- data/lib/solargraph/api_map/index.rb +193 -193
- data/lib/solargraph/api_map/source_to_yard.rb +97 -97
- data/lib/solargraph/api_map/store.rb +384 -384
- data/lib/solargraph/api_map.rb +945 -945
- data/lib/solargraph/complex_type/type_methods.rb +228 -228
- data/lib/solargraph/complex_type/unique_type.rb +482 -482
- data/lib/solargraph/complex_type.rb +444 -444
- data/lib/solargraph/convention/data_definition/data_definition_node.rb +91 -91
- data/lib/solargraph/convention/data_definition.rb +105 -105
- data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +61 -61
- data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +102 -102
- data/lib/solargraph/convention/struct_definition.rb +164 -164
- data/lib/solargraph/diagnostics/require_not_found.rb +53 -53
- data/lib/solargraph/diagnostics/rubocop.rb +118 -118
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +68 -68
- data/lib/solargraph/diagnostics/type_check.rb +55 -55
- data/lib/solargraph/doc_map.rb +439 -439
- data/lib/solargraph/equality.rb +34 -34
- data/lib/solargraph/gem_pins.rb +98 -98
- data/lib/solargraph/language_server/host/diagnoser.rb +89 -89
- data/lib/solargraph/language_server/host/dispatch.rb +130 -130
- data/lib/solargraph/language_server/host/message_worker.rb +112 -112
- data/lib/solargraph/language_server/host/sources.rb +99 -99
- data/lib/solargraph/language_server/host.rb +878 -878
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +114 -114
- data/lib/solargraph/language_server/message/extended/document.rb +23 -23
- data/lib/solargraph/language_server/message/text_document/completion.rb +56 -56
- data/lib/solargraph/language_server/message/text_document/definition.rb +40 -40
- data/lib/solargraph/language_server/message/text_document/document_symbol.rb +26 -26
- data/lib/solargraph/language_server/message/text_document/formatting.rb +148 -148
- data/lib/solargraph/language_server/message/text_document/hover.rb +58 -58
- data/lib/solargraph/language_server/message/text_document/signature_help.rb +24 -24
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +25 -25
- data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +23 -23
- data/lib/solargraph/library.rb +683 -683
- data/lib/solargraph/location.rb +82 -82
- data/lib/solargraph/logging.rb +37 -37
- data/lib/solargraph/parser/comment_ripper.rb +69 -69
- data/lib/solargraph/parser/flow_sensitive_typing.rb +255 -255
- data/lib/solargraph/parser/node_processor/base.rb +92 -92
- data/lib/solargraph/parser/node_processor.rb +62 -62
- data/lib/solargraph/parser/parser_gem/class_methods.rb +149 -149
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +166 -166
- data/lib/solargraph/parser/parser_gem/node_methods.rb +486 -486
- data/lib/solargraph/parser/parser_gem/node_processors/and_node.rb +22 -22
- data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +59 -59
- data/lib/solargraph/parser/parser_gem/node_processors/begin_node.rb +15 -15
- data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +46 -46
- data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +53 -53
- data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +23 -23
- data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +40 -40
- data/lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb +29 -29
- data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +59 -59
- data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +98 -98
- data/lib/solargraph/parser/parser_gem/node_processors/orasgn_node.rb +17 -17
- data/lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb +38 -38
- data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +52 -52
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +291 -291
- data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +29 -29
- data/lib/solargraph/parser/parser_gem/node_processors.rb +70 -70
- data/lib/solargraph/parser/region.rb +69 -69
- data/lib/solargraph/parser/snippet.rb +17 -17
- data/lib/solargraph/pin/base.rb +729 -729
- data/lib/solargraph/pin/base_variable.rb +126 -126
- data/lib/solargraph/pin/block.rb +104 -104
- data/lib/solargraph/pin/breakable.rb +9 -9
- data/lib/solargraph/pin/callable.rb +231 -231
- data/lib/solargraph/pin/closure.rb +72 -72
- data/lib/solargraph/pin/common.rb +79 -79
- data/lib/solargraph/pin/conversions.rb +123 -123
- data/lib/solargraph/pin/delegated_method.rb +120 -120
- data/lib/solargraph/pin/documenting.rb +114 -114
- data/lib/solargraph/pin/instance_variable.rb +34 -34
- data/lib/solargraph/pin/keyword.rb +20 -20
- data/lib/solargraph/pin/local_variable.rb +75 -75
- data/lib/solargraph/pin/method.rb +672 -672
- data/lib/solargraph/pin/method_alias.rb +34 -34
- data/lib/solargraph/pin/namespace.rb +115 -115
- data/lib/solargraph/pin/parameter.rb +275 -275
- data/lib/solargraph/pin/proxy_type.rb +39 -39
- data/lib/solargraph/pin/reference/override.rb +47 -47
- data/lib/solargraph/pin/reference/superclass.rb +15 -15
- data/lib/solargraph/pin/reference.rb +39 -39
- data/lib/solargraph/pin/search.rb +61 -61
- data/lib/solargraph/pin/signature.rb +61 -61
- data/lib/solargraph/pin/symbol.rb +53 -53
- data/lib/solargraph/pin/until.rb +18 -18
- data/lib/solargraph/pin/while.rb +18 -18
- data/lib/solargraph/pin.rb +44 -44
- data/lib/solargraph/pin_cache.rb +245 -245
- data/lib/solargraph/position.rb +132 -119
- data/lib/solargraph/range.rb +112 -112
- data/lib/solargraph/rbs_map/conversions.rb +823 -823
- data/lib/solargraph/rbs_map/core_map.rb +58 -58
- data/lib/solargraph/rbs_map/stdlib_map.rb +43 -43
- data/lib/solargraph/rbs_map.rb +163 -163
- data/lib/solargraph/shell.rb +352 -352
- data/lib/solargraph/source/chain/call.rb +337 -337
- data/lib/solargraph/source/chain/constant.rb +26 -26
- data/lib/solargraph/source/chain/hash.rb +34 -34
- data/lib/solargraph/source/chain/if.rb +28 -28
- data/lib/solargraph/source/chain/instance_variable.rb +13 -13
- data/lib/solargraph/source/chain/literal.rb +48 -48
- data/lib/solargraph/source/chain/or.rb +23 -23
- data/lib/solargraph/source/chain.rb +291 -291
- data/lib/solargraph/source/change.rb +82 -82
- data/lib/solargraph/source/cursor.rb +166 -166
- data/lib/solargraph/source/source_chainer.rb +194 -194
- data/lib/solargraph/source/updater.rb +55 -55
- data/lib/solargraph/source.rb +498 -498
- data/lib/solargraph/source_map/clip.rb +226 -226
- data/lib/solargraph/source_map/data.rb +34 -34
- data/lib/solargraph/source_map/mapper.rb +259 -259
- data/lib/solargraph/source_map.rb +212 -212
- data/lib/solargraph/type_checker/checks.rb +124 -124
- data/lib/solargraph/type_checker/param_def.rb +37 -37
- data/lib/solargraph/type_checker/problem.rb +32 -32
- data/lib/solargraph/type_checker/rules.rb +84 -84
- data/lib/solargraph/type_checker.rb +814 -814
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/workspace/config.rb +255 -255
- data/lib/solargraph/workspace/require_paths.rb +97 -97
- data/lib/solargraph/workspace.rb +220 -220
- data/lib/solargraph/yard_map/helpers.rb +44 -44
- data/lib/solargraph/yard_map/mapper/to_method.rb +130 -130
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +31 -31
- data/lib/solargraph/yard_map/mapper.rb +79 -79
- data/lib/solargraph/yard_map/to_method.rb +89 -89
- data/lib/solargraph/yardoc.rb +87 -87
- data/lib/solargraph.rb +105 -105
- data/rbs_collection.yaml +1 -1
- metadata +12 -12
- /data/{sig → rbs}/shims/ast/0/node.rbs +0 -0
- /data/{sig → rbs}/shims/ast/2.4/.rbs_meta.yaml +0 -0
- /data/{sig → rbs}/shims/ast/2.4/ast.rbs +0 -0
- /data/{sig → rbs}/shims/parser/3.2.0.1/builders/default.rbs +0 -0
- /data/{sig → rbs}/shims/parser/3.2.0.1/manifest.yaml +0 -0
- /data/{sig → rbs}/shims/parser/3.2.0.1/parser.rbs +0 -0
- /data/{sig → rbs}/shims/parser/3.2.0.1/polyfill.rbs +0 -0
- /data/{sig → rbs}/shims/thor/1.2.0.1/.rbs_meta.yaml +0 -0
- /data/{sig → rbs}/shims/thor/1.2.0.1/manifest.yaml +0 -0
- /data/{sig → rbs}/shims/thor/1.2.0.1/thor.rbs +0 -0
|
@@ -1,193 +1,193 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Solargraph
|
|
4
|
-
class ApiMap
|
|
5
|
-
class Index
|
|
6
|
-
include Logging
|
|
7
|
-
|
|
8
|
-
# @param pins [Array<Pin::Base>]
|
|
9
|
-
def initialize pins = []
|
|
10
|
-
catalog pins
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
# @return [Array<Pin::Base>]
|
|
14
|
-
def pins
|
|
15
|
-
@pins ||= []
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
# @return [Hash{String => Array<Pin::Namespace>}]
|
|
19
|
-
def namespace_hash
|
|
20
|
-
# @param h [String]
|
|
21
|
-
# @param k [Array<Pin::Namespace>]
|
|
22
|
-
@namespace_hash ||= Hash.new { |h, k| h[k] = [] }
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
# @return [Hash{String => Array<Pin::Base>}]
|
|
26
|
-
def pin_class_hash
|
|
27
|
-
# @param h [String]
|
|
28
|
-
# @param k [Array<Pin::Base>]
|
|
29
|
-
@pin_class_hash ||= Hash.new { |h, k| h[k] = [] }
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# @return [Hash{String => Array<Pin::Base>}]
|
|
33
|
-
def path_pin_hash
|
|
34
|
-
# @param h [String]
|
|
35
|
-
# @param k [Array<Pin::Base>]
|
|
36
|
-
@path_pin_hash ||= Hash.new { |h, k| h[k] = [] }
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
# @generic T
|
|
40
|
-
# @param klass [Class<generic<T>>]
|
|
41
|
-
# @return [Set<generic<T>>]
|
|
42
|
-
def pins_by_class klass
|
|
43
|
-
# @type [Set<Solargraph::Pin::Base>]
|
|
44
|
-
s = Set.new
|
|
45
|
-
# @sg-ignore need to support destructured args in blocks
|
|
46
|
-
@pin_select_cache[klass] ||= pin_class_hash.each_with_object(s) { |(key, o), n| n.merge(o) if key <= klass }
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
# @return [Hash{String => Array<String>}]
|
|
50
|
-
def include_references
|
|
51
|
-
# @param h [String]
|
|
52
|
-
# @param k [Array<String>]
|
|
53
|
-
@include_references ||= Hash.new { |h, k| h[k] = [] }
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
# @return [Hash{String => Array<Pin::Reference::Include>}]
|
|
57
|
-
def include_reference_pins
|
|
58
|
-
# @param h [String]
|
|
59
|
-
# @param k [Array<Pin::Reference::Include>]
|
|
60
|
-
@include_reference_pins ||= Hash.new { |h, k| h[k] = [] }
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
# @return [Hash{String => Array<String>}]
|
|
64
|
-
def extend_references
|
|
65
|
-
# @param h [String]
|
|
66
|
-
# @param k [Array<String>]
|
|
67
|
-
@extend_references ||= Hash.new { |h, k| h[k] = [] }
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
# @return [Hash{String => Array<String>}]
|
|
71
|
-
def prepend_references
|
|
72
|
-
# @param h [String]
|
|
73
|
-
# @param k [Array<String>]
|
|
74
|
-
@prepend_references ||= Hash.new { |h, k| h[k] = [] }
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
# @return [Hash{String => Array<String>}]
|
|
78
|
-
def superclass_references
|
|
79
|
-
# @param h [String]
|
|
80
|
-
# @param k [Array<String>]
|
|
81
|
-
@superclass_references ||= Hash.new { |h, k| h[k] = [] }
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
# @param pins [Enumerable<Pin::Base>]
|
|
85
|
-
# @return [self]
|
|
86
|
-
def merge pins
|
|
87
|
-
deep_clone.catalog pins
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
protected
|
|
91
|
-
|
|
92
|
-
attr_writer :pins, :pin_select_cache, :namespace_hash, :pin_class_hash, :path_pin_hash, :include_references,
|
|
93
|
-
:extend_references, :prepend_references, :superclass_references
|
|
94
|
-
|
|
95
|
-
# @return [self]
|
|
96
|
-
def deep_clone
|
|
97
|
-
Index.allocate.tap do |copy|
|
|
98
|
-
copy.pin_select_cache = {}
|
|
99
|
-
copy.pins = pins.clone
|
|
100
|
-
%i[
|
|
101
|
-
namespace_hash pin_class_hash path_pin_hash include_references extend_references prepend_references
|
|
102
|
-
superclass_references
|
|
103
|
-
].each do |sym|
|
|
104
|
-
copy.send("#{sym}=", send(sym).clone)
|
|
105
|
-
copy.send(sym)&.transform_values!(&:clone)
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
# @param new_pins [Enumerable<Pin::Base>]
|
|
111
|
-
#
|
|
112
|
-
# @return [self]
|
|
113
|
-
def catalog new_pins
|
|
114
|
-
# @type [Hash{Class<generic<T>> => Set<generic<T>>}]
|
|
115
|
-
@pin_select_cache = {}
|
|
116
|
-
pins.concat new_pins
|
|
117
|
-
set = new_pins.to_set
|
|
118
|
-
# @param k [String]
|
|
119
|
-
# @param v [Set<Pin::Base>]
|
|
120
|
-
set.classify(&:class)
|
|
121
|
-
.map { |k, v| pin_class_hash[k].concat v.to_a }
|
|
122
|
-
# @param k [String]
|
|
123
|
-
# @param v [Set<Pin::Namespace>]
|
|
124
|
-
set.classify(&:namespace)
|
|
125
|
-
.map { |k, v| namespace_hash[k].concat v.to_a }
|
|
126
|
-
# @param k [String]
|
|
127
|
-
# @param v [Set<Pin::Base>]
|
|
128
|
-
set.classify(&:path)
|
|
129
|
-
.map { |k, v| path_pin_hash[k].concat v.to_a }
|
|
130
|
-
@namespaces = path_pin_hash.keys.compact.to_set
|
|
131
|
-
map_references Pin::Reference::Include, include_references
|
|
132
|
-
map_references Pin::Reference::Prepend, prepend_references
|
|
133
|
-
map_references Pin::Reference::Extend, extend_references
|
|
134
|
-
map_references Pin::Reference::Superclass, superclass_references
|
|
135
|
-
map_overrides
|
|
136
|
-
self
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
# @generic T
|
|
140
|
-
# @param klass [Class<generic<T>>]
|
|
141
|
-
# @param hash [Hash{String => generic<T>}]
|
|
142
|
-
#
|
|
143
|
-
# @return [void]
|
|
144
|
-
def map_references klass, hash
|
|
145
|
-
# @param pin [generic<T>]
|
|
146
|
-
pins_by_class(klass).each do |pin|
|
|
147
|
-
hash[pin.namespace].push pin
|
|
148
|
-
end
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
# @return [void]
|
|
152
|
-
def map_overrides
|
|
153
|
-
# @param ovr [Pin::Reference::Override]
|
|
154
|
-
pins_by_class(Pin::Reference::Override).each do |ovr|
|
|
155
|
-
logger.debug { "ApiMap::Index#map_overrides: Looking at override #{ovr} for #{ovr.name}" }
|
|
156
|
-
pins = path_pin_hash[ovr.name]
|
|
157
|
-
logger.debug { "ApiMap::Index#map_overrides: pins for path=#{ovr.name}: #{pins}" }
|
|
158
|
-
pins.each do |pin|
|
|
159
|
-
new_pin = if pin.path.end_with?('#initialize')
|
|
160
|
-
path_pin_hash[pin.path.sub(/#initialize/, '.new')].first
|
|
161
|
-
end
|
|
162
|
-
(ovr.tags.map(&:tag_name) + ovr.delete).uniq.each do |tag|
|
|
163
|
-
pin.docstring.delete_tags tag
|
|
164
|
-
new_pin.docstring.delete_tags tag if new_pin
|
|
165
|
-
end
|
|
166
|
-
ovr.tags.each do |tag|
|
|
167
|
-
pin.docstring.add_tag(tag)
|
|
168
|
-
redefine_return_type pin, tag
|
|
169
|
-
if new_pin
|
|
170
|
-
new_pin.docstring.add_tag(tag)
|
|
171
|
-
redefine_return_type new_pin, tag
|
|
172
|
-
end
|
|
173
|
-
end
|
|
174
|
-
end
|
|
175
|
-
end
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
# @param pin [Pin::Method]
|
|
179
|
-
# @param tag [YARD::Tags::Tag]
|
|
180
|
-
# @return [void]
|
|
181
|
-
def redefine_return_type pin, tag
|
|
182
|
-
# @todo can this be made to not mutate existing pins and use
|
|
183
|
-
# proxy() / proxy_with_signatures() instead?
|
|
184
|
-
return unless pin && tag.tag_name == 'return'
|
|
185
|
-
pin.instance_variable_set(:@return_type, ComplexType.try_parse(tag.type))
|
|
186
|
-
pin.signatures.each do |sig|
|
|
187
|
-
sig.instance_variable_set(:@return_type, ComplexType.try_parse(tag.type))
|
|
188
|
-
end
|
|
189
|
-
pin.reset_generated!
|
|
190
|
-
end
|
|
191
|
-
end
|
|
192
|
-
end
|
|
193
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
class ApiMap
|
|
5
|
+
class Index
|
|
6
|
+
include Logging
|
|
7
|
+
|
|
8
|
+
# @param pins [Array<Pin::Base>]
|
|
9
|
+
def initialize pins = []
|
|
10
|
+
catalog pins
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# @return [Array<Pin::Base>]
|
|
14
|
+
def pins
|
|
15
|
+
@pins ||= []
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# @return [Hash{String => Array<Pin::Namespace>}]
|
|
19
|
+
def namespace_hash
|
|
20
|
+
# @param h [String]
|
|
21
|
+
# @param k [Array<Pin::Namespace>]
|
|
22
|
+
@namespace_hash ||= Hash.new { |h, k| h[k] = [] }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# @return [Hash{String => Array<Pin::Base>}]
|
|
26
|
+
def pin_class_hash
|
|
27
|
+
# @param h [String]
|
|
28
|
+
# @param k [Array<Pin::Base>]
|
|
29
|
+
@pin_class_hash ||= Hash.new { |h, k| h[k] = [] }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# @return [Hash{String => Array<Pin::Base>}]
|
|
33
|
+
def path_pin_hash
|
|
34
|
+
# @param h [String]
|
|
35
|
+
# @param k [Array<Pin::Base>]
|
|
36
|
+
@path_pin_hash ||= Hash.new { |h, k| h[k] = [] }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# @generic T
|
|
40
|
+
# @param klass [Class<generic<T>>]
|
|
41
|
+
# @return [Set<generic<T>>]
|
|
42
|
+
def pins_by_class klass
|
|
43
|
+
# @type [Set<Solargraph::Pin::Base>]
|
|
44
|
+
s = Set.new
|
|
45
|
+
# @sg-ignore need to support destructured args in blocks
|
|
46
|
+
@pin_select_cache[klass] ||= pin_class_hash.each_with_object(s) { |(key, o), n| n.merge(o) if key <= klass }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# @return [Hash{String => Array<String>}]
|
|
50
|
+
def include_references
|
|
51
|
+
# @param h [String]
|
|
52
|
+
# @param k [Array<String>]
|
|
53
|
+
@include_references ||= Hash.new { |h, k| h[k] = [] }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# @return [Hash{String => Array<Pin::Reference::Include>}]
|
|
57
|
+
def include_reference_pins
|
|
58
|
+
# @param h [String]
|
|
59
|
+
# @param k [Array<Pin::Reference::Include>]
|
|
60
|
+
@include_reference_pins ||= Hash.new { |h, k| h[k] = [] }
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# @return [Hash{String => Array<String>}]
|
|
64
|
+
def extend_references
|
|
65
|
+
# @param h [String]
|
|
66
|
+
# @param k [Array<String>]
|
|
67
|
+
@extend_references ||= Hash.new { |h, k| h[k] = [] }
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# @return [Hash{String => Array<String>}]
|
|
71
|
+
def prepend_references
|
|
72
|
+
# @param h [String]
|
|
73
|
+
# @param k [Array<String>]
|
|
74
|
+
@prepend_references ||= Hash.new { |h, k| h[k] = [] }
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# @return [Hash{String => Array<String>}]
|
|
78
|
+
def superclass_references
|
|
79
|
+
# @param h [String]
|
|
80
|
+
# @param k [Array<String>]
|
|
81
|
+
@superclass_references ||= Hash.new { |h, k| h[k] = [] }
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# @param pins [Enumerable<Pin::Base>]
|
|
85
|
+
# @return [self]
|
|
86
|
+
def merge pins
|
|
87
|
+
deep_clone.catalog pins
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
protected
|
|
91
|
+
|
|
92
|
+
attr_writer :pins, :pin_select_cache, :namespace_hash, :pin_class_hash, :path_pin_hash, :include_references,
|
|
93
|
+
:extend_references, :prepend_references, :superclass_references
|
|
94
|
+
|
|
95
|
+
# @return [self]
|
|
96
|
+
def deep_clone
|
|
97
|
+
Index.allocate.tap do |copy|
|
|
98
|
+
copy.pin_select_cache = {}
|
|
99
|
+
copy.pins = pins.clone
|
|
100
|
+
%i[
|
|
101
|
+
namespace_hash pin_class_hash path_pin_hash include_references extend_references prepend_references
|
|
102
|
+
superclass_references
|
|
103
|
+
].each do |sym|
|
|
104
|
+
copy.send("#{sym}=", send(sym).clone)
|
|
105
|
+
copy.send(sym)&.transform_values!(&:clone)
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# @param new_pins [Enumerable<Pin::Base>]
|
|
111
|
+
#
|
|
112
|
+
# @return [self]
|
|
113
|
+
def catalog new_pins
|
|
114
|
+
# @type [Hash{Class<generic<T>> => Set<generic<T>>}]
|
|
115
|
+
@pin_select_cache = {}
|
|
116
|
+
pins.concat new_pins
|
|
117
|
+
set = new_pins.to_set
|
|
118
|
+
# @param k [String]
|
|
119
|
+
# @param v [Set<Pin::Base>]
|
|
120
|
+
set.classify(&:class)
|
|
121
|
+
.map { |k, v| pin_class_hash[k].concat v.to_a }
|
|
122
|
+
# @param k [String]
|
|
123
|
+
# @param v [Set<Pin::Namespace>]
|
|
124
|
+
set.classify(&:namespace)
|
|
125
|
+
.map { |k, v| namespace_hash[k].concat v.to_a }
|
|
126
|
+
# @param k [String]
|
|
127
|
+
# @param v [Set<Pin::Base>]
|
|
128
|
+
set.classify(&:path)
|
|
129
|
+
.map { |k, v| path_pin_hash[k].concat v.to_a }
|
|
130
|
+
@namespaces = path_pin_hash.keys.compact.to_set
|
|
131
|
+
map_references Pin::Reference::Include, include_references
|
|
132
|
+
map_references Pin::Reference::Prepend, prepend_references
|
|
133
|
+
map_references Pin::Reference::Extend, extend_references
|
|
134
|
+
map_references Pin::Reference::Superclass, superclass_references
|
|
135
|
+
map_overrides
|
|
136
|
+
self
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
# @generic T
|
|
140
|
+
# @param klass [Class<generic<T>>]
|
|
141
|
+
# @param hash [Hash{String => generic<T>}]
|
|
142
|
+
#
|
|
143
|
+
# @return [void]
|
|
144
|
+
def map_references klass, hash
|
|
145
|
+
# @param pin [generic<T>]
|
|
146
|
+
pins_by_class(klass).each do |pin|
|
|
147
|
+
hash[pin.namespace].push pin
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# @return [void]
|
|
152
|
+
def map_overrides
|
|
153
|
+
# @param ovr [Pin::Reference::Override]
|
|
154
|
+
pins_by_class(Pin::Reference::Override).each do |ovr|
|
|
155
|
+
logger.debug { "ApiMap::Index#map_overrides: Looking at override #{ovr} for #{ovr.name}" }
|
|
156
|
+
pins = path_pin_hash[ovr.name]
|
|
157
|
+
logger.debug { "ApiMap::Index#map_overrides: pins for path=#{ovr.name}: #{pins}" }
|
|
158
|
+
pins.each do |pin|
|
|
159
|
+
new_pin = if pin.path.end_with?('#initialize')
|
|
160
|
+
path_pin_hash[pin.path.sub(/#initialize/, '.new')].first
|
|
161
|
+
end
|
|
162
|
+
(ovr.tags.map(&:tag_name) + ovr.delete).uniq.each do |tag|
|
|
163
|
+
pin.docstring.delete_tags tag
|
|
164
|
+
new_pin.docstring.delete_tags tag if new_pin
|
|
165
|
+
end
|
|
166
|
+
ovr.tags.each do |tag|
|
|
167
|
+
pin.docstring.add_tag(tag)
|
|
168
|
+
redefine_return_type pin, tag
|
|
169
|
+
if new_pin
|
|
170
|
+
new_pin.docstring.add_tag(tag)
|
|
171
|
+
redefine_return_type new_pin, tag
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
# @param pin [Pin::Method]
|
|
179
|
+
# @param tag [YARD::Tags::Tag]
|
|
180
|
+
# @return [void]
|
|
181
|
+
def redefine_return_type pin, tag
|
|
182
|
+
# @todo can this be made to not mutate existing pins and use
|
|
183
|
+
# proxy() / proxy_with_signatures() instead?
|
|
184
|
+
return unless pin && tag.tag_name == 'return'
|
|
185
|
+
pin.instance_variable_set(:@return_type, ComplexType.try_parse(tag.type))
|
|
186
|
+
pin.signatures.each do |sig|
|
|
187
|
+
sig.instance_variable_set(:@return_type, ComplexType.try_parse(tag.type))
|
|
188
|
+
end
|
|
189
|
+
pin.reset_generated!
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
end
|
|
@@ -1,97 +1,97 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Solargraph
|
|
4
|
-
class ApiMap
|
|
5
|
-
module SourceToYard
|
|
6
|
-
|
|
7
|
-
# Get the YARD CodeObject at the specified path.
|
|
8
|
-
#
|
|
9
|
-
# @generic T
|
|
10
|
-
# @param path [String]
|
|
11
|
-
# @param klass [Class<generic<T>>]
|
|
12
|
-
# @return [generic<T>, nil]
|
|
13
|
-
def code_object_at path, klass = YARD::CodeObjects::Base
|
|
14
|
-
obj = code_object_map[path]
|
|
15
|
-
obj if obj&.is_a?(klass)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
# @return [Array<String>]
|
|
19
|
-
def code_object_paths
|
|
20
|
-
code_object_map.keys
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# @param store [ApiMap::Store] ApiMap pin store
|
|
24
|
-
# @return [void]
|
|
25
|
-
def rake_yard store
|
|
26
|
-
YARD::Registry.clear
|
|
27
|
-
code_object_map.clear
|
|
28
|
-
store.namespace_pins.each do |pin|
|
|
29
|
-
next if pin.path.nil? || pin.path.empty?
|
|
30
|
-
if pin.code_object
|
|
31
|
-
code_object_map[pin.path] ||= pin.code_object
|
|
32
|
-
next
|
|
33
|
-
end
|
|
34
|
-
if pin.type == :class
|
|
35
|
-
# @param obj [YARD::CodeObjects::RootObject]
|
|
36
|
-
code_object_map[pin.path] ||= YARD::CodeObjects::ClassObject.new(root_code_object, pin.path) { |obj|
|
|
37
|
-
next if pin.location.nil? || pin.location.filename.nil?
|
|
38
|
-
obj.add_file(pin.location.filename, pin.location.range.start.line, !pin.comments.empty?)
|
|
39
|
-
}
|
|
40
|
-
else
|
|
41
|
-
# @param obj [YARD::CodeObjects::RootObject]
|
|
42
|
-
code_object_map[pin.path] ||= YARD::CodeObjects::ModuleObject.new(root_code_object, pin.path) { |obj|
|
|
43
|
-
next if pin.location.nil? || pin.location.filename.nil?
|
|
44
|
-
obj.add_file(pin.location.filename, pin.location.range.start.line, !pin.comments.empty?)
|
|
45
|
-
}
|
|
46
|
-
end
|
|
47
|
-
code_object_map[pin.path].docstring = pin.docstring
|
|
48
|
-
store.get_includes(pin.path).each do |ref|
|
|
49
|
-
include_object = code_object_at(pin.path, YARD::CodeObjects::ClassObject)
|
|
50
|
-
unless include_object.nil? || include_object.nil?
|
|
51
|
-
include_object.instance_mixins.push code_object_map[ref.type.to_s]
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
store.get_extends(pin.path).each do |ref|
|
|
55
|
-
extend_object = code_object_at(pin.path, YARD::CodeObjects::ClassObject)
|
|
56
|
-
next unless extend_object
|
|
57
|
-
code_object = code_object_map[ref.type.to_s]
|
|
58
|
-
next unless code_object
|
|
59
|
-
extend_object.class_mixins.push code_object
|
|
60
|
-
# @todo add spec showing why this next line is necessary
|
|
61
|
-
extend_object.instance_mixins.push code_object
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
store.method_pins.each do |pin|
|
|
65
|
-
if pin.code_object
|
|
66
|
-
code_object_map[pin.path] ||= pin.code_object
|
|
67
|
-
next
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
# @param obj [YARD::CodeObjects::RootObject]
|
|
71
|
-
code_object_map[pin.path] ||= YARD::CodeObjects::MethodObject.new(code_object_at(pin.namespace, YARD::CodeObjects::NamespaceObject), pin.name, pin.scope) { |obj|
|
|
72
|
-
next if pin.location.nil? || pin.location.filename.nil?
|
|
73
|
-
obj.add_file pin.location.filename, pin.location.range.start.line
|
|
74
|
-
}
|
|
75
|
-
method_object = code_object_at(pin.path, YARD::CodeObjects::MethodObject)
|
|
76
|
-
method_object.docstring = pin.docstring
|
|
77
|
-
method_object.visibility = pin.visibility || :public
|
|
78
|
-
method_object.parameters = pin.parameters.map do |p|
|
|
79
|
-
[p.full_name, p.asgn_code]
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
private
|
|
85
|
-
|
|
86
|
-
# @return [Hash{String => YARD::CodeObjects::Base}]
|
|
87
|
-
def code_object_map
|
|
88
|
-
@code_object_map ||= {}
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
# @return [YARD::CodeObjects::RootObject]
|
|
92
|
-
def root_code_object
|
|
93
|
-
@root_code_object ||= YARD::CodeObjects::RootObject.new(nil, 'root')
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
class ApiMap
|
|
5
|
+
module SourceToYard
|
|
6
|
+
|
|
7
|
+
# Get the YARD CodeObject at the specified path.
|
|
8
|
+
#
|
|
9
|
+
# @generic T
|
|
10
|
+
# @param path [String]
|
|
11
|
+
# @param klass [Class<generic<T>>]
|
|
12
|
+
# @return [generic<T>, nil]
|
|
13
|
+
def code_object_at path, klass = YARD::CodeObjects::Base
|
|
14
|
+
obj = code_object_map[path]
|
|
15
|
+
obj if obj&.is_a?(klass)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# @return [Array<String>]
|
|
19
|
+
def code_object_paths
|
|
20
|
+
code_object_map.keys
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# @param store [ApiMap::Store] ApiMap pin store
|
|
24
|
+
# @return [void]
|
|
25
|
+
def rake_yard store
|
|
26
|
+
YARD::Registry.clear
|
|
27
|
+
code_object_map.clear
|
|
28
|
+
store.namespace_pins.each do |pin|
|
|
29
|
+
next if pin.path.nil? || pin.path.empty?
|
|
30
|
+
if pin.code_object
|
|
31
|
+
code_object_map[pin.path] ||= pin.code_object
|
|
32
|
+
next
|
|
33
|
+
end
|
|
34
|
+
if pin.type == :class
|
|
35
|
+
# @param obj [YARD::CodeObjects::RootObject]
|
|
36
|
+
code_object_map[pin.path] ||= YARD::CodeObjects::ClassObject.new(root_code_object, pin.path) { |obj|
|
|
37
|
+
next if pin.location.nil? || pin.location.filename.nil?
|
|
38
|
+
obj.add_file(pin.location.filename, pin.location.range.start.line, !pin.comments.empty?)
|
|
39
|
+
}
|
|
40
|
+
else
|
|
41
|
+
# @param obj [YARD::CodeObjects::RootObject]
|
|
42
|
+
code_object_map[pin.path] ||= YARD::CodeObjects::ModuleObject.new(root_code_object, pin.path) { |obj|
|
|
43
|
+
next if pin.location.nil? || pin.location.filename.nil?
|
|
44
|
+
obj.add_file(pin.location.filename, pin.location.range.start.line, !pin.comments.empty?)
|
|
45
|
+
}
|
|
46
|
+
end
|
|
47
|
+
code_object_map[pin.path].docstring = pin.docstring
|
|
48
|
+
store.get_includes(pin.path).each do |ref|
|
|
49
|
+
include_object = code_object_at(pin.path, YARD::CodeObjects::ClassObject)
|
|
50
|
+
unless include_object.nil? || include_object.nil?
|
|
51
|
+
include_object.instance_mixins.push code_object_map[ref.type.to_s]
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
store.get_extends(pin.path).each do |ref|
|
|
55
|
+
extend_object = code_object_at(pin.path, YARD::CodeObjects::ClassObject)
|
|
56
|
+
next unless extend_object
|
|
57
|
+
code_object = code_object_map[ref.type.to_s]
|
|
58
|
+
next unless code_object
|
|
59
|
+
extend_object.class_mixins.push code_object
|
|
60
|
+
# @todo add spec showing why this next line is necessary
|
|
61
|
+
extend_object.instance_mixins.push code_object
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
store.method_pins.each do |pin|
|
|
65
|
+
if pin.code_object
|
|
66
|
+
code_object_map[pin.path] ||= pin.code_object
|
|
67
|
+
next
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# @param obj [YARD::CodeObjects::RootObject]
|
|
71
|
+
code_object_map[pin.path] ||= YARD::CodeObjects::MethodObject.new(code_object_at(pin.namespace, YARD::CodeObjects::NamespaceObject), pin.name, pin.scope) { |obj|
|
|
72
|
+
next if pin.location.nil? || pin.location.filename.nil?
|
|
73
|
+
obj.add_file pin.location.filename, pin.location.range.start.line
|
|
74
|
+
}
|
|
75
|
+
method_object = code_object_at(pin.path, YARD::CodeObjects::MethodObject)
|
|
76
|
+
method_object.docstring = pin.docstring
|
|
77
|
+
method_object.visibility = pin.visibility || :public
|
|
78
|
+
method_object.parameters = pin.parameters.map do |p|
|
|
79
|
+
[p.full_name, p.asgn_code]
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
private
|
|
85
|
+
|
|
86
|
+
# @return [Hash{String => YARD::CodeObjects::Base}]
|
|
87
|
+
def code_object_map
|
|
88
|
+
@code_object_map ||= {}
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# @return [YARD::CodeObjects::RootObject]
|
|
92
|
+
def root_code_object
|
|
93
|
+
@root_code_object ||= YARD::CodeObjects::RootObject.new(nil, 'root')
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|