solargraph 0.47.2 → 0.53.3

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 (185) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +1 -0
  3. data/.github/workflows/plugins.yml +40 -0
  4. data/.github/workflows/rspec.yml +4 -8
  5. data/.github/workflows/typecheck.yml +34 -0
  6. data/.yardopts +2 -2
  7. data/CHANGELOG.md +137 -3
  8. data/LICENSE +1 -1
  9. data/README.md +19 -16
  10. data/SPONSORS.md +2 -9
  11. data/lib/solargraph/api_map/cache.rb +60 -20
  12. data/lib/solargraph/api_map/source_to_yard.rb +17 -10
  13. data/lib/solargraph/api_map/store.rb +60 -12
  14. data/lib/solargraph/api_map.rb +171 -99
  15. data/lib/solargraph/bench.rb +3 -2
  16. data/lib/solargraph/cache.rb +77 -0
  17. data/lib/solargraph/complex_type/type_methods.rb +61 -12
  18. data/lib/solargraph/complex_type/unique_type.rb +193 -16
  19. data/lib/solargraph/complex_type.rb +113 -10
  20. data/lib/solargraph/convention/rakefile.rb +17 -0
  21. data/lib/solargraph/convention.rb +2 -3
  22. data/lib/solargraph/converters/dd.rb +5 -0
  23. data/lib/solargraph/converters/dl.rb +3 -0
  24. data/lib/solargraph/converters/dt.rb +3 -0
  25. data/lib/solargraph/diagnostics/rubocop.rb +23 -8
  26. data/lib/solargraph/diagnostics/rubocop_helpers.rb +4 -1
  27. data/lib/solargraph/diagnostics/type_check.rb +1 -0
  28. data/lib/solargraph/diagnostics.rb +2 -2
  29. data/lib/solargraph/doc_map.rb +171 -0
  30. data/lib/solargraph/gem_pins.rb +64 -0
  31. data/lib/solargraph/language_server/host/cataloger.rb +2 -1
  32. data/lib/solargraph/language_server/host/diagnoser.rb +2 -2
  33. data/lib/solargraph/language_server/host/dispatch.rb +15 -5
  34. data/lib/solargraph/language_server/host/message_worker.rb +4 -0
  35. data/lib/solargraph/language_server/host/sources.rb +7 -4
  36. data/lib/solargraph/language_server/host.rb +50 -26
  37. data/lib/solargraph/language_server/message/completion_item/resolve.rb +3 -1
  38. data/lib/solargraph/language_server/message/extended/check_gem_version.rb +13 -1
  39. data/lib/solargraph/language_server/message/extended/download_core.rb +1 -5
  40. data/lib/solargraph/language_server/message/initialize.rb +13 -0
  41. data/lib/solargraph/language_server/message/initialized.rb +1 -0
  42. data/lib/solargraph/language_server/message/text_document/document_symbol.rb +4 -1
  43. data/lib/solargraph/language_server/message/text_document/formatting.rb +4 -4
  44. data/lib/solargraph/language_server/message/text_document/hover.rb +2 -0
  45. data/lib/solargraph/language_server/message/text_document/signature_help.rb +1 -6
  46. data/lib/solargraph/language_server/message/text_document/type_definition.rb +24 -0
  47. data/lib/solargraph/language_server/message/text_document.rb +1 -1
  48. data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +5 -0
  49. data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +10 -3
  50. data/lib/solargraph/language_server/message.rb +1 -0
  51. data/lib/solargraph/language_server/transport/adapter.rb +16 -1
  52. data/lib/solargraph/language_server/transport/data_reader.rb +2 -0
  53. data/lib/solargraph/library.rb +124 -37
  54. data/lib/solargraph/location.rb +1 -0
  55. data/lib/solargraph/page.rb +6 -0
  56. data/lib/solargraph/parser/comment_ripper.rb +4 -0
  57. data/lib/solargraph/parser/node_methods.rb +47 -7
  58. data/lib/solargraph/parser/node_processor/base.rb +9 -0
  59. data/lib/solargraph/parser/{legacy → parser_gem}/class_methods.rb +31 -5
  60. data/lib/solargraph/parser/{legacy → parser_gem}/flawed_builder.rb +3 -1
  61. data/lib/solargraph/parser/{legacy → parser_gem}/node_chainer.rb +57 -41
  62. data/lib/solargraph/parser/parser_gem/node_methods.rb +499 -0
  63. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/alias_node.rb +1 -1
  64. data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +53 -0
  65. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/begin_node.rb +1 -1
  66. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/block_node.rb +3 -2
  67. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/casgn_node.rb +14 -4
  68. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/cvasgn_node.rb +1 -1
  69. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/def_node.rb +7 -20
  70. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/defs_node.rb +2 -2
  71. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/gvasgn_node.rb +1 -1
  72. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/ivasgn_node.rb +2 -2
  73. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/lvasgn_node.rb +2 -2
  74. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/namespace_node.rb +2 -2
  75. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/orasgn_node.rb +1 -1
  76. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/resbody_node.rb +3 -3
  77. data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +42 -0
  78. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/send_node.rb +2 -2
  79. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/sym_node.rb +1 -1
  80. data/lib/solargraph/parser/parser_gem/node_processors.rb +54 -0
  81. data/lib/solargraph/parser/parser_gem.rb +12 -0
  82. data/lib/solargraph/parser/region.rb +1 -1
  83. data/lib/solargraph/parser/snippet.rb +2 -0
  84. data/lib/solargraph/parser.rb +9 -10
  85. data/lib/solargraph/pin/base.rb +69 -11
  86. data/lib/solargraph/pin/base_variable.rb +8 -4
  87. data/lib/solargraph/pin/block.rb +21 -28
  88. data/lib/solargraph/pin/closure.rb +17 -2
  89. data/lib/solargraph/pin/common.rb +7 -3
  90. data/lib/solargraph/pin/conversions.rb +34 -8
  91. data/lib/solargraph/pin/delegated_method.rb +97 -0
  92. data/lib/solargraph/pin/documenting.rb +25 -34
  93. data/lib/solargraph/pin/instance_variable.rb +4 -0
  94. data/lib/solargraph/pin/local_variable.rb +13 -1
  95. data/lib/solargraph/pin/method.rb +270 -16
  96. data/lib/solargraph/pin/namespace.rb +17 -1
  97. data/lib/solargraph/pin/parameter.rb +52 -17
  98. data/lib/solargraph/pin/reference/override.rb +2 -2
  99. data/lib/solargraph/pin/reference.rb +8 -0
  100. data/lib/solargraph/pin/search.rb +4 -4
  101. data/lib/solargraph/pin/signature.rb +143 -0
  102. data/lib/solargraph/pin.rb +2 -1
  103. data/lib/solargraph/range.rb +4 -6
  104. data/lib/solargraph/rbs_map/conversions.rb +601 -0
  105. data/lib/solargraph/rbs_map/core_fills.rb +47 -0
  106. data/lib/solargraph/rbs_map/core_map.rb +28 -0
  107. data/lib/solargraph/rbs_map/stdlib_map.rb +33 -0
  108. data/lib/solargraph/rbs_map.rb +84 -0
  109. data/lib/solargraph/shell.rb +69 -48
  110. data/lib/solargraph/source/chain/array.rb +32 -0
  111. data/lib/solargraph/source/chain/block_symbol.rb +13 -0
  112. data/lib/solargraph/source/chain/call.rb +125 -61
  113. data/lib/solargraph/source/chain/constant.rb +15 -1
  114. data/lib/solargraph/source/chain/if.rb +23 -0
  115. data/lib/solargraph/source/chain/link.rb +8 -2
  116. data/lib/solargraph/source/chain/or.rb +1 -1
  117. data/lib/solargraph/source/chain/z_super.rb +3 -3
  118. data/lib/solargraph/source/chain.rb +44 -14
  119. data/lib/solargraph/source/change.rb +3 -0
  120. data/lib/solargraph/source/cursor.rb +2 -0
  121. data/lib/solargraph/source/source_chainer.rb +8 -5
  122. data/lib/solargraph/source.rb +18 -19
  123. data/lib/solargraph/source_map/clip.rb +30 -23
  124. data/lib/solargraph/source_map/mapper.rb +20 -5
  125. data/lib/solargraph/source_map.rb +28 -13
  126. data/lib/solargraph/type_checker/checks.rb +10 -2
  127. data/lib/solargraph/type_checker.rb +201 -98
  128. data/lib/solargraph/version.rb +1 -1
  129. data/lib/solargraph/views/environment.erb +2 -2
  130. data/lib/solargraph/workspace/config.rb +14 -11
  131. data/lib/solargraph/workspace.rb +28 -17
  132. data/lib/solargraph/yard_map/cache.rb +6 -0
  133. data/lib/solargraph/yard_map/helpers.rb +1 -1
  134. data/lib/solargraph/yard_map/mapper/to_method.rb +18 -5
  135. data/lib/solargraph/yard_map/mapper.rb +1 -1
  136. data/lib/solargraph/yard_map/to_method.rb +11 -4
  137. data/lib/solargraph/yard_map.rb +1 -443
  138. data/lib/solargraph/yard_tags.rb +20 -0
  139. data/lib/solargraph/yardoc.rb +52 -0
  140. data/lib/solargraph.rb +8 -6
  141. data/solargraph.gemspec +19 -8
  142. metadata +162 -98
  143. data/.travis.yml +0 -19
  144. data/lib/solargraph/api_map/bundler_methods.rb +0 -22
  145. data/lib/solargraph/compat.rb +0 -37
  146. data/lib/solargraph/convention/rspec.rb +0 -30
  147. data/lib/solargraph/documentor.rb +0 -76
  148. data/lib/solargraph/parser/legacy/node_methods.rb +0 -325
  149. data/lib/solargraph/parser/legacy/node_processors/alias_node.rb +0 -23
  150. data/lib/solargraph/parser/legacy/node_processors/args_node.rb +0 -35
  151. data/lib/solargraph/parser/legacy/node_processors/begin_node.rb +0 -15
  152. data/lib/solargraph/parser/legacy/node_processors/def_node.rb +0 -63
  153. data/lib/solargraph/parser/legacy/node_processors/sclass_node.rb +0 -21
  154. data/lib/solargraph/parser/legacy/node_processors.rb +0 -54
  155. data/lib/solargraph/parser/legacy.rb +0 -12
  156. data/lib/solargraph/parser/rubyvm/class_methods.rb +0 -144
  157. data/lib/solargraph/parser/rubyvm/node_chainer.rb +0 -160
  158. data/lib/solargraph/parser/rubyvm/node_methods.rb +0 -315
  159. data/lib/solargraph/parser/rubyvm/node_processors/args_node.rb +0 -85
  160. data/lib/solargraph/parser/rubyvm/node_processors/block_node.rb +0 -42
  161. data/lib/solargraph/parser/rubyvm/node_processors/casgn_node.rb +0 -22
  162. data/lib/solargraph/parser/rubyvm/node_processors/cvasgn_node.rb +0 -23
  163. data/lib/solargraph/parser/rubyvm/node_processors/defs_node.rb +0 -57
  164. data/lib/solargraph/parser/rubyvm/node_processors/gvasgn_node.rb +0 -23
  165. data/lib/solargraph/parser/rubyvm/node_processors/ivasgn_node.rb +0 -38
  166. data/lib/solargraph/parser/rubyvm/node_processors/kw_arg_node.rb +0 -39
  167. data/lib/solargraph/parser/rubyvm/node_processors/lit_node.rb +0 -20
  168. data/lib/solargraph/parser/rubyvm/node_processors/lvasgn_node.rb +0 -27
  169. data/lib/solargraph/parser/rubyvm/node_processors/namespace_node.rb +0 -39
  170. data/lib/solargraph/parser/rubyvm/node_processors/opt_arg_node.rb +0 -26
  171. data/lib/solargraph/parser/rubyvm/node_processors/orasgn_node.rb +0 -15
  172. data/lib/solargraph/parser/rubyvm/node_processors/resbody_node.rb +0 -45
  173. data/lib/solargraph/parser/rubyvm/node_processors/sclass_node.rb +0 -21
  174. data/lib/solargraph/parser/rubyvm/node_processors/scope_node.rb +0 -15
  175. data/lib/solargraph/parser/rubyvm/node_processors/send_node.rb +0 -277
  176. data/lib/solargraph/parser/rubyvm/node_processors/sym_node.rb +0 -18
  177. data/lib/solargraph/parser/rubyvm/node_processors.rb +0 -63
  178. data/lib/solargraph/parser/rubyvm.rb +0 -40
  179. data/lib/solargraph/yard_map/core_docs.rb +0 -170
  180. data/lib/solargraph/yard_map/core_fills.rb +0 -208
  181. data/lib/solargraph/yard_map/core_gen.rb +0 -76
  182. data/lib/solargraph/yard_map/rdoc_to_yard.rb +0 -140
  183. data/lib/solargraph/yard_map/stdlib_fills.rb +0 -43
  184. data/lib/yard-solargraph.rb +0 -33
  185. data/yardoc/2.2.2.tar.gz +0 -0
