solargraph 0.58.1 → 0.59.0.dev.1
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/.envrc +3 -0
- data/.github/workflows/linting.yml +4 -5
- data/.github/workflows/plugins.yml +40 -36
- data/.github/workflows/rspec.yml +45 -13
- data/.github/workflows/typecheck.yml +2 -2
- data/.rubocop_todo.yml +27 -49
- data/README.md +3 -3
- data/Rakefile +1 -0
- data/lib/solargraph/api_map/cache.rb +110 -110
- data/lib/solargraph/api_map/constants.rb +289 -279
- data/lib/solargraph/api_map/index.rb +204 -193
- data/lib/solargraph/api_map/source_to_yard.rb +109 -97
- data/lib/solargraph/api_map/store.rb +387 -384
- data/lib/solargraph/api_map.rb +1000 -945
- data/lib/solargraph/complex_type/conformance.rb +176 -0
- data/lib/solargraph/complex_type/type_methods.rb +242 -228
- data/lib/solargraph/complex_type/unique_type.rb +632 -482
- data/lib/solargraph/complex_type.rb +549 -444
- data/lib/solargraph/convention/data_definition/data_definition_node.rb +93 -91
- data/lib/solargraph/convention/data_definition.rb +108 -105
- data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +62 -61
- data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +103 -102
- data/lib/solargraph/convention/struct_definition.rb +168 -164
- data/lib/solargraph/diagnostics/require_not_found.rb +54 -53
- data/lib/solargraph/diagnostics/rubocop.rb +119 -118
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +70 -68
- data/lib/solargraph/diagnostics/type_check.rb +56 -55
- data/lib/solargraph/doc_map.rb +200 -439
- data/lib/solargraph/equality.rb +34 -34
- data/lib/solargraph/gem_pins.rb +97 -98
- data/lib/solargraph/language_server/host/dispatch.rb +131 -130
- data/lib/solargraph/language_server/host/message_worker.rb +113 -112
- data/lib/solargraph/language_server/host/sources.rb +100 -99
- data/lib/solargraph/language_server/host.rb +883 -878
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +109 -114
- data/lib/solargraph/language_server/message/extended/document.rb +24 -23
- data/lib/solargraph/language_server/message/text_document/completion.rb +58 -56
- data/lib/solargraph/language_server/message/text_document/definition.rb +42 -40
- data/lib/solargraph/language_server/message/text_document/document_symbol.rb +28 -26
- data/lib/solargraph/language_server/message/text_document/formatting.rb +150 -148
- data/lib/solargraph/language_server/message/text_document/hover.rb +60 -58
- data/lib/solargraph/language_server/message/text_document/signature_help.rb +25 -24
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +27 -25
- data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +25 -23
- data/lib/solargraph/library.rb +729 -683
- data/lib/solargraph/location.rb +87 -82
- data/lib/solargraph/logging.rb +57 -37
- data/lib/solargraph/parser/comment_ripper.rb +76 -69
- data/lib/solargraph/parser/flow_sensitive_typing.rb +483 -255
- data/lib/solargraph/parser/node_processor/base.rb +122 -92
- data/lib/solargraph/parser/node_processor.rb +63 -62
- data/lib/solargraph/parser/parser_gem/class_methods.rb +167 -149
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +191 -166
- data/lib/solargraph/parser/parser_gem/node_methods.rb +506 -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 +61 -59
- data/lib/solargraph/parser/parser_gem/node_processors/begin_node.rb +24 -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 +60 -53
- data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +53 -23
- data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +41 -40
- data/lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb +30 -29
- data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +61 -59
- data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +98 -98
- data/lib/solargraph/parser/parser_gem/node_processors/or_node.rb +22 -0
- data/lib/solargraph/parser/parser_gem/node_processors/orasgn_node.rb +17 -17
- data/lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb +39 -38
- data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +53 -52
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +296 -291
- data/lib/solargraph/parser/parser_gem/node_processors/when_node.rb +23 -0
- data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +33 -29
- data/lib/solargraph/parser/parser_gem/node_processors.rb +74 -70
- data/lib/solargraph/parser/region.rb +75 -69
- data/lib/solargraph/parser/snippet.rb +17 -17
- data/lib/solargraph/pin/base.rb +761 -729
- data/lib/solargraph/pin/base_variable.rb +418 -126
- data/lib/solargraph/pin/block.rb +126 -104
- data/lib/solargraph/pin/breakable.rb +13 -9
- data/lib/solargraph/pin/callable.rb +278 -231
- data/lib/solargraph/pin/closure.rb +68 -72
- data/lib/solargraph/pin/common.rb +94 -79
- data/lib/solargraph/pin/compound_statement.rb +55 -0
- data/lib/solargraph/pin/conversions.rb +124 -123
- data/lib/solargraph/pin/delegated_method.rb +131 -120
- data/lib/solargraph/pin/documenting.rb +115 -114
- data/lib/solargraph/pin/instance_variable.rb +38 -34
- data/lib/solargraph/pin/keyword.rb +16 -20
- data/lib/solargraph/pin/local_variable.rb +31 -75
- data/lib/solargraph/pin/method.rb +720 -672
- data/lib/solargraph/pin/method_alias.rb +42 -34
- data/lib/solargraph/pin/namespace.rb +121 -115
- data/lib/solargraph/pin/parameter.rb +338 -275
- data/lib/solargraph/pin/proxy_type.rb +40 -39
- data/lib/solargraph/pin/reference/override.rb +47 -47
- data/lib/solargraph/pin/reference/superclass.rb +17 -15
- data/lib/solargraph/pin/reference.rb +41 -39
- data/lib/solargraph/pin/search.rb +62 -61
- data/lib/solargraph/pin/signature.rb +69 -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 +46 -44
- data/lib/solargraph/pin_cache.rb +665 -245
- data/lib/solargraph/position.rb +118 -119
- data/lib/solargraph/range.rb +112 -112
- data/lib/solargraph/rbs_map/conversions.rb +846 -823
- data/lib/solargraph/rbs_map/core_map.rb +65 -58
- data/lib/solargraph/rbs_map/stdlib_map.rb +72 -43
- data/lib/solargraph/rbs_map.rb +217 -163
- data/lib/solargraph/shell.rb +397 -352
- data/lib/solargraph/source/chain/call.rb +372 -337
- data/lib/solargraph/source/chain/constant.rb +28 -26
- data/lib/solargraph/source/chain/hash.rb +35 -34
- data/lib/solargraph/source/chain/if.rb +29 -28
- data/lib/solargraph/source/chain/instance_variable.rb +34 -13
- data/lib/solargraph/source/chain/literal.rb +53 -48
- data/lib/solargraph/source/chain/or.rb +31 -23
- data/lib/solargraph/source/chain.rb +294 -291
- data/lib/solargraph/source/change.rb +89 -82
- data/lib/solargraph/source/cursor.rb +172 -166
- data/lib/solargraph/source/source_chainer.rb +204 -194
- data/lib/solargraph/source/updater.rb +59 -55
- data/lib/solargraph/source.rb +524 -498
- data/lib/solargraph/source_map/clip.rb +237 -226
- data/lib/solargraph/source_map/data.rb +37 -34
- data/lib/solargraph/source_map/mapper.rb +282 -259
- data/lib/solargraph/source_map.rb +220 -212
- data/lib/solargraph/type_checker/problem.rb +34 -32
- data/lib/solargraph/type_checker/rules.rb +157 -84
- data/lib/solargraph/type_checker.rb +895 -814
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/workspace/config.rb +257 -255
- data/lib/solargraph/workspace/gemspecs.rb +367 -0
- data/lib/solargraph/workspace/require_paths.rb +98 -97
- data/lib/solargraph/workspace.rb +362 -220
- data/lib/solargraph/yard_map/helpers.rb +45 -44
- data/lib/solargraph/yard_map/mapper/to_method.rb +134 -130
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +32 -31
- data/lib/solargraph/yard_map/mapper.rb +84 -79
- data/lib/solargraph/yardoc.rb +97 -87
- data/lib/solargraph.rb +126 -105
- data/rbs/fills/rubygems/0/dependency.rbs +193 -0
- data/rbs/fills/tuple/tuple.rbs +28 -0
- data/rbs/shims/ast/0/node.rbs +5 -0
- data/rbs/shims/diff-lcs/1.5/diff-lcs.rbs +11 -0
- data/rbs_collection.yaml +1 -1
- data/solargraph.gemspec +2 -1
- metadata +22 -17
- data/lib/solargraph/type_checker/checks.rb +0 -124
- data/lib/solargraph/type_checker/param_def.rb +0 -37
- data/lib/solargraph/yard_map/to_method.rb +0 -89
- data/sig/shims/ast/0/node.rbs +0 -5
- /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,204 @@
|
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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
|
-
# @
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
pins.
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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<generic<T>>]
|
|
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<Pin::Reference::Include>}]
|
|
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<Pin::Reference::Extend>}]
|
|
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<Pin::Reference::Prepend>}]
|
|
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<Pin::Reference::Superclass>}]
|
|
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 => Array<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
|
+
# @todo should complain when type for 'ovr' is not provided
|
|
154
|
+
# @param ovr [Pin::Reference::Override]
|
|
155
|
+
pins_by_class(Pin::Reference::Override).each do |ovr|
|
|
156
|
+
logger.debug { "ApiMap::Index#map_overrides: Looking at override #{ovr} for #{ovr.name}" }
|
|
157
|
+
pins = path_pin_hash[ovr.name]
|
|
158
|
+
logger.debug { "ApiMap::Index#map_overrides: pins for path=#{ovr.name}: #{pins}" }
|
|
159
|
+
pins.each do |pin|
|
|
160
|
+
new_pin = if pin.path.end_with?('#initialize')
|
|
161
|
+
path_pin_hash[pin.path.sub(/#initialize/, '.new')].first
|
|
162
|
+
end
|
|
163
|
+
(ovr.tags.map(&:tag_name) + ovr.delete).uniq.each do |tag|
|
|
164
|
+
# @sg-ignore Wrong argument type for
|
|
165
|
+
# YARD::Docstring#delete_tags: name expected String,
|
|
166
|
+
# received String, Symbol - delete_tags is ok with a
|
|
167
|
+
# _ToS, but we should fix anyway
|
|
168
|
+
pin.docstring.delete_tags tag
|
|
169
|
+
# @sg-ignore Wrong argument type for
|
|
170
|
+
# YARD::Docstring#delete_tags: name expected String,
|
|
171
|
+
# received String, Symbol - delete_tags is ok with a
|
|
172
|
+
# _ToS, but we should fix anyway
|
|
173
|
+
new_pin.docstring.delete_tags tag if new_pin
|
|
174
|
+
end
|
|
175
|
+
ovr.tags.each do |tag|
|
|
176
|
+
pin.docstring.add_tag(tag)
|
|
177
|
+
redefine_return_type pin, tag
|
|
178
|
+
pin.reset_generated!
|
|
179
|
+
|
|
180
|
+
next unless new_pin
|
|
181
|
+
|
|
182
|
+
new_pin.docstring.add_tag(tag)
|
|
183
|
+
redefine_return_type new_pin, tag
|
|
184
|
+
new_pin.reset_generated!
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
# @param pin [Pin::Method]
|
|
191
|
+
# @param tag [YARD::Tags::Tag]
|
|
192
|
+
# @return [void]
|
|
193
|
+
def redefine_return_type pin, tag
|
|
194
|
+
# @todo can this be made to not mutate existing pins and use
|
|
195
|
+
# proxy() / proxy_with_signatures() instead?
|
|
196
|
+
return unless pin && tag.tag_name == 'return'
|
|
197
|
+
pin.instance_variable_set(:@return_type, ComplexType.try_parse(tag.type))
|
|
198
|
+
pin.signatures.each do |sig|
|
|
199
|
+
sig.instance_variable_set(:@return_type, ComplexType.try_parse(tag.type))
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
end
|
|
@@ -1,97 +1,109 @@
|
|
|
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
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
# @
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
|
|
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
|
+
# @sg-ignore Declared return type generic<T>, nil does not match
|
|
10
|
+
# inferred type ::YARD::CodeObjects::Base, nil for
|
|
11
|
+
# Solargraph::ApiMap::SourceToYard#code_object_at
|
|
12
|
+
# @generic T
|
|
13
|
+
# @param path [String]
|
|
14
|
+
# @param klass [Class<generic<T>>]
|
|
15
|
+
# @return [generic<T>, nil]
|
|
16
|
+
def code_object_at path, klass = YARD::CodeObjects::Base
|
|
17
|
+
obj = code_object_map[path]
|
|
18
|
+
obj if obj&.is_a?(klass)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# @return [Array<String>]
|
|
22
|
+
def code_object_paths
|
|
23
|
+
code_object_map.keys
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# @param store [ApiMap::Store] ApiMap pin store
|
|
27
|
+
# @return [void]
|
|
28
|
+
def rake_yard store
|
|
29
|
+
YARD::Registry.clear
|
|
30
|
+
code_object_map.clear
|
|
31
|
+
store.namespace_pins.each do |pin|
|
|
32
|
+
next if pin.path.nil? || pin.path.empty?
|
|
33
|
+
if pin.code_object
|
|
34
|
+
code_object_map[pin.path] ||= pin.code_object
|
|
35
|
+
next
|
|
36
|
+
end
|
|
37
|
+
if pin.type == :class
|
|
38
|
+
# @param obj [YARD::CodeObjects::RootObject]
|
|
39
|
+
code_object_map[pin.path] ||= YARD::CodeObjects::ClassObject.new(root_code_object, pin.path) { |obj|
|
|
40
|
+
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
41
|
+
next if pin.location.nil? || pin.location.filename.nil?
|
|
42
|
+
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
43
|
+
obj.add_file(pin.location.filename, pin.location.range.start.line, !pin.comments.empty?)
|
|
44
|
+
}
|
|
45
|
+
else
|
|
46
|
+
# @param obj [YARD::CodeObjects::RootObject]
|
|
47
|
+
code_object_map[pin.path] ||= YARD::CodeObjects::ModuleObject.new(root_code_object, pin.path) { |obj|
|
|
48
|
+
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
49
|
+
next if pin.location.nil? || pin.location.filename.nil?
|
|
50
|
+
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
51
|
+
obj.add_file(pin.location.filename, pin.location.range.start.line, !pin.comments.empty?)
|
|
52
|
+
}
|
|
53
|
+
end
|
|
54
|
+
code_object_map[pin.path].docstring = pin.docstring
|
|
55
|
+
store.get_includes(pin.path).each do |ref|
|
|
56
|
+
include_object = code_object_at(pin.path, YARD::CodeObjects::ClassObject)
|
|
57
|
+
unless include_object.nil? || include_object.nil?
|
|
58
|
+
include_object.instance_mixins.push code_object_map[ref.type.to_s]
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
store.get_extends(pin.path).each do |ref|
|
|
62
|
+
extend_object = code_object_at(pin.path, YARD::CodeObjects::ClassObject)
|
|
63
|
+
next unless extend_object
|
|
64
|
+
code_object = code_object_map[ref.type.to_s]
|
|
65
|
+
next unless code_object
|
|
66
|
+
extend_object.class_mixins.push code_object
|
|
67
|
+
extend_object.instance_mixins.push code_object
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
store.method_pins.each do |pin|
|
|
71
|
+
if pin.code_object
|
|
72
|
+
code_object_map[pin.path] ||= pin.code_object
|
|
73
|
+
next
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# @sg-ignore Need to add nil check here
|
|
77
|
+
# @param obj [YARD::CodeObjects::RootObject]
|
|
78
|
+
code_object_map[pin.path] ||= YARD::CodeObjects::MethodObject.new(code_object_at(pin.namespace, YARD::CodeObjects::NamespaceObject), pin.name, pin.scope) { |obj|
|
|
79
|
+
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
80
|
+
next if pin.location.nil? || pin.location.filename.nil?
|
|
81
|
+
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
82
|
+
obj.add_file pin.location.filename, pin.location.range.start.line
|
|
83
|
+
}
|
|
84
|
+
method_object = code_object_at(pin.path, YARD::CodeObjects::MethodObject)
|
|
85
|
+
# @sg-ignore Need to add nil check here
|
|
86
|
+
method_object.docstring = pin.docstring
|
|
87
|
+
# @sg-ignore Need to add nil check here
|
|
88
|
+
method_object.visibility = pin.visibility || :public
|
|
89
|
+
# @sg-ignore Need to add nil check here
|
|
90
|
+
method_object.parameters = pin.parameters.map do |p|
|
|
91
|
+
[p.full_name, p.asgn_code]
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
private
|
|
97
|
+
|
|
98
|
+
# @return [Hash{String => YARD::CodeObjects::Base}]
|
|
99
|
+
def code_object_map
|
|
100
|
+
@code_object_map ||= {}
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# @return [YARD::CodeObjects::RootObject]
|
|
104
|
+
def root_code_object
|
|
105
|
+
@root_code_object ||= YARD::CodeObjects::RootObject.new(nil, 'root')
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|