solargraph 0.52.0 → 0.53.0

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 (155) 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 +30 -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/store.rb +45 -9
  10. data/lib/solargraph/api_map.rb +152 -93
  11. data/lib/solargraph/bench.rb +2 -2
  12. data/lib/solargraph/cache.rb +29 -5
  13. data/lib/solargraph/complex_type/type_methods.rb +53 -8
  14. data/lib/solargraph/complex_type/unique_type.rb +149 -59
  15. data/lib/solargraph/complex_type.rb +62 -9
  16. data/lib/solargraph/convention.rb +0 -1
  17. data/lib/solargraph/converters/dd.rb +5 -0
  18. data/lib/solargraph/converters/dl.rb +3 -0
  19. data/lib/solargraph/converters/dt.rb +3 -0
  20. data/lib/solargraph/diagnostics/rubocop.rb +8 -7
  21. data/lib/solargraph/diagnostics/rubocop_helpers.rb +1 -0
  22. data/lib/solargraph/diagnostics/type_check.rb +1 -0
  23. data/lib/solargraph/diagnostics.rb +2 -2
  24. data/lib/solargraph/doc_map.rb +146 -0
  25. data/lib/solargraph/gem_pins.rb +64 -0
  26. data/lib/solargraph/language_server/host/cataloger.rb +1 -0
  27. data/lib/solargraph/language_server/host/diagnoser.rb +2 -2
  28. data/lib/solargraph/language_server/host/dispatch.rb +10 -4
  29. data/lib/solargraph/language_server/host/message_worker.rb +4 -0
  30. data/lib/solargraph/language_server/host/sources.rb +7 -4
  31. data/lib/solargraph/language_server/host.rb +15 -6
  32. data/lib/solargraph/language_server/message/completion_item/resolve.rb +3 -1
  33. data/lib/solargraph/language_server/message/extended/check_gem_version.rb +13 -1
  34. data/lib/solargraph/language_server/message/initialize.rb +5 -2
  35. data/lib/solargraph/language_server/message/text_document/hover.rb +2 -0
  36. data/lib/solargraph/language_server/message/text_document.rb +0 -1
  37. data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +5 -0
  38. data/lib/solargraph/language_server/transport/adapter.rb +16 -1
  39. data/lib/solargraph/language_server/transport/data_reader.rb +2 -0
  40. data/lib/solargraph/library.rb +58 -11
  41. data/lib/solargraph/location.rb +1 -0
  42. data/lib/solargraph/parser/comment_ripper.rb +3 -0
  43. data/lib/solargraph/parser/node_methods.rb +47 -8
  44. data/lib/solargraph/parser/node_processor/base.rb +9 -0
  45. data/lib/solargraph/parser/{legacy → parser_gem}/class_methods.rb +29 -3
  46. data/lib/solargraph/parser/{legacy → parser_gem}/flawed_builder.rb +3 -1
  47. data/lib/solargraph/parser/{legacy → parser_gem}/node_chainer.rb +42 -34
  48. data/lib/solargraph/parser/{legacy → parser_gem}/node_methods.rb +201 -29
  49. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/alias_node.rb +1 -1
  50. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/args_node.rb +4 -1
  51. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/begin_node.rb +1 -1
  52. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/block_node.rb +3 -2
  53. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/casgn_node.rb +2 -2
  54. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/cvasgn_node.rb +1 -1
  55. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/def_node.rb +1 -1
  56. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/defs_node.rb +2 -2
  57. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/gvasgn_node.rb +1 -1
  58. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/ivasgn_node.rb +2 -2
  59. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/lvasgn_node.rb +2 -2
  60. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/namespace_node.rb +2 -2
  61. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/orasgn_node.rb +1 -1
  62. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/resbody_node.rb +3 -3
  63. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/sclass_node.rb +1 -1
  64. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/send_node.rb +2 -2
  65. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/sym_node.rb +1 -1
  66. data/lib/solargraph/parser/parser_gem/node_processors.rb +54 -0
  67. data/lib/solargraph/parser/parser_gem.rb +12 -0
  68. data/lib/solargraph/parser/snippet.rb +2 -0
  69. data/lib/solargraph/parser.rb +8 -11
  70. data/lib/solargraph/pin/base.rb +63 -8
  71. data/lib/solargraph/pin/base_variable.rb +6 -2
  72. data/lib/solargraph/pin/block.rb +11 -6
  73. data/lib/solargraph/pin/closure.rb +17 -2
  74. data/lib/solargraph/pin/common.rb +7 -3
  75. data/lib/solargraph/pin/conversions.rb +33 -3
  76. data/lib/solargraph/pin/documenting.rb +25 -34
  77. data/lib/solargraph/pin/instance_variable.rb +4 -0
  78. data/lib/solargraph/pin/local_variable.rb +13 -1
  79. data/lib/solargraph/pin/method.rb +109 -15
  80. data/lib/solargraph/pin/namespace.rb +16 -10
  81. data/lib/solargraph/pin/parameter.rb +41 -10
  82. data/lib/solargraph/pin/reference/override.rb +2 -2
  83. data/lib/solargraph/pin/reference.rb +8 -0
  84. data/lib/solargraph/pin/search.rb +3 -3
  85. data/lib/solargraph/pin/signature.rb +114 -2
  86. data/lib/solargraph/pin.rb +0 -1
  87. data/lib/solargraph/range.rb +2 -2
  88. data/lib/solargraph/rbs_map/conversions.rb +212 -25
  89. data/lib/solargraph/rbs_map/core_fills.rb +4 -26
  90. data/lib/solargraph/rbs_map/core_map.rb +1 -0
  91. data/lib/solargraph/rbs_map/core_signs.rb +2 -0
  92. data/lib/solargraph/rbs_map/stdlib_map.rb +2 -8
  93. data/lib/solargraph/rbs_map.rb +19 -9
  94. data/lib/solargraph/shell.rb +62 -59
  95. data/lib/solargraph/source/chain/array.rb +4 -1
  96. data/lib/solargraph/source/chain/block_symbol.rb +13 -0
  97. data/lib/solargraph/source/chain/call.rb +95 -26
  98. data/lib/solargraph/source/chain/constant.rb +15 -1
  99. data/lib/solargraph/source/chain/if.rb +23 -0
  100. data/lib/solargraph/source/chain/link.rb +7 -1
  101. data/lib/solargraph/source/chain/or.rb +1 -1
  102. data/lib/solargraph/source/chain/z_super.rb +2 -2
  103. data/lib/solargraph/source/chain.rb +20 -4
  104. data/lib/solargraph/source/change.rb +3 -0
  105. data/lib/solargraph/source/cursor.rb +2 -0
  106. data/lib/solargraph/source/source_chainer.rb +6 -5
  107. data/lib/solargraph/source.rb +15 -16
  108. data/lib/solargraph/source_map/clip.rb +11 -7
  109. data/lib/solargraph/source_map/mapper.rb +10 -0
  110. data/lib/solargraph/source_map.rb +13 -3
  111. data/lib/solargraph/type_checker/checks.rb +10 -2
  112. data/lib/solargraph/type_checker.rb +74 -19
  113. data/lib/solargraph/version.rb +1 -1
  114. data/lib/solargraph/workspace/config.rb +8 -6
  115. data/lib/solargraph/workspace.rb +1 -1
  116. data/lib/solargraph/yard_map/cache.rb +6 -0
  117. data/lib/solargraph/yard_map/helpers.rb +1 -1
  118. data/lib/solargraph/yard_map/mapper/to_method.rb +11 -1
  119. data/lib/solargraph/yard_map/to_method.rb +11 -4
  120. data/lib/solargraph/yard_map.rb +0 -292
  121. data/lib/solargraph/yardoc.rb +52 -0
  122. data/lib/solargraph.rb +4 -1
  123. data/solargraph.gemspec +2 -2
  124. metadata +35 -57
  125. data/lib/solargraph/api_map/bundler_methods.rb +0 -22
  126. data/lib/solargraph/documentor.rb +0 -76
  127. data/lib/solargraph/parser/legacy/node_processors/alias_node.rb +0 -23
  128. data/lib/solargraph/parser/legacy/node_processors/begin_node.rb +0 -15
  129. data/lib/solargraph/parser/legacy/node_processors/sym_node.rb +0 -18
  130. data/lib/solargraph/parser/legacy/node_processors.rb +0 -55
  131. data/lib/solargraph/parser/legacy.rb +0 -12
  132. data/lib/solargraph/parser/rubyvm/class_methods.rb +0 -151
  133. data/lib/solargraph/parser/rubyvm/node_chainer.rb +0 -163
  134. data/lib/solargraph/parser/rubyvm/node_methods.rb +0 -317
  135. data/lib/solargraph/parser/rubyvm/node_processors/args_node.rb +0 -85
  136. data/lib/solargraph/parser/rubyvm/node_processors/block_node.rb +0 -42
  137. data/lib/solargraph/parser/rubyvm/node_processors/casgn_node.rb +0 -33
  138. data/lib/solargraph/parser/rubyvm/node_processors/cvasgn_node.rb +0 -23
  139. data/lib/solargraph/parser/rubyvm/node_processors/def_node.rb +0 -75
  140. data/lib/solargraph/parser/rubyvm/node_processors/defs_node.rb +0 -68
  141. data/lib/solargraph/parser/rubyvm/node_processors/gvasgn_node.rb +0 -23
  142. data/lib/solargraph/parser/rubyvm/node_processors/ivasgn_node.rb +0 -38
  143. data/lib/solargraph/parser/rubyvm/node_processors/kw_arg_node.rb +0 -39
  144. data/lib/solargraph/parser/rubyvm/node_processors/lit_node.rb +0 -20
  145. data/lib/solargraph/parser/rubyvm/node_processors/lvasgn_node.rb +0 -27
  146. data/lib/solargraph/parser/rubyvm/node_processors/namespace_node.rb +0 -39
  147. data/lib/solargraph/parser/rubyvm/node_processors/opt_arg_node.rb +0 -26
  148. data/lib/solargraph/parser/rubyvm/node_processors/orasgn_node.rb +0 -15
  149. data/lib/solargraph/parser/rubyvm/node_processors/resbody_node.rb +0 -51
  150. data/lib/solargraph/parser/rubyvm/node_processors/sclass_node.rb +0 -32
  151. data/lib/solargraph/parser/rubyvm/node_processors/scope_node.rb +0 -15
  152. data/lib/solargraph/parser/rubyvm/node_processors/send_node.rb +0 -279
  153. data/lib/solargraph/parser/rubyvm/node_processors.rb +0 -64
  154. data/lib/solargraph/parser/rubyvm/node_wrapper.rb +0 -47
  155. data/lib/solargraph/parser/rubyvm.rb +0 -40
