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,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Parser
5
+ module ParserGem
6
+ module NodeProcessors
7
+ class ArgsNode < Parser::NodeProcessor::Base
8
+ def process
9
+ if node.type == :forward_args
10
+ forward
11
+ else
12
+ node.children.each do |u|
13
+ loc = get_node_location(u)
14
+ locals.push Solargraph::Pin::Parameter.new(
15
+ location: loc,
16
+ closure: region.closure,
17
+ comments: comments_for(node),
18
+ name: u.children[0].to_s,
19
+ assignment: u.children[1],
20
+ asgn_code: u.children[1] ? region.code_for(u.children[1]) : nil,
21
+ presence: region.closure.location.range,
22
+ decl: get_decl(u)
23
+ )
24
+ region.closure.parameters.push locals.last
25
+ end
26
+ end
27
+ process_children
28
+ end
29
+
30
+ private
31
+
32
+ # @return [void]
33
+ def forward
34
+ loc = get_node_location(node)
35
+ locals.push Solargraph::Pin::Parameter.new(
36
+ location: loc,
37
+ closure: region.closure,
38
+ presence: region.closure.location.range,
39
+ decl: get_decl(node)
40
+ )
41
+ region.closure.parameters.push locals.last
42
+ end
43
+
44
+ # @param node [AST::Node]
45
+ # @return [Symbol]
46
+ def get_decl node
47
+ node.type
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Solargraph
4
4
  module Parser
5
- module Rubyvm
5
+ module ParserGem
6
6
  module NodeProcessors
7
7
  class BeginNode < Parser::NodeProcessor::Base
8
8
  def process
@@ -2,10 +2,10 @@
2
2
 
3
3
  module Solargraph
4
4
  module Parser
5
- module Legacy
5
+ module ParserGem
6
6
  module NodeProcessors
7
7
  class BlockNode < Parser::NodeProcessor::Base
8
- include Legacy::NodeMethods
8
+ include ParserGem::NodeMethods
9
9
 
10
10
  def process
11
11
  location = get_node_location(node)
