solargraph 0.58.0 → 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.
Files changed (166) hide show
  1. checksums.yaml +4 -4
  2. data/.envrc +3 -0
  3. data/.gitattributes +2 -0
  4. data/.github/workflows/linting.yml +4 -5
  5. data/.github/workflows/plugins.yml +40 -36
  6. data/.github/workflows/rspec.yml +45 -13
  7. data/.github/workflows/typecheck.yml +2 -2
  8. data/.rubocop_todo.yml +27 -49
  9. data/CHANGELOG.md +3 -0
  10. data/README.md +3 -3
  11. data/Rakefile +1 -0
  12. data/bin/solargraph +8 -8
  13. data/lib/solargraph/api_map/cache.rb +110 -110
  14. data/lib/solargraph/api_map/constants.rb +289 -279
  15. data/lib/solargraph/api_map/index.rb +204 -193
  16. data/lib/solargraph/api_map/source_to_yard.rb +109 -97
  17. data/lib/solargraph/api_map/store.rb +387 -384
  18. data/lib/solargraph/api_map.rb +1000 -945
  19. data/lib/solargraph/complex_type/conformance.rb +176 -0
  20. data/lib/solargraph/complex_type/type_methods.rb +242 -228
  21. data/lib/solargraph/complex_type/unique_type.rb +632 -482
  22. data/lib/solargraph/complex_type.rb +549 -444
  23. data/lib/solargraph/convention/data_definition/data_definition_node.rb +93 -91
  24. data/lib/solargraph/convention/data_definition.rb +108 -105
  25. data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +62 -61
  26. data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +103 -102
  27. data/lib/solargraph/convention/struct_definition.rb +168 -164
  28. data/lib/solargraph/diagnostics/require_not_found.rb +54 -53
  29. data/lib/solargraph/diagnostics/rubocop.rb +119 -118
  30. data/lib/solargraph/diagnostics/rubocop_helpers.rb +70 -68
  31. data/lib/solargraph/diagnostics/type_check.rb +56 -55
  32. data/lib/solargraph/doc_map.rb +200 -439
  33. data/lib/solargraph/equality.rb +34 -34
  34. data/lib/solargraph/gem_pins.rb +97 -98
  35. data/lib/solargraph/language_server/host/dispatch.rb +131 -130
  36. data/lib/solargraph/language_server/host/message_worker.rb +113 -112
  37. data/lib/solargraph/language_server/host/sources.rb +100 -99
  38. data/lib/solargraph/language_server/host.rb +883 -878
  39. data/lib/solargraph/language_server/message/extended/check_gem_version.rb +109 -114
  40. data/lib/solargraph/language_server/message/extended/document.rb +24 -23
  41. data/lib/solargraph/language_server/message/text_document/completion.rb +58 -56
  42. data/lib/solargraph/language_server/message/text_document/definition.rb +42 -40
  43. data/lib/solargraph/language_server/message/text_document/document_symbol.rb +28 -26
  44. data/lib/solargraph/language_server/message/text_document/formatting.rb +150 -148
  45. data/lib/solargraph/language_server/message/text_document/hover.rb +60 -58
  46. data/lib/solargraph/language_server/message/text_document/signature_help.rb +25 -24
  47. data/lib/solargraph/language_server/message/text_document/type_definition.rb +27 -25
  48. data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +25 -23
  49. data/lib/solargraph/library.rb +729 -683
  50. data/lib/solargraph/location.rb +87 -82
  51. data/lib/solargraph/logging.rb +57 -37
  52. data/lib/solargraph/parser/comment_ripper.rb +76 -69
  53. data/lib/solargraph/parser/flow_sensitive_typing.rb +483 -255
  54. data/lib/solargraph/parser/node_processor/base.rb +122 -92
  55. data/lib/solargraph/parser/node_processor.rb +63 -62
  56. data/lib/solargraph/parser/parser_gem/class_methods.rb +167 -149
  57. data/lib/solargraph/parser/parser_gem/node_chainer.rb +191 -166
  58. data/lib/solargraph/parser/parser_gem/node_methods.rb +506 -486
  59. data/lib/solargraph/parser/parser_gem/node_processors/and_node.rb +22 -22
  60. data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +61 -59
  61. data/lib/solargraph/parser/parser_gem/node_processors/begin_node.rb +24 -15
  62. data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +46 -46
  63. data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +60 -53
  64. data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +53 -23
  65. data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +41 -40
  66. data/lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb +30 -29
  67. data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +61 -59
  68. data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +98 -98
  69. data/lib/solargraph/parser/parser_gem/node_processors/or_node.rb +22 -0
  70. data/lib/solargraph/parser/parser_gem/node_processors/orasgn_node.rb +17 -17
  71. data/lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb +39 -38
  72. data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +53 -52
  73. data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +296 -291
  74. data/lib/solargraph/parser/parser_gem/node_processors/when_node.rb +23 -0
  75. data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +33 -29
  76. data/lib/solargraph/parser/parser_gem/node_processors.rb +74 -70
  77. data/lib/solargraph/parser/region.rb +75 -69
  78. data/lib/solargraph/parser/snippet.rb +17 -17
  79. data/lib/solargraph/pin/base.rb +761 -729
  80. data/lib/solargraph/pin/base_variable.rb +418 -126
  81. data/lib/solargraph/pin/block.rb +126 -104
  82. data/lib/solargraph/pin/breakable.rb +13 -9
  83. data/lib/solargraph/pin/callable.rb +278 -231
  84. data/lib/solargraph/pin/closure.rb +68 -72
  85. data/lib/solargraph/pin/common.rb +94 -79
  86. data/lib/solargraph/pin/compound_statement.rb +55 -0
  87. data/lib/solargraph/pin/conversions.rb +124 -123
  88. data/lib/solargraph/pin/delegated_method.rb +131 -120
  89. data/lib/solargraph/pin/documenting.rb +115 -114
  90. data/lib/solargraph/pin/instance_variable.rb +38 -34
  91. data/lib/solargraph/pin/keyword.rb +16 -20
  92. data/lib/solargraph/pin/local_variable.rb +31 -75
  93. data/lib/solargraph/pin/method.rb +720 -672
  94. data/lib/solargraph/pin/method_alias.rb +42 -34
  95. data/lib/solargraph/pin/namespace.rb +121 -115
  96. data/lib/solargraph/pin/parameter.rb +338 -275
  97. data/lib/solargraph/pin/proxy_type.rb +40 -39
  98. data/lib/solargraph/pin/reference/override.rb +47 -47
  99. data/lib/solargraph/pin/reference/superclass.rb +17 -15
  100. data/lib/solargraph/pin/reference.rb +41 -39
  101. data/lib/solargraph/pin/search.rb +62 -61
  102. data/lib/solargraph/pin/signature.rb +69 -61
  103. data/lib/solargraph/pin/symbol.rb +53 -53
  104. data/lib/solargraph/pin/until.rb +18 -18
  105. data/lib/solargraph/pin/while.rb +18 -18
  106. data/lib/solargraph/pin.rb +46 -44
  107. data/lib/solargraph/pin_cache.rb +665 -245
  108. data/lib/solargraph/position.rb +118 -119
  109. data/lib/solargraph/range.rb +112 -112
  110. data/lib/solargraph/rbs_map/conversions.rb +846 -823
  111. data/lib/solargraph/rbs_map/core_map.rb +65 -58
  112. data/lib/solargraph/rbs_map/stdlib_map.rb +72 -43
  113. data/lib/solargraph/rbs_map.rb +217 -163
  114. data/lib/solargraph/shell.rb +397 -352
  115. data/lib/solargraph/source/chain/call.rb +372 -337
  116. data/lib/solargraph/source/chain/constant.rb +28 -26
  117. data/lib/solargraph/source/chain/hash.rb +35 -34
  118. data/lib/solargraph/source/chain/if.rb +29 -28
  119. data/lib/solargraph/source/chain/instance_variable.rb +34 -13
  120. data/lib/solargraph/source/chain/literal.rb +53 -48
  121. data/lib/solargraph/source/chain/or.rb +31 -23
  122. data/lib/solargraph/source/chain.rb +294 -291
  123. data/lib/solargraph/source/change.rb +89 -82
  124. data/lib/solargraph/source/cursor.rb +172 -166
  125. data/lib/solargraph/source/encoding_fixes.rb +23 -23
  126. data/lib/solargraph/source/source_chainer.rb +204 -194
  127. data/lib/solargraph/source/updater.rb +59 -55
  128. data/lib/solargraph/source.rb +524 -498
  129. data/lib/solargraph/source_map/clip.rb +237 -226
  130. data/lib/solargraph/source_map/data.rb +37 -34
  131. data/lib/solargraph/source_map/mapper.rb +282 -259
  132. data/lib/solargraph/source_map.rb +220 -212
  133. data/lib/solargraph/type_checker/problem.rb +34 -32
  134. data/lib/solargraph/type_checker/rules.rb +157 -84
  135. data/lib/solargraph/type_checker.rb +895 -814
  136. data/lib/solargraph/version.rb +5 -5
  137. data/lib/solargraph/workspace/config.rb +257 -255
  138. data/lib/solargraph/workspace/gemspecs.rb +367 -0
  139. data/lib/solargraph/workspace/require_paths.rb +98 -97
  140. data/lib/solargraph/workspace.rb +362 -220
  141. data/lib/solargraph/yard_map/helpers.rb +45 -44
  142. data/lib/solargraph/yard_map/mapper/to_method.rb +134 -130
  143. data/lib/solargraph/yard_map/mapper/to_namespace.rb +32 -31
  144. data/lib/solargraph/yard_map/mapper.rb +84 -79
  145. data/lib/solargraph/yardoc.rb +97 -87
  146. data/lib/solargraph.rb +126 -105
  147. data/rbs/fills/rubygems/0/dependency.rbs +193 -0
  148. data/rbs/fills/tuple/tuple.rbs +28 -0
  149. data/rbs/shims/ast/0/node.rbs +5 -0
  150. data/rbs/shims/diff-lcs/1.5/diff-lcs.rbs +11 -0
  151. data/rbs_collection.yaml +1 -1
  152. data/solargraph.gemspec +2 -1
  153. metadata +23 -17
  154. data/lib/solargraph/type_checker/checks.rb +0 -124
  155. data/lib/solargraph/type_checker/param_def.rb +0 -37
  156. data/lib/solargraph/yard_map/to_method.rb +0 -89
  157. data/sig/shims/ast/0/node.rbs +0 -5
  158. /data/{sig → rbs}/shims/ast/2.4/.rbs_meta.yaml +0 -0
  159. /data/{sig → rbs}/shims/ast/2.4/ast.rbs +0 -0
  160. /data/{sig → rbs}/shims/parser/3.2.0.1/builders/default.rbs +0 -0
  161. /data/{sig → rbs}/shims/parser/3.2.0.1/manifest.yaml +0 -0
  162. /data/{sig → rbs}/shims/parser/3.2.0.1/parser.rbs +0 -0
  163. /data/{sig → rbs}/shims/parser/3.2.0.1/polyfill.rbs +0 -0
  164. /data/{sig → rbs}/shims/thor/1.2.0.1/.rbs_meta.yaml +0 -0
  165. /data/{sig → rbs}/shims/thor/1.2.0.1/manifest.yaml +0 -0
  166. /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<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<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 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
+ # @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