@@ -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,7 +50,7 @@ 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?)
53
+ chain = Parser.chain(node, nil, nil)
54
54
  result = chain.infer(api_map, closure, clip.locals)
55
55
  types.push result unless result.undefined?
56
56
  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,17 +3,22 @@
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]
@@ -26,12 +31,12 @@ module Solargraph
26
31
  @binder || 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
@@ -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'
@@ -38,23 +38,20 @@ module Solargraph
38
38
  end
39
39
 
40
40
  def to_s
41
- return "\n```ruby\n#{@plaintext}#{@plaintext.end_with?("\n") ? '' : "\n"}```\n\n" if code?
42
- ReverseMarkdown.convert unescape_brackets(Kramdown::Document.new(escape_brackets(@plaintext), input: 'GFM').to_html)
41
+ return to_code if code?
42
+ to_markdown
43
43
  end
44
44
 
45
45
  private
46
46
 
47
- # @param text [String]
48
47
  # @return [String]
49
- def escape_brackets text
50
- # text.gsub(/(\[[^\]]*\])([^\(]|\z)/, '!!!^\1^!!!\2')
51
- text.gsub('[', '!!!!b').gsub(']', 'e!!!!')
48
+ def to_code
49
+ "\n```ruby\n#{Documenting.normalize_indentation(@plaintext)}#{@plaintext.end_with?("\n") ? '' : "\n"}```\n\n"
52
50
  end