@@ -21,6 +21,7 @@ module Solargraph
21
21
  pins.push Solargraph::Pin::Block.new(
22
22
  location: location,
23
23
  closure: parent,
24
+ node: node,
24
25
  receiver: node.children[0],
25
26
  comments: comments_for(node),
26
27
  scope: region.scope || region.closure.context.scope
@@ -2,22 +2,32 @@
2
2
 
3
3
  module Solargraph
4
4
  module Parser
5
- module Legacy
5
+ module ParserGem
6
6
  module NodeProcessors
7
7
  class CasgnNode < Parser::NodeProcessor::Base
8
- include Legacy::NodeMethods
8
+ include ParserGem::NodeMethods
9
9
 
10
10
  def process
11
- here = get_node_start_position(node)
12
11
  pins.push Solargraph::Pin::Constant.new(
13
12
  location: get_node_location(node),
14
13
  closure: region.closure,
15
- name: node.children[1].to_s,
14
+ name: const_name,
16
15
  comments: comments_for(node),
17
16
  assignment: node.children[2]
18
17
  )
19
18
  process_children
20
19
  end
20
+
21
+ private
22
+
23
+ # @return [String]
24
+ def const_name
25
+ if node.children[0]
26
+ Parser::NodeMethods.unpack_name(node.children[0]) + "::#{node.children[1]}"
27
+ else
28
+ node.children[1].to_s
29
+ end
30
+ end
21
31
  end
22
32
  end
23
33
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Solargraph
4
4
  module Parser
5
- module Legacy
5
+ module ParserGem
6
6
  module NodeProcessors
7
7
  class CvasgnNode < Parser::NodeProcessor::Base
8
8
  def process
@@ -2,35 +2,22 @@
2
2
 
3
3
  module Solargraph
4
4
  module Parser
5
- module Rubyvm
5
+ module ParserGem
6
6
  module NodeProcessors
7
7
  class DefNode < Parser::NodeProcessor::Base
8
8
  def process
9
+ name = node.children[0].to_s
10
+ scope = region.scope || (region.closure.is_a?(Pin::Singleton) ? :class : :instance)
9
11
  methpin = Solargraph::Pin::Method.new(
10
12
  location: get_node_location(node),
11
13
  closure: region.closure,
12
- name: node.children[0].to_s,
14
+ name: name,
13
15
  comments: comments_for(node),
14
- scope: region.scope || (region.closure.is_a?(Pin::Singleton) ? :class : :instance),
15
- visibility: region.visibility,
16
+ scope: scope,
17
+ visibility: scope == :instance && name == 'initialize' ? :private : region.visibility,
16
18
  node: node
17
19
  )
18
- if methpin.name == 'initialize' and methpin.scope == :instance
19
- pins.push Solargraph::Pin::Method.new(
20
- location: methpin.location,
21
- closure: methpin.closure,
22
- name: 'new',
23
- comments: methpin.comments,
24
- scope: :class,
25
- parameters: methpin.parameters
26
- )
27
- # @todo Smelly instance variable access.
28
- pins.last.instance_variable_set(:@return_type, ComplexType::SELF)
29
- pins.push methpin
30
- # @todo Smelly instance variable access.
31
- methpin.instance_variable_set(:@visibility, :private)
32
- methpin.instance_variable_set(:@return_type, ComplexType::VOID)
33
- elsif region.visibility == :module_function
20
+ if region.visibility == :module_function
34
21
  pins.push Solargraph::Pin::Method.new(
35
22
  location: methpin.location,
36
23
  closure: methpin.closure,
@@ -2,10 +2,10 @@
2
2
 
3
3
  module Solargraph
4
4
  module Parser
5
- module Legacy
5
+ module ParserGem
6
6
  module NodeProcessors
7
7
  class DefsNode < DefNode
8
- include Legacy::NodeMethods
8
+ include ParserGem::NodeMethods
9
9
 
10
10
  def process
11
11
  s_visi = region.visibility
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Solargraph
4
4
  module Parser
5
- module Legacy
5
+ module ParserGem
6
6
  module NodeProcessors
7
7
  class GvasgnNode < Parser::NodeProcessor::Base
8
8
  def process
@@ -2,10 +2,10 @@
2
2
 
3
3
  module Solargraph
4
4
  module Parser
5
- module Legacy
5
+ module ParserGem
6
6
  module NodeProcessors
7
7
  class IvasgnNode < Parser::NodeProcessor::Base
8
- include Legacy::NodeMethods
8
+ include ParserGem::NodeMethods
9
9
 
10
10
  def process
11
11
  loc = get_node_location(node)
@@ -2,10 +2,10 @@
2
2
 
3
3
  module Solargraph
4
4
  module Parser
5
- module Legacy
5
+ module ParserGem
6
6
  module NodeProcessors
7
7
  class LvasgnNode < Parser::NodeProcessor::Base
8
- include Legacy::NodeMethods
8
+ include ParserGem::NodeMethods
9
9
 
10
10
  def process
11
11
  here = get_node_start_position(node)
@@ -2,10 +2,10 @@
2
2
 
3
3
  module Solargraph
4
4
  module Parser
5
- module Legacy
5
+ module ParserGem
6
6
  module NodeProcessors
7
7
  class NamespaceNode < Parser::NodeProcessor::Base
8
- include Legacy::NodeMethods
8
+ include ParserGem::NodeMethods
9
9
 
10
10
  def process
11
11
  sc = nil
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Solargraph
4
4
  module Parser
5
- module Legacy
5
+ module ParserGem
6
6
  module NodeProcessors
7
7
  class OrasgnNode < Parser::NodeProcessor::Base
8
8
  def process
@@ -2,13 +2,13 @@
2
2
 
3
3
  module Solargraph
4
4
  module Parser
5
- module Legacy
5
+ module ParserGem
6
6
  module NodeProcessors
7
7
  class ResbodyNode < Parser::NodeProcessor::Base
8
- include Legacy::NodeMethods
8
+ include ParserGem::NodeMethods
9
9
 
10
10
  def process
11
- if node.children[1]
11
+ if node.children[1] # Exception local variable name
12
12
  here = get_node_start_position(node.children[1])
13
13
  presence = Range.new(here, region.closure.location.range.ending)
14
14
  loc = get_node_location(node.children[1])
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Parser
5
+ module ParserGem
6
+ module NodeProcessors
7
+ class SclassNode < Parser::NodeProcessor::Base
8
+ def process
9
+ sclass = node.children[0]
10
+ if sclass.is_a?(AST::Node) && sclass.type == :self
11
+ closure = region.closure
12
+ elsif sclass.is_a?(AST::Node) && sclass.type == :casgn
13
+ names = [region.closure.namespace, region.closure.name]
14
+ if sclass.children[0].nil? && names.last != sclass.children[1].to_s
15
+ names << sclass.children[1].to_s
16
+ else
17
+ names.concat [NodeMethods.unpack_name(sclass.children[0]), sclass.children[1].to_s]
18
+ end
19
+ name = names.reject(&:empty?).join('::')
20
+ closure = Solargraph::Pin::Namespace.new(name: name, location: region.closure.location)
21
+ elsif sclass.is_a?(AST::Node) && sclass.type == :const
22
+ names = [region.closure.namespace, region.closure.name]
23
+ also = NodeMethods.unpack_name(sclass)
24
+ if also != region.closure.name
25
+ names << also
26
+ end
27
+ name = names.reject(&:empty?).join('::')
28
+ closure = Solargraph::Pin::Namespace.new(name: name, location: region.closure.location)
29
+ else
30
+ return
31
+ end
32
+ pins.push Solargraph::Pin::Singleton.new(
33
+ location: get_node_location(node),
34
+ closure: closure
35
+ )
36
+ process_children region.update(visibility: :public, scope: :class, closure: pins.last)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -2,10 +2,10 @@
2
2
 
3
3
  module Solargraph
4
4
  module Parser
5
- module Legacy
5
+ module ParserGem
6
6
  module NodeProcessors
7
7
  class SendNode < Parser::NodeProcessor::Base
8
- include Legacy::NodeMethods
8
+ include ParserGem::NodeMethods
9
9
 
10
10
  def process
11
11
  if node.children[0].nil?
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Solargraph
4
4
  module Parser
5
- module Legacy
5
+ module ParserGem
6
6
  module NodeProcessors
7
7
  class SymNode < Parser::NodeProcessor::Base
8
8
  def process
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'solargraph/parser/node_processor'
4
+
5
+ module Solargraph
6
+ module Parser
7
+ module ParserGem
8
+ module NodeProcessors
9
+ autoload :BeginNode, 'solargraph/parser/parser_gem/node_processors/begin_node'
10
+ autoload :DefNode, 'solargraph/parser/parser_gem/node_processors/def_node'
11
+ autoload :DefsNode, 'solargraph/parser/parser_gem/node_processors/defs_node'
12
+ autoload :SendNode, 'solargraph/parser/parser_gem/node_processors/send_node'
13
+ autoload :NamespaceNode, 'solargraph/parser/parser_gem/node_processors/namespace_node'
14
+ autoload :SclassNode, 'solargraph/parser/parser_gem/node_processors/sclass_node'
15
+ autoload :IvasgnNode, 'solargraph/parser/parser_gem/node_processors/ivasgn_node'
16
+ autoload :CvasgnNode, 'solargraph/parser/parser_gem/node_processors/cvasgn_node'
17
+ autoload :LvasgnNode, 'solargraph/parser/parser_gem/node_processors/lvasgn_node'
18
+ autoload :GvasgnNode, 'solargraph/parser/parser_gem/node_processors/gvasgn_node'
19
+ autoload :CasgnNode, 'solargraph/parser/parser_gem/node_processors/casgn_node'
20
+ autoload :AliasNode, 'solargraph/parser/parser_gem/node_processors/alias_node'
21
+ autoload :ArgsNode, 'solargraph/parser/parser_gem/node_processors/args_node'
22
+ autoload :BlockNode, 'solargraph/parser/parser_gem/node_processors/block_node'
23
+ autoload :OrasgnNode, 'solargraph/parser/parser_gem/node_processors/orasgn_node'
24
+ autoload :SymNode, 'solargraph/parser/parser_gem/node_processors/sym_node'
25
+ autoload :ResbodyNode, 'solargraph/parser/parser_gem/node_processors/resbody_node'
26
+ end
27
+ end
28
+
29
+ module NodeProcessor
30
+ register :source, ParserGem::NodeProcessors::BeginNode
31
+ register :begin, ParserGem::NodeProcessors::BeginNode
32
+ register :kwbegin, ParserGem::NodeProcessors::BeginNode
33
+ register :rescue, ParserGem::NodeProcessors::BeginNode
34
+ register :resbody, ParserGem::NodeProcessors::ResbodyNode
35
+ register :def, ParserGem::NodeProcessors::DefNode
36
+ register :defs, ParserGem::NodeProcessors::DefsNode
37
+ register :send, ParserGem::NodeProcessors::SendNode
38
+ register :class, ParserGem::NodeProcessors::NamespaceNode
39
+ register :module, ParserGem::NodeProcessors::NamespaceNode
40
+ register :sclass, ParserGem::NodeProcessors::SclassNode
41
+ register :ivasgn, ParserGem::NodeProcessors::IvasgnNode
42
+ register :cvasgn, ParserGem::NodeProcessors::CvasgnNode
43
+ register :lvasgn, ParserGem::NodeProcessors::LvasgnNode
44
+ register :gvasgn, ParserGem::NodeProcessors::GvasgnNode
45
+ register :casgn, ParserGem::NodeProcessors::CasgnNode
46
+ register :alias, ParserGem::NodeProcessors::AliasNode
47
+ register :args, ParserGem::NodeProcessors::ArgsNode
48
+ register :forward_args, ParserGem::NodeProcessors::ArgsNode
49
+ register :block, ParserGem::NodeProcessors::BlockNode
50
+ register :or_asgn, ParserGem::NodeProcessors::OrasgnNode
51
+ register :sym, ParserGem::NodeProcessors::SymNode
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,12 @@
1
+ module Solargraph
2
+ module Parser
3
+ module ParserGem
4
+ autoload :FlawedBuilder, 'solargraph/parser/parser_gem/flawed_builder'
5
+ autoload :ClassMethods, 'solargraph/parser/parser_gem/class_methods'
6
+ autoload :NodeMethods, 'solargraph/parser/parser_gem/node_methods'
7
+ autoload :NodeChainer, 'solargraph/parser/parser_gem/node_chainer'
8
+ end
9
+ end
10
+ end
11
+
12
+ require 'solargraph/parser/parser_gem/node_processors'
@@ -23,7 +23,7 @@ module Solargraph
23
23
 
24
24
  # @param source [Source]
25
25
  # @param namespace [String]
26
- # @param scope [Symbol]
26
+ # @param scope [Symbol, nil]
27
27
  # @param visibility [Symbol]
28
28
  def initialize source: Solargraph::Source.load_string(''), closure: nil,
29
29
  scope: nil, visibility: :public, lvars: []
@@ -1,7 +1,9 @@
1
1
  module Solargraph
2
2
  module Parser
3
3
  class Snippet
4
+ # @return [Range]
4
5
  attr_reader :range
6
+ # @return [String]
5
7
  attr_reader :text
6
8
 
7
9
  def initialize range, text
@@ -1,8 +1,7 @@
1
1
  module Solargraph
2
2
  module Parser
3
3
  autoload :CommentRipper, 'solargraph/parser/comment_ripper'
4
- autoload :Legacy, 'solargraph/parser/legacy'
5
- autoload :Rubyvm, 'solargraph/parser/rubyvm'
4
+ autoload :ParserGem, 'solargraph/parser/parser_gem'
6
5
  autoload :Region, 'solargraph/parser/region'
7
6
  autoload :NodeProcessor, 'solargraph/parser/node_processor'
8
7
  autoload :Snippet, 'solargraph/parser/snippet'
@@ -10,17 +9,17 @@ module Solargraph
10
9
  class SyntaxError < StandardError
11
10
  end
12
11
 
13
- # True if the parser can use RubyVM.
14
- #
15
12
  def self.rubyvm?
16
- !!defined?(RubyVM::AbstractSyntaxTree)
17
- # false
13
+ false
18
14
  end
19
15
 
20
- selected = rubyvm? ? Rubyvm : Legacy
21
- # include selected
22
- extend selected::ClassMethods
16
+ # @deprecated
17
+ Legacy = ParserGem
23
18
 
24
- NodeMethods = (rubyvm? ? Rubyvm::NodeMethods : Legacy::NodeMethods)
19
+ ClassMethods = ParserGem::ClassMethods
20
+
21
+ extend ParserGem::ClassMethods
22
+
23
+ NodeMethods = ParserGem::NodeMethods
25
24
  end
26
25
  end
@@ -21,9 +21,11 @@ module Solargraph
21
21
  # @return [String]
22
22
  attr_reader :path
23
23
 
24
- # @param location [Solargraph::Location]
25
- # @param kind [Integer]
26
- # @param closure [Solargraph::Pin::Closure]
24
+ # @return [::Symbol]
25
+ attr_accessor :source
26
+
27
+ # @param location [Solargraph::Location, nil]
28
+ # @param closure [Solargraph::Pin::Closure, nil]
27
29
  # @param name [String]
28
30
  # @param comments [String]
29
31
  def initialize location: nil, closure: nil, name: '', comments: ''
@@ -38,6 +40,43 @@ module Solargraph
38
40
  @comments ||= ''
39
41
  end
40
42
 
43
+ # @param generics_to_resolve [Enumerable<String>]
44
+ # @param return_type_context [ComplexType, nil]
45
+ # @param context [ComplexType]
46
+ # @param resolved_generic_values [Hash{String => ComplexType}]
47
+ # @return [self]
48
+ def resolve_generics_from_context(generics_to_resolve, return_type_context = nil, resolved_generic_values: {})
49
+ proxy return_type.resolve_generics_from_context(generics_to_resolve,
50
+ return_type_context,
51
+ resolved_generic_values: resolved_generic_values)
52
+ end
53
+
54
+ # @yieldparam [ComplexType]
55
+ # @yieldreturn [ComplexType]
56
+ # @return [self]
57
+ def transform_types(&transform)
58
+ proxy return_type.transform(&transform)
59
+ end
60
+
61
+ # Determine the concrete type for each of the generic type
62
+ # parameters used in this method based on the parameters passed
63
+ # into the its class and return a new method pin.
64
+ #
65
+ # @param definitions [Pin::Namespace] The module/class which uses generic types
66
+ # @param context_type [ComplexType] The receiver type
67
+ # @return [self]
68
+ def resolve_generics definitions, context_type
69
+ transformed = transform_types { |t| t.resolve_generics(definitions, context_type) if t }
70
+ transformed.erase_generics(definitions.generics)
71
+ end
72
+
73
+ # @param generics_to_erase [Enumerable<String>]
74
+ # @return [self]
75
+ def erase_generics(generics_to_erase)
76
+ return self if generics_to_erase.empty?
77
+ transform_types { |t| t.erase_generics(generics_to_erase) }
78
+ end
79
+
41
80
  # @return [String, nil]
42
81
  def filename
43
82
  return nil if location.nil?
@@ -55,7 +94,7 @@ module Solargraph
55
94
  end
56
95
 
57
96
  def to_s
58
- name.to_s
97
+ to_rbs
59
98
  end
60
99
 
61
100
  # @return [Boolean]
@@ -100,13 +139,13 @@ module Solargraph
100
139
  @docstring ||= Solargraph::Source.parse_docstring('').to_docstring
101
140
  end
102
141
 
103
- # @return [Array<YARD::Tags::Directive>]
142
+ # @return [::Array<YARD::Tags::Directive>]
104
143
  def directives
105
144
  parse_comments unless defined?(@directives)
106
145
  @directives
107
146
  end
108
147
 
109
- # @return [Array<YARD::Tags::MacroDirective>]
148
+ # @return [::Array<YARD::Tags::MacroDirective>]
110
149
  def macros
111
150
  @macros ||= collect_macros
112
151
  end
@@ -213,12 +252,31 @@ module Solargraph
213
252
  result
214
253
  end
215
254
 
255
+ # @return [String]
216
256
  def identity
217
- @identity ||= "#{closure.context.namespace}|#{name}"
257
+ @identity ||= "#{closure.path}|#{name}"
258
+ end
259
+
260
+ # @return [String, nil]
261
+ def to_rbs
262
+ return_type.to_rbs
263
+ end
264
+
265
+ # @return [String, nil]
266
+ def desc
267
+ if path
268
+ if to_rbs
269
+ path + ' ' + to_rbs
270
+ else
271
+ path
272
+ end
273
+ else
274
+ to_rbs
275
+ end
218
276
  end
219
277
 
220
278
  def inspect
221
- "#<#{self.class} `#{self.path}` at #{self.location.inspect}>"
279
+ "#<#{self.class} `#{self.desc}` at #{self.location.inspect}>"
222
280
  end
223
281
 
224
282
  protected
@@ -263,8 +321,8 @@ module Solargraph
263
321
  true
264
322
  end
265
323
 
266
- # @param dir1 [Array<YARD::Tags::Directive>]
267
- # @param dir2 [Array<YARD::Tags::Directive>]
324
+ # @param dir1 [::Array<YARD::Tags::Directive>]
325
+ # @param dir2 [::Array<YARD::Tags::Directive>]
268
326
  # @return [Boolean]
269
327
  def compare_directives dir1, dir2
270
328
  return false if dir1.length != dir2.length
@@ -285,7 +343,7 @@ module Solargraph
285
343
  tag1.types == tag2.types
286
344
  end
287
345
 
288
- # @return [Array<YARD::Tags::Handlers::Directive>]
346
+ # @return [::Array<YARD::Tags::Handlers::Directive>]
289
347
  def collect_macros
290
348
  return [] unless maybe_directives?
291
349
  parse = Solargraph::Source.parse_docstring(comments)
@@ -39,7 +39,7 @@ module Solargraph
39
39
  def probe api_map
40
40
  return ComplexType::UNDEFINED if @assignment.nil?
41
41
  types = []
42
- returns_from(@assignment).each do |node|
42
+ value_position_nodes_only(@assignment).each do |node|
43
43
  # Nil nodes may not have a location
44
44
  if node.nil? || node.type == :NIL || node.type == :nil
45
45
  types.push ComplexType::NIL
@@ -50,13 +50,13 @@ module Solargraph
50
50
  clip = api_map.clip_at(location.filename, pos)
51
51
  # Use the return node for inference. The clip might infer from the
52
52
  # first node in a method call instead of the entire call.
53
- chain = Parser.chain(node, nil, clip.in_block?)
54
- result = chain.infer(api_map, closure, clip.locals)
53
+ chain = Parser.chain(node, nil, nil)
54
+ result = chain.infer(api_map, closure, clip.locals).self_to(closure.context.tag)
55
55
  types.push result unless result.undefined?
56
56
  end
57
57
  end
58
58
  return ComplexType::UNDEFINED if types.empty?
59
- ComplexType.try_parse(*types.map(&:tag))
59
+ ComplexType.try_parse(*types.map(&:to_s))
60
60
  end
61
61
 
62
62
  def == other
@@ -71,6 +71,10 @@ module Solargraph
71
71
  true
72
72
  end
73
73
 
74
+ def desc
75
+ "#{to_rbs} = #{assignment&.type.inspect}"
76
+ end
77
+
74
78
  private
75
79
 
76
80
  # @return [ComplexType]