solargraph 0.52.0 → 0.53.4

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 (157) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/plugins.yml +40 -0
  3. data/.github/workflows/rspec.yml +1 -3
  4. data/.github/workflows/typecheck.yml +34 -0
  5. data/CHANGELOG.md +53 -0
  6. data/README.md +13 -16
  7. data/SPONSORS.md +1 -7
  8. data/lib/solargraph/api_map/cache.rb +59 -21
  9. data/lib/solargraph/api_map/source_to_yard.rb +17 -10
  10. data/lib/solargraph/api_map/store.rb +45 -9
  11. data/lib/solargraph/api_map.rb +178 -113
  12. data/lib/solargraph/bench.rb +3 -2
  13. data/lib/solargraph/cache.rb +29 -5
  14. data/lib/solargraph/complex_type/type_methods.rb +53 -8
  15. data/lib/solargraph/complex_type/unique_type.rb +171 -58
  16. data/lib/solargraph/complex_type.rb +62 -9
  17. data/lib/solargraph/convention.rb +0 -1
  18. data/lib/solargraph/converters/dd.rb +5 -0
  19. data/lib/solargraph/converters/dl.rb +3 -0
  20. data/lib/solargraph/converters/dt.rb +3 -0
  21. data/lib/solargraph/diagnostics/rubocop.rb +8 -7
  22. data/lib/solargraph/diagnostics/rubocop_helpers.rb +1 -0
  23. data/lib/solargraph/diagnostics/type_check.rb +1 -0
  24. data/lib/solargraph/diagnostics.rb +2 -2
  25. data/lib/solargraph/doc_map.rb +171 -0
  26. data/lib/solargraph/gem_pins.rb +64 -0
  27. data/lib/solargraph/language_server/host/cataloger.rb +1 -0
  28. data/lib/solargraph/language_server/host/diagnoser.rb +2 -2
  29. data/lib/solargraph/language_server/host/dispatch.rb +15 -5
  30. data/lib/solargraph/language_server/host/message_worker.rb +4 -0
  31. data/lib/solargraph/language_server/host/sources.rb +7 -4
  32. data/lib/solargraph/language_server/host.rb +35 -7
  33. data/lib/solargraph/language_server/message/completion_item/resolve.rb +3 -1
  34. data/lib/solargraph/language_server/message/extended/check_gem_version.rb +13 -1
  35. data/lib/solargraph/language_server/message/initialize.rb +5 -2
  36. data/lib/solargraph/language_server/message/text_document/hover.rb +2 -0
  37. data/lib/solargraph/language_server/message/text_document.rb +0 -1
  38. data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +5 -0
  39. data/lib/solargraph/language_server/transport/adapter.rb +16 -1
  40. data/lib/solargraph/language_server/transport/data_reader.rb +2 -0
  41. data/lib/solargraph/library.rb +71 -12
  42. data/lib/solargraph/location.rb +1 -0
  43. data/lib/solargraph/page.rb +6 -0
  44. data/lib/solargraph/parser/comment_ripper.rb +3 -0
  45. data/lib/solargraph/parser/node_methods.rb +47 -8
  46. data/lib/solargraph/parser/node_processor/base.rb +9 -0
  47. data/lib/solargraph/parser/{legacy → parser_gem}/class_methods.rb +29 -3
  48. data/lib/solargraph/parser/{legacy → parser_gem}/flawed_builder.rb +3 -1
  49. data/lib/solargraph/parser/{legacy → parser_gem}/node_chainer.rb +42 -34
  50. data/lib/solargraph/parser/{legacy → parser_gem}/node_methods.rb +201 -29
  51. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/alias_node.rb +1 -1
  52. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/args_node.rb +4 -1
  53. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/begin_node.rb +1 -1
  54. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/block_node.rb +3 -2
  55. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/casgn_node.rb +2 -2
  56. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/cvasgn_node.rb +1 -1
  57. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/def_node.rb +7 -20
  58. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/defs_node.rb +2 -2
  59. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/gvasgn_node.rb +1 -1
  60. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/ivasgn_node.rb +2 -2
  61. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/lvasgn_node.rb +2 -2
  62. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/namespace_node.rb +2 -2
  63. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/orasgn_node.rb +1 -1
  64. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/resbody_node.rb +3 -3
  65. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/sclass_node.rb +1 -1
  66. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/send_node.rb +2 -2
  67. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/sym_node.rb +1 -1
  68. data/lib/solargraph/parser/parser_gem/node_processors.rb +54 -0
  69. data/lib/solargraph/parser/parser_gem.rb +12 -0
  70. data/lib/solargraph/parser/snippet.rb +2 -0
  71. data/lib/solargraph/parser.rb +8 -11
  72. data/lib/solargraph/pin/base.rb +63 -8
  73. data/lib/solargraph/pin/base_variable.rb +7 -3
  74. data/lib/solargraph/pin/block.rb +26 -38
  75. data/lib/solargraph/pin/closure.rb +17 -2
  76. data/lib/solargraph/pin/common.rb +7 -3
  77. data/lib/solargraph/pin/conversions.rb +33 -3
  78. data/lib/solargraph/pin/documenting.rb +25 -34
  79. data/lib/solargraph/pin/instance_variable.rb +4 -0
  80. data/lib/solargraph/pin/local_variable.rb +13 -1
  81. data/lib/solargraph/pin/method.rb +110 -16
  82. data/lib/solargraph/pin/namespace.rb +16 -10
  83. data/lib/solargraph/pin/parameter.rb +41 -10
  84. data/lib/solargraph/pin/reference/override.rb +2 -2
  85. data/lib/solargraph/pin/reference.rb +8 -0
  86. data/lib/solargraph/pin/search.rb +3 -3
  87. data/lib/solargraph/pin/signature.rb +114 -2
  88. data/lib/solargraph/pin.rb +0 -1
  89. data/lib/solargraph/range.rb +2 -2
  90. data/lib/solargraph/rbs_map/conversions.rb +213 -61
  91. data/lib/solargraph/rbs_map/core_fills.rb +12 -28
  92. data/lib/solargraph/rbs_map/core_map.rb +2 -12
  93. data/lib/solargraph/rbs_map/stdlib_map.rb +2 -8
  94. data/lib/solargraph/rbs_map.rb +24 -12
  95. data/lib/solargraph/shell.rb +62 -59
  96. data/lib/solargraph/source/chain/array.rb +4 -1
  97. data/lib/solargraph/source/chain/block_symbol.rb +13 -0
  98. data/lib/solargraph/source/chain/call.rb +95 -26
  99. data/lib/solargraph/source/chain/constant.rb +15 -1
  100. data/lib/solargraph/source/chain/if.rb +23 -0
  101. data/lib/solargraph/source/chain/link.rb +7 -1
  102. data/lib/solargraph/source/chain/or.rb +1 -1
  103. data/lib/solargraph/source/chain/z_super.rb +2 -2
  104. data/lib/solargraph/source/chain.rb +20 -4
  105. data/lib/solargraph/source/change.rb +3 -0
  106. data/lib/solargraph/source/cursor.rb +2 -0
  107. data/lib/solargraph/source/source_chainer.rb +6 -5
  108. data/lib/solargraph/source.rb +15 -16
  109. data/lib/solargraph/source_map/clip.rb +14 -9
  110. data/lib/solargraph/source_map/mapper.rb +10 -0
  111. data/lib/solargraph/source_map.rb +12 -10
  112. data/lib/solargraph/type_checker/checks.rb +10 -2
  113. data/lib/solargraph/type_checker.rb +96 -21
  114. data/lib/solargraph/version.rb +1 -1
  115. data/lib/solargraph/workspace/config.rb +8 -6
  116. data/lib/solargraph/workspace.rb +15 -2
  117. data/lib/solargraph/yard_map/cache.rb +6 -0
  118. data/lib/solargraph/yard_map/helpers.rb +1 -1
  119. data/lib/solargraph/yard_map/mapper/to_method.rb +16 -3
  120. data/lib/solargraph/yard_map/to_method.rb +11 -4
  121. data/lib/solargraph/yard_map.rb +0 -292
  122. data/lib/solargraph/yardoc.rb +52 -0
  123. data/lib/solargraph.rb +4 -1
  124. data/solargraph.gemspec +2 -2
  125. metadata +35 -58
  126. data/lib/solargraph/api_map/bundler_methods.rb +0 -22
  127. data/lib/solargraph/documentor.rb +0 -76
  128. data/lib/solargraph/parser/legacy/node_processors/alias_node.rb +0 -23
  129. data/lib/solargraph/parser/legacy/node_processors/begin_node.rb +0 -15
  130. data/lib/solargraph/parser/legacy/node_processors/sym_node.rb +0 -18
  131. data/lib/solargraph/parser/legacy/node_processors.rb +0 -55
  132. data/lib/solargraph/parser/legacy.rb +0 -12
  133. data/lib/solargraph/parser/rubyvm/class_methods.rb +0 -151
  134. data/lib/solargraph/parser/rubyvm/node_chainer.rb +0 -163
  135. data/lib/solargraph/parser/rubyvm/node_methods.rb +0 -317
  136. data/lib/solargraph/parser/rubyvm/node_processors/args_node.rb +0 -85
  137. data/lib/solargraph/parser/rubyvm/node_processors/block_node.rb +0 -42
  138. data/lib/solargraph/parser/rubyvm/node_processors/casgn_node.rb +0 -33
  139. data/lib/solargraph/parser/rubyvm/node_processors/cvasgn_node.rb +0 -23
  140. data/lib/solargraph/parser/rubyvm/node_processors/def_node.rb +0 -75
  141. data/lib/solargraph/parser/rubyvm/node_processors/defs_node.rb +0 -68
  142. data/lib/solargraph/parser/rubyvm/node_processors/gvasgn_node.rb +0 -23
  143. data/lib/solargraph/parser/rubyvm/node_processors/ivasgn_node.rb +0 -38
  144. data/lib/solargraph/parser/rubyvm/node_processors/kw_arg_node.rb +0 -39
  145. data/lib/solargraph/parser/rubyvm/node_processors/lit_node.rb +0 -20
  146. data/lib/solargraph/parser/rubyvm/node_processors/lvasgn_node.rb +0 -27
  147. data/lib/solargraph/parser/rubyvm/node_processors/namespace_node.rb +0 -39
  148. data/lib/solargraph/parser/rubyvm/node_processors/opt_arg_node.rb +0 -26
  149. data/lib/solargraph/parser/rubyvm/node_processors/orasgn_node.rb +0 -15
  150. data/lib/solargraph/parser/rubyvm/node_processors/resbody_node.rb +0 -51
  151. data/lib/solargraph/parser/rubyvm/node_processors/sclass_node.rb +0 -32
  152. data/lib/solargraph/parser/rubyvm/node_processors/scope_node.rb +0 -15
  153. data/lib/solargraph/parser/rubyvm/node_processors/send_node.rb +0 -279
  154. data/lib/solargraph/parser/rubyvm/node_processors.rb +0 -64
  155. data/lib/solargraph/parser/rubyvm/node_wrapper.rb +0 -47
  156. data/lib/solargraph/parser/rubyvm.rb +0 -40
  157. data/lib/solargraph/rbs_map/core_signs.rb +0 -33