53
51
 
54
- # @param text [String]
55
52
  # @return [String]
56
- def unescape_brackets text
57
- text.gsub('!!!!b', '[').gsub('e!!!!', ']')
53
+ def to_markdown
54
+ ReverseMarkdown.convert Kramdown::Document.new(@plaintext, input: 'GFM').to_html
58
55
  end
59
56
  end
60
57
 
@@ -65,40 +62,34 @@ module Solargraph
65
62
  # line and at least two spaces of indentation. This is a common
66
63
  # convention in Ruby core documentation, e.g., String#split.
67
64
  sections = [DocSection.new(false)]
68
- normalize_indentation(docstring.to_s).gsub(/\t/, ' ').lines.each do |l|
69
- if l.strip.empty?
70
- sections.last.concat l
71
- else
72
- if (l =~ /^ [^\s]/ && sections.last.plaintext =~ /(\r?\n[ \t]*?){2,}$/) || (l.start_with?(' ') && sections.last.code?)
73
- # Code block
74
- sections.push DocSection.new(true) unless sections.last.code?
75
- sections.last.concat l[2..-1]
76
- else
77
- # Regular documentation
78
- sections.push DocSection.new(false) if sections.last.code?
79
- sections.last.concat l
80
- end
65
+ Documenting.normalize_indentation(Documenting.strip_html_comments(docstring.to_s.gsub("\t", ' '))).lines.each do |l|
66
+ if l.start_with?(' ')
67
+ # Code block
68
+ sections.push DocSection.new(true) unless sections.last.code?
69
+ elsif sections.last.code?
70
+ # Regular documentation
71
+ sections.push DocSection.new(false)
81
72
  end