@@ -0,0 +1,143 @@
1
+ module Solargraph
2
+ module Pin
3
+ class Signature < Base
4
+ # @return [::Array<Parameter>]
5
+ attr_reader :parameters
6
+
7
+ # @return [ComplexType]
8
+ attr_reader :return_type
9
+
10
+ # @return [self]
11
+ attr_reader :block
12
+
13
+ # @param generics [Array<String>]
14
+ # @param parameters [Array<Parameter>]
15
+ # @param return_type [ComplexType]
16
+ # @param block [Signature, nil]
17
+ def initialize generics, parameters, return_type, block = nil
18
+ @generics = generics
19
+ @parameters = parameters
20
+ @return_type = return_type
21
+ @block = block
22
+ end
23
+
24
+ def generics
25
+ @generics ||= [].freeze
26
+ end
27
+
28
+ # @return [String]
29
+ def to_rbs
30
+ rbs_generics + '(' + parameters.map { |param| param.to_rbs }.join(', ') + ') ' + (block.nil? ? '' : '{ ' + block.to_rbs + ' } ') + '-> ' + return_type.to_rbs
31
+ end
32
+
33
+ # @return [String]
34
+ def rbs_generics
35
+ if generics.empty?
36
+ return ''
37
+ else
38
+ return '[' + generics.map { |gen| gen.to_s }.join(', ') + '] '
39
+ end
40
+ end
41
+
42
+ # @return [Array<String>]
43
+ # @yieldparam [ComplexType]
44
+ # @yieldreturn [ComplexType]
45
+ # @return [self]
46
+ def transform_types(&transform)
47
+ # @todo 'super' alone should work here I think, but doesn't typecheck at level typed
48
+ signature = super(&transform)
49
+ signature.parameters = signature.parameters.map do |param|
50
+ param.transform_types(&transform)
51
+ end
52
+ signature.block = block.transform_types(&transform) if signature.block?
53
+ signature
54
+ end
55
+
56
+ # @param generics_to_resolve [Enumerable<String>]
57
+ # @param arg_types [Array<ComplexType>, nil]
58
+ # @param return_type_context [ComplexType, nil]
59
+ # @param yield_arg_types [Array<ComplexType>, nil]
60
+ # @param yield_return_type_context [ComplexType, nil]
61
+ # @param context [ComplexType, nil]
62
+ # @param resolved_generic_values [Hash{String => ComplexType}]
63
+ # @return [self]
64
+ def resolve_generics_from_context(generics_to_resolve,
65
+ arg_types = nil,
66
+ return_type_context = nil,
67
+ yield_arg_types = nil,
68
+ yield_return_type_context = nil,
69
+ resolved_generic_values: {})
70
+ signature = super(generics_to_resolve, return_type_context, resolved_generic_values: resolved_generic_values)
71
+ signature.parameters = signature.parameters.each_with_index.map do |param, i|
72
+ if arg_types.nil?
73
+ param.dup
74
+ else
75
+ param.resolve_generics_from_context(generics_to_resolve,
76
+ arg_types[i],
77
+ resolved_generic_values: resolved_generic_values)
78
+ end
79
+ end
80
+ signature.block = block.resolve_generics_from_context(generics_to_resolve,
81
+ yield_arg_types,
82
+ yield_return_type_context,
83
+ resolved_generic_values: resolved_generic_values) if signature.block?
84
+ signature
85
+ end
86
+
87
+ # @param generics_to_resolve [Enumerable<String>]
88
+ # @param arg_types [Array<ComplexType>, nil]
89
+ # @param return_type_context [ComplexType, nil]
90
+ # @param yield_arg_types [Array<ComplexType>, nil]
91
+ # @param yield_return_type_context [ComplexType, nil]
92
+ # @param context [ComplexType, nil]
93
+ # @param resolved_generic_values [Hash{String => ComplexType}]
94
+ # @return [self]
95
+ def resolve_generics_from_context_until_complete(generics_to_resolve,
96
+ arg_types = nil,
97
+ return_type_context = nil,
98
+ yield_arg_types = nil,
99
+ yield_return_type_context = nil,
100
+ resolved_generic_values: {})
101
+ # See
102
+ # https://github.com/soutaro/steep/tree/master/lib/steep/type_inference
103
+ # and
104
+ # https://github.com/sorbet/sorbet/blob/master/infer/inference.cc
105
+ # for other implementations
106
+
107
+ return self if generics_to_resolve.empty?
108
+
109
+ last_resolved_generic_values = resolved_generic_values.dup
110
+ new_pin = resolve_generics_from_context(generics_to_resolve,
111
+ arg_types,
112
+ return_type_context,
113
+ yield_arg_types,
114
+ yield_return_type_context,
115
+ resolved_generic_values: resolved_generic_values)
116
+ if last_resolved_generic_values == resolved_generic_values
117
+ # erase anything unresolved
118
+ return new_pin.erase_generics(self.generics)
119
+ end
120
+ new_pin.resolve_generics_from_context_until_complete(generics_to_resolve,
121
+ arg_types,
122
+ return_type_context,
123
+ yield_arg_types,
124
+ yield_return_type_context,
125
+ resolved_generic_values: resolved_generic_values)
126
+ end
127
+
128
+ def identity
129
+ @identity ||= "signature#{object_id}"
130
+ end
131
+
132
+ def block?
133
+ !!@block
134
+ end
135
+
136
+ protected
137
+
138
+ attr_writer :block
139
+
140
+ attr_writer :parameters
141
+ end
142
+ end
143
+ end
@@ -10,7 +10,9 @@ module Solargraph
10
10
  autoload :Conversions, 'solargraph/pin/conversions'