@@ -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])
@@ -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 SclassNode < 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 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 Rubyvm
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'
@@ -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,19 +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
13
  false
18
14
  end
19
15
 
20
- selected = rubyvm? ? Rubyvm : Legacy
21
- # include selected
22
- # @!parse
23
- # extend Solargraph::Parser::Legacy::ClassMethods
24
- extend selected::ClassMethods
16
+ # @deprecated
17
+ Legacy = ParserGem
25
18
 
26
- NodeMethods = (rubyvm? ? Rubyvm::NodeMethods : Legacy::NodeMethods)
19
+ ClassMethods = ParserGem::ClassMethods
20
+
21
+ extend ParserGem::ClassMethods
22
+
23
+ NodeMethods = ParserGem::NodeMethods
27
24
  end
28
25
  end
@@ -25,7 +25,6 @@ module Solargraph
25
25
  attr_accessor :source
26
26
 
27
27
  # @param location [Solargraph::Location, nil]
28
- # @param kind [Integer]
29
28
  # @param closure [Solargraph::Pin::Closure, nil]
30
29
  # @param name [String]
31
30
  # @param comments [String]
@@ -41,6 +40,43 @@ module Solargraph
41
40
  @comments ||= ''
42
41
  end
43
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
+
44
80
  # @return [String, nil]