73
+ sections.last.concat l
82
74
  end
83
75
  sections.map(&:to_s).join.strip
84
76
  end
85
77
  end
86
78
 
87
- private
88
-
89
- # @param text [String]
90
- # @return [String]
91
- def normalize_indentation text
92
- text.lines.map { |l| remove_odd_spaces(l) }.join
79
+ def self.strip_html_comments text
80
+ text.gsub(/<!--([\s\S]*?)-->/, '').strip
93
81
  end
94
82
 
95
- # @param line [String]
83
+ # @param text [String]
96
84
  # @return [String]
97
- def remove_odd_spaces line
98
- return line unless line.start_with?(' ')
99
- spaces = line.match(/^ +/)[0].length
100
- return line unless spaces.odd?
101
- line[1..-1]
85
+ def self.normalize_indentation text
86
+ left = text.lines.map do |line|
87
+ match = line.match(/^ +/)
88
+ next 0 unless match
89
+ match[0].length
90
+ end.min
91
+ return text if left.nil? || left.zero?
92
+ text.lines.map { |line| line[left..] }.join
102
93
  end
103
94
  end
104
95
  end
@@ -3,14 +3,17 @@
3
3
  module Solargraph
4
4
  module Pin
5
5
  class InstanceVariable < BaseVariable
6
+ # @return [ComplexType]
6
7
  def binder
7
8
  closure.binder
8
9
  end
9
10
 
11
+ # @return [::Symbol]
10
12
  def scope
11
13
  closure.binder.scope
12
14
  end
13
15
 
16
+ # @return [ComplexType]
14
17
  def context
15
18
  @context ||= begin
16
19
  result = super
@@ -22,6 +25,7 @@ module Solargraph
22
25
  end
23
26
  end
24
27
 
28
+ # @param other [InstanceVariable]
25
29
  def nearly? other
26
30
  super && binder == other.binder
27
31
  end
@@ -6,12 +6,16 @@ module Solargraph
6
6
  # @return [Range]
7
7
  attr_reader :presence
8
8
 
9
+ # @param assignment [AST::Node, nil]
10
+ # @param presence [Range, nil]
11
+ # @param splat [Hash]
9
12
  def initialize assignment: nil, presence: nil, **splat
10
13
  super(**splat)
11
14
  @assignment = assignment
12
15
  @presence = presence
13
16
  end
14
17
 
18
+ # @param pin [self]
15
19
  def try_merge! pin
16
20
  return false unless super
17
21
  @presence = pin.presence
@@ -21,11 +25,16 @@ module Solargraph
21
25
  # @param other_closure [Pin::Closure]
22
26
  # @param other_loc [Location]
23
27
  def visible_at?(other_closure, other_loc)
24
- return true if location.filename == other_loc.filename &&
28
+ location.filename == other_loc.filename &&
25
29
  presence.include?(other_loc.range.start) &&
26
30
  match_named_closure(other_closure, closure)
27
31
  end
28
32
 
33
+ # @return [String]
34
+ def to_rbs
35
+ (name || '(anon)') + ' ' + (return_type&.to_rbs || 'untyped')
36
+ end
37
+
29
38
  private
30
39
 
31
40
  # @param tag1 [String]
@@ -40,6 +49,9 @@ module Solargraph
40
49
  (['', 'Class<>'].include?(tag1) && ['', 'Class<>'].include?(tag2))
41
50
  end
42
51
 
52
+ # @param needle [Pin::Base]
53
+ # @param haystack [Pin::Base]
54
+ # @return [Boolean]
43
55
  def match_named_closure needle, haystack
44
56
  return true if needle == haystack || haystack.is_a?(Pin::Block)
45
57
  cursor = haystack