11
11
  autoload :Base, 'solargraph/pin/base'
12
12
  autoload :Method, 'solargraph/pin/method'
13
+ autoload :Signature, 'solargraph/pin/signature'
13
14
  autoload :MethodAlias, 'solargraph/pin/method_alias'
15
+ autoload :DelegatedMethod, 'solargraph/pin/delegated_method'
14
16
  autoload :BaseVariable, 'solargraph/pin/base_variable'
15
17
  autoload :InstanceVariable, 'solargraph/pin/instance_variable'
16
18
  autoload :ClassVariable, 'solargraph/pin/class_variable'
@@ -25,7 +27,6 @@ module Solargraph
25
27
  autoload :Reference, 'solargraph/pin/reference'
26
28
  autoload :Documenting, 'solargraph/pin/documenting'
27
29
  autoload :Block, 'solargraph/pin/block'
28
- autoload :Localized, 'solargraph/pin/localized'
29
30
  autoload :ProxyType, 'solargraph/pin/proxy_type'
30
31
  autoload :DuckMethod, 'solargraph/pin/duck_method'
31
32
  autoload :Singleton, 'solargraph/pin/singleton'
@@ -62,13 +62,11 @@ module Solargraph
62
62
 
63
63
  # Get a range from a node.
64
64
  #
65
- # @param node [RubyVM::AbstractSyntaxTree::Node, Parser::AST::Node]
66
- # @return [Range]
65
+ # @param node [Parser::AST::Node]
66
+ # @return [Range, nil]
67
67
  def self.from_node node
68
- if defined?(RubyVM::AbstractSyntaxTree::Node)
69
- if node.is_a?(RubyVM::AbstractSyntaxTree::Node)
70
- Solargraph::Range.from_to(node.first_lineno - 1, node.first_column, node.last_lineno - 1, node.last_column)
71
- end
68
+ if Parser.rubyvm? && node.is_a?(RubyVM::AbstractSyntaxTree::Node)
69
+ Solargraph::Range.from_to(node.first_lineno - 1, node.first_column, node.last_lineno - 1, node.last_column)
72
70
  elsif node&.loc && node.loc.expression
73
71
  from_expr(node.loc.expression)
74
72
  end