45
81
  def filename
46
82
  return nil if location.nil?
@@ -58,7 +94,7 @@ module Solargraph
58
94
  end
59
95
 
60
96
  def to_s
61
- name.to_s
97
+ to_rbs
62
98
  end
63
99
 
64
100
  # @return [Boolean]
@@ -103,13 +139,13 @@ module Solargraph
103
139
  @docstring ||= Solargraph::Source.parse_docstring('').to_docstring
104
140
  end
105
141
 
106
- # @return [Array<YARD::Tags::Directive>]
142
+ # @return [::Array<YARD::Tags::Directive>]
107
143
  def directives
108
144
  parse_comments unless defined?(@directives)
109
145
  @directives
110
146
  end
111
147
 
112
- # @return [Array<YARD::Tags::MacroDirective>]
148
+ # @return [::Array<YARD::Tags::MacroDirective>]
113
149
  def macros
114
150
  @macros ||= collect_macros
115
151
  end
@@ -216,12 +252,31 @@ module Solargraph
216
252
  result
217
253
  end
218
254
 
255
+ # @return [String]
219
256
  def identity
220
257
  @identity ||= "#{closure.path}|#{name}"
221
258
  end
222
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
276
+ end
277
+
223
278
  def inspect
224
- "#<#{self.class} `#{self.path}` at #{self.location.inspect}>"
279
+ "#<#{self.class} `#{self.desc}` at #{self.location.inspect}>"
225
280
  end
226
281
 
227
282
  protected
@@ -266,8 +321,8 @@ module Solargraph
266
321
  true
267
322
  end
268
323
 
269
- # @param dir1 [Array<YARD::Tags::Directive>]
270
- # @param dir2 [Array<YARD::Tags::Directive>]
324
+ # @param dir1 [::Array<YARD::Tags::Directive>]
325
+ # @param dir2 [::Array<YARD::Tags::Directive>]
271
326
  # @return [Boolean]
272
327
  def compare_directives dir1, dir2
273
328
  return false if dir1.length != dir2.length
@@ -288,7 +343,7 @@ module Solargraph
288
343
  tag1.types == tag2.types
289
344
  end
290
345
 
291
- # @return [Array<YARD::Tags::Handlers::Directive>]
346
+ # @return [::Array<YARD::Tags::Handlers::Directive>]
292
347
  def collect_macros
293
348
  return [] unless maybe_directives?
294
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,8 +50,8 @@ 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
@@ -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]
@@ -3,35 +3,40 @@
3
3
  module Solargraph
4
4
  module Pin
5
5
  class Block < Closure
6
- # The signature of the method that receives this block.
7
- #
8
6
  # @return [Parser::AST::Node]
9
7
  attr_reader :receiver
10
8
 
11
- # @param args [Array<Parameter>]
12
- def initialize receiver: nil, args: [], context: nil, **splat
9
+ # @return [Parser::AST::Node]
10
+ attr_reader :node
11
+
12
+ # @param receiver [Parser::AST::Node, nil]
13
+ # @param node [Parser::AST::Node, nil]
14
+ # @param context [ComplexType, nil]
15
+ # @param args [::Array<Parameter>]
16
+ def initialize receiver: nil, args: [], context: nil, node: nil, **splat
13
17
  super(**splat)
14
18
  @receiver = receiver
15
19
  @context = context
16
20
  @parameters = args
21
+ @node = node
17
22
  end
18
23
 
19
24
  # @param api_map [ApiMap]
20
25
  # @return [void]
21
26
  def rebind api_map
22
- @binder ||= binder_or_nil(api_map)
27
+ @rebind ||= maybe_rebind(api_map)
23
28
  end
24
29
 
25
30
  def binder
26
- @binder || closure.binder
31
+ @rebind&.defined? ? @rebind : closure.binder
27
32
  end
28
33
 
29
- # @return [Array<Parameter>]
34
+ # @return [::Array<Parameter>]
30
35
  def parameters
31
36
  @parameters ||= []
32
37
  end
33
38
 
34
- # @return [Array<String>]
39
+ # @return [::Array<String>]
35
40
  def parameter_names
36
41
  @parameter_names ||= parameters.map(&:name)
37
42
  end
@@ -39,39 +44,22 @@ module Solargraph
39
44
  private
40
45
 
41
46
  # @param api_map [ApiMap]
42
- # @return [ComplexType, nil]
43
- def binder_or_nil api_map
44
- return nil unless receiver
45
- word = receiver.children.find { |c| c.is_a?(::Symbol) }.to_s
46
- return nil unless api_map.rebindable_method_names.include?(word)
47
+ # @return [ComplexType]
48
+ def maybe_rebind api_map
49
+ return ComplexType::UNDEFINED unless receiver
50
+
47
51
  chain = Parser.chain(receiver, location.filename)
48
52
  locals = api_map.source_map(location.filename).locals_at(location)
49
- links_last_word = chain.links.last.word
50
- if %w[instance_eval instance_exec class_eval class_exec module_eval module_exec].include?(links_last_word)
51
- return chain.base.infer(api_map, self, locals)
52
- end
53
- if 'define_method' == links_last_word and chain.define(api_map, self, locals).first&.path == 'Module#define_method' # change class type to instance type
54
- if chain.links.size > 1 # Class.define_method
55
- ty = chain.base.infer(api_map, self, locals)
56
- return Solargraph::ComplexType.parse(ty.namespace)
57
- else # define_method without self
58
- return Solargraph::ComplexType.parse(closure.binder.namespace)
59
- end
60
- end
61
- # other case without early return, read block yieldreceiver tags
62
53
  receiver_pin = chain.define(api_map, self, locals).first
63
- if receiver_pin && receiver_pin.docstring
64
- ys = receiver_pin.docstring.tag(:yieldreceiver)
65
- if ys && ys.types && !ys.types.empty?
66
- target = if chain.links.first.is_a?(Source::Chain::Constant)
67
- receiver_pin.full_context.namespace
68
- else
69
- full_context.namespace
70
- end
71
- return ComplexType.try_parse(*ys.types).qualify(api_map, receiver_pin.context.namespace).self_to(target)
72
- end
73
- end
74
- nil
54
+ return ComplexType::UNDEFINED unless receiver_pin
55
+
56
+ types = receiver_pin.docstring.tag(:yieldreceiver)&.types
57
+ return ComplexType::UNDEFINED unless types&.any?
58
+
59
+ target = chain.base.infer(api_map, receiver_pin, locals)
60
+ target = full_context unless target.defined?
61
+
62
+ ComplexType.try_parse(*types).qualify(api_map, receiver_pin.context.namespace).self_to(target.to_s)
75
63
  end
76
64
  end
77
65
  end
@@ -6,9 +6,12 @@ module Solargraph
6
6
  # @return [::Symbol] :class or :instance
7
7
  attr_reader :scope
8
8
 
9
- def initialize scope: :class, **splat
9
+ # @param scope [::Symbol] :class or :instance
10
+ # @param generics [::Array<Pin::Parameter>, nil]
11
+ def initialize scope: :class, generics: nil, **splat
10
12
  super(**splat)
11
13
  @scope = scope
14
+ @generics = generics
12
15
  end
13
16
 
14
17
  def context
@@ -26,12 +29,24 @@ module Solargraph
26
29
  @binder || context
27
30
  end
28
31
 
29
- # @return [Array<String>]
32
+ # @return [::Array<String>]
30
33
  def gates
31
34
  # @todo This check might not be necessary. There should always be a
32
35
  # root pin
33
36
  closure ? closure.gates : ['']
34
37
  end
38
+
39
+ # @return [::Array<String>]
40
+ def generics
41
+ @generics ||= docstring.tags(:generic).map(&:name)
42
+ end
43
+
44
+ # @return [String]
45
+ def generics_as_rbs
46
+ return '' if generics.empty?
47
+
48
+ generics.join(', ') + ' '
49
+ end
35
50
  end
36
51
  end
37
52
  end
@@ -6,7 +6,7 @@ module Solargraph
6
6
  # @return [Location]
7
7
  attr_reader :location
8
8
 
9
- # @return [Pin::Base, nil]
9
+ # @return [Pin::Closure, nil]
10
10
  attr_reader :closure
11
11
 
12
12
  # @return [String]
@@ -19,7 +19,7 @@ module Solargraph
19
19
  @return_type ||= ComplexType::UNDEFINED
20
20
  end
21
21
 
22
- # @return [ComplexType]
22
+ # @return [ComplexType, Array<UniqueType>]
23
23
  def context
24
24
  # Get the static context from the nearest namespace
25
25
  @context ||= find_context
@@ -46,6 +46,10 @@ module Solargraph
46
46
  @path ||= name.empty? ? context.namespace : "#{context.namespace}::#{name}"
47
47
  end
48
48
 
49
+ protected
50
+
51
+ attr_writer :context
52
+
49
53
  private
50
54
 
51
55
  # @return [ComplexType]
@@ -56,7 +60,7 @@ module Solargraph
56
60
  return here.return_type
57
61
  elsif here.is_a?(Pin::Method)
58
62
  if here.scope == :instance
59
- return ComplexType.try_parse(here.context.namespace)
63
+ return ComplexType.try_parse(here.context.tag)
60
64
  else
61
65
  return here.context
62
66
  end
@@ -5,7 +5,35 @@ require 'cgi'
5
5
  module Solargraph
6
6
  module Pin
7
7
  # @todo Move this stuff. It should be the responsibility of the language server.
8
+ # @todo abstract methods below should be verified to be overridden
9
+ # by type checker when mixin included by non-abstract class
8
10
  module Conversions
11
+ # @!parse
12
+ # include Documenting
13
+ # include Common
14
+
15
+ # @return [Integer]
16
+ # @abstract
17
+ def completion_item_kind
18
+ raise NotImplementedError
19
+ end
20
+
21
+ # @abstract
22
+ # @return [Boolean]
23
+ def deprecated?
24
+ raise NotImplementedError
25
+ end
26
+
27
+ # @abstract
28
+ def probed?
29
+ raise NotImplementedError
30
+ end
31
+
32
+ # @abstract
33
+ def proxied?
34
+ raise NotImplementedError
35
+ end
36
+
9
37
  # @return [Hash]
10
38
  def completion_item
11
39
  @completion_item ||= {
@@ -34,12 +62,12 @@ module Solargraph
34
62
  end
35
63
  end
36
64
 
37
- # @return [Array<Hash>]
65
+ # @return [::Array<Hash>]
38
66
  def signature_help
39
67
  []
40
68
  end
41
69
 
42
- # @return [String]
70
+ # @return [String, nil]
43
71
  def detail
44
72
  # This property is not cached in an instance variable because it can
45
73
  # change when pins get proxied.
@@ -57,12 +85,14 @@ module Solargraph
57
85
  @link_documentation ||= generate_link
58
86
  end
59
87
 
88
+ # @return [String, nil]
60
89
  def text_documentation
61
90
  this_path = path || return_type.tag
62
91
  return nil if this_path == 'undefined'
63
92
  escape_brackets this_path
64
93
  end
65
94
 
95
+ # @return [void]
66
96
  def reset_conversions
67
97
  @completion_item = nil
68
98
  @resolve_completion_item = nil
@@ -73,7 +103,7 @@ module Solargraph
73
103
 
74
104
  private
75
105
 
76
- # @return [String]
106
+ # @return [String, nil]
77
107
  def generate_link
78
108
  this_path = path || return_type.tag
79
109
  return nil if this_path == 'undefined'