solargraph 0.38.6 → 0.39.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +4 -4
  2. data/SPONSORS.md +9 -0
  3. data/lib/solargraph.rb +1 -0
  4. data/lib/solargraph/api_map.rb +24 -13
  5. data/lib/solargraph/api_map/bundler_methods.rb +3 -0
  6. data/lib/solargraph/api_map/source_to_yard.rb +1 -6
  7. data/lib/solargraph/api_map/store.rb +19 -3
  8. data/lib/solargraph/complex_type/type_methods.rb +4 -4
  9. data/lib/solargraph/convention/base.rb +0 -5
  10. data/lib/solargraph/core_fills.rb +28 -2
  11. data/lib/solargraph/diagnostics/base.rb +1 -0
  12. data/lib/solargraph/diagnostics/type_check.rb +13 -13
  13. data/lib/solargraph/language_server/host.rb +11 -2
  14. data/lib/solargraph/language_server/host/sources.rb +20 -11
  15. data/lib/solargraph/language_server/message/text_document/formatting.rb +16 -11
  16. data/lib/solargraph/language_server/transport/data_reader.rb +2 -0
  17. data/lib/solargraph/library.rb +3 -3
  18. data/lib/solargraph/parser.rb +26 -0
  19. data/lib/solargraph/parser/comment_ripper.rb +52 -0
  20. data/lib/solargraph/parser/legacy.rb +12 -0
  21. data/lib/solargraph/parser/legacy/class_methods.rb +105 -0
  22. data/lib/solargraph/parser/legacy/flawed_builder.rb +16 -0
  23. data/lib/solargraph/parser/legacy/node_chainer.rb +115 -0
  24. data/lib/solargraph/parser/legacy/node_methods.rb +289 -0
  25. data/lib/solargraph/parser/legacy/node_processors.rb +54 -0
  26. data/lib/solargraph/parser/legacy/node_processors/alias_node.rb +23 -0
  27. data/lib/solargraph/parser/legacy/node_processors/args_node.rb +35 -0
  28. data/lib/solargraph/parser/legacy/node_processors/begin_node.rb +15 -0
  29. data/lib/solargraph/parser/legacy/node_processors/block_node.rb +22 -0
  30. data/lib/solargraph/parser/legacy/node_processors/casgn_node.rb +25 -0
  31. data/lib/solargraph/parser/legacy/node_processors/cvasgn_node.rb +23 -0
  32. data/lib/solargraph/parser/legacy/node_processors/def_node.rb +63 -0
  33. data/lib/solargraph/parser/legacy/node_processors/defs_node.rb +36 -0
  34. data/lib/solargraph/parser/legacy/node_processors/gvasgn_node.rb +23 -0
  35. data/lib/solargraph/parser/legacy/node_processors/ivasgn_node.rb +38 -0
  36. data/lib/solargraph/parser/legacy/node_processors/lvasgn_node.rb +28 -0
  37. data/lib/solargraph/parser/legacy/node_processors/namespace_node.rb +39 -0
  38. data/lib/solargraph/parser/legacy/node_processors/orasgn_node.rb +16 -0
  39. data/lib/solargraph/parser/legacy/node_processors/resbody_node.rb +36 -0
  40. data/lib/solargraph/parser/legacy/node_processors/sclass_node.rb +21 -0
  41. data/lib/solargraph/parser/legacy/node_processors/send_node.rb +232 -0
  42. data/lib/solargraph/parser/legacy/node_processors/sym_node.rb +18 -0
  43. data/lib/solargraph/parser/node_methods.rb +43 -0
  44. data/lib/solargraph/parser/node_processor.rb +43 -0
  45. data/lib/solargraph/parser/node_processor/base.rb +77 -0
  46. data/lib/solargraph/{source_map → parser}/region.rb +11 -6
  47. data/lib/solargraph/parser/rubyvm.rb +40 -0
  48. data/lib/solargraph/parser/rubyvm/class_methods.rb +146 -0
  49. data/lib/solargraph/parser/rubyvm/node_chainer.rb +133 -0
  50. data/lib/solargraph/parser/rubyvm/node_methods.rb +279 -0
  51. data/lib/solargraph/parser/rubyvm/node_processors.rb +60 -0
  52. data/lib/solargraph/parser/rubyvm/node_processors/alias_node.rb +23 -0
  53. data/lib/solargraph/parser/rubyvm/node_processors/args_node.rb +62 -0
  54. data/lib/solargraph/parser/rubyvm/node_processors/begin_node.rb +15 -0
  55. data/lib/solargraph/parser/rubyvm/node_processors/block_node.rb +22 -0
  56. data/lib/solargraph/parser/rubyvm/node_processors/casgn_node.rb +22 -0
  57. data/lib/solargraph/parser/rubyvm/node_processors/cvasgn_node.rb +23 -0
  58. data/lib/solargraph/parser/rubyvm/node_processors/def_node.rb +64 -0
  59. data/lib/solargraph/parser/rubyvm/node_processors/defs_node.rb +57 -0
  60. data/lib/solargraph/parser/rubyvm/node_processors/gvasgn_node.rb +23 -0
  61. data/lib/solargraph/parser/rubyvm/node_processors/ivasgn_node.rb +38 -0
  62. data/lib/solargraph/parser/rubyvm/node_processors/kw_arg_node.rb +34 -0
  63. data/lib/solargraph/parser/rubyvm/node_processors/lit_node.rb +20 -0
  64. data/lib/solargraph/parser/rubyvm/node_processors/lvasgn_node.rb +27 -0
  65. data/lib/solargraph/parser/rubyvm/node_processors/namespace_node.rb +39 -0
  66. data/lib/solargraph/parser/rubyvm/node_processors/opt_arg_node.rb +26 -0
  67. data/lib/solargraph/parser/rubyvm/node_processors/orasgn_node.rb +15 -0
  68. data/lib/solargraph/parser/rubyvm/node_processors/resbody_node.rb +45 -0
  69. data/lib/solargraph/parser/rubyvm/node_processors/sclass_node.rb +21 -0
  70. data/lib/solargraph/parser/rubyvm/node_processors/scope_node.rb +15 -0
  71. data/lib/solargraph/parser/rubyvm/node_processors/send_node.rb +292 -0
  72. data/lib/solargraph/parser/rubyvm/node_processors/sym_node.rb +18 -0
  73. data/lib/solargraph/parser/snippet.rb +13 -0
  74. data/lib/solargraph/pin/attribute.rb +8 -0
  75. data/lib/solargraph/pin/base.rb +1 -1
  76. data/lib/solargraph/pin/base_method.rb +26 -4
  77. data/lib/solargraph/pin/base_variable.rb +7 -8
  78. data/lib/solargraph/pin/block.rb +1 -1
  79. data/lib/solargraph/pin/constant.rb +16 -0
  80. data/lib/solargraph/pin/conversions.rb +2 -2
  81. data/lib/solargraph/pin/method.rb +26 -14
  82. data/lib/solargraph/pin/parameter.rb +56 -2
  83. data/lib/solargraph/pin/reference.rb +1 -0
  84. data/lib/solargraph/pin/reference/override.rb +2 -0
  85. data/lib/solargraph/pin/reference/prepend.rb +10 -0
  86. data/lib/solargraph/pin/yard_pin/constant.rb +2 -4
  87. data/lib/solargraph/pin/yard_pin/method.rb +34 -18
  88. data/lib/solargraph/pin/yard_pin/namespace.rb +3 -11
  89. data/lib/solargraph/pin/yard_pin/yard_mixin.rb +3 -12
  90. data/lib/solargraph/range.rb +8 -2
  91. data/lib/solargraph/shell.rb +17 -11
  92. data/lib/solargraph/source.rb +114 -135
  93. data/lib/solargraph/source/chain.rb +11 -3
  94. data/lib/solargraph/source/chain/call.rb +1 -2
  95. data/lib/solargraph/source/chain/constant.rb +44 -8
  96. data/lib/solargraph/source/chain/link.rb +1 -0
  97. data/lib/solargraph/source/cursor.rb +2 -28
  98. data/lib/solargraph/source/source_chainer.rb +12 -6
  99. data/lib/solargraph/source/updater.rb +2 -0
  100. data/lib/solargraph/source_map.rb +0 -2
  101. data/lib/solargraph/source_map/clip.rb +24 -17
  102. data/lib/solargraph/source_map/mapper.rb +34 -29
  103. data/lib/solargraph/type_checker.rb +367 -275
  104. data/lib/solargraph/type_checker/checks.rb +95 -0
  105. data/lib/solargraph/type_checker/param_def.rb +2 -17
  106. data/lib/solargraph/type_checker/rules.rb +53 -0
  107. data/lib/solargraph/version.rb +1 -1
  108. data/lib/solargraph/views/environment.erb +5 -3
  109. data/lib/solargraph/workspace.rb +17 -2
  110. data/lib/solargraph/workspace/config.rb +15 -7
  111. data/lib/solargraph/yard_map.rb +89 -49
  112. data/lib/solargraph/yard_map/core_docs.rb +1 -1
  113. data/solargraph.gemspec +2 -1
  114. metadata +88 -32
  115. data/OVERVIEW.md +0 -37
  116. data/lib/solargraph/source/flawed_builder.rb +0 -15
  117. data/lib/solargraph/source/node_chainer.rb +0 -111
  118. data/lib/solargraph/source/node_methods.rb +0 -240
  119. data/lib/solargraph/source_map/node_processor.rb +0 -85
  120. data/lib/solargraph/source_map/node_processor/alias_node.rb +0 -21
  121. data/lib/solargraph/source_map/node_processor/args_node.rb +0 -24
  122. data/lib/solargraph/source_map/node_processor/base.rb +0 -103
  123. data/lib/solargraph/source_map/node_processor/begin_node.rb +0 -13
  124. data/lib/solargraph/source_map/node_processor/block_node.rb +0 -21
  125. data/lib/solargraph/source_map/node_processor/casgn_node.rb +0 -21
  126. data/lib/solargraph/source_map/node_processor/cvasgn_node.rb +0 -21
  127. data/lib/solargraph/source_map/node_processor/def_node.rb +0 -62
  128. data/lib/solargraph/source_map/node_processor/defs_node.rb +0 -33
  129. data/lib/solargraph/source_map/node_processor/gvasgn_node.rb +0 -21
  130. data/lib/solargraph/source_map/node_processor/ivasgn_node.rb +0 -34
  131. data/lib/solargraph/source_map/node_processor/lvasgn_node.rb +0 -24
  132. data/lib/solargraph/source_map/node_processor/namespace_node.rb +0 -35
  133. data/lib/solargraph/source_map/node_processor/orasgn_node.rb +0 -14
  134. data/lib/solargraph/source_map/node_processor/resbody_node.rb +0 -32
  135. data/lib/solargraph/source_map/node_processor/sclass_node.rb +0 -19
  136. data/lib/solargraph/source_map/node_processor/send_node.rb +0 -217
  137. data/lib/solargraph/source_map/node_processor/sym_node.rb +0 -16
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Parser
5
+ module Rubyvm
6
+ module NodeProcessors
7
+ class SymNode < Parser::NodeProcessor::Base
8
+ def process
9
+ pins.push Solargraph::Pin::Symbol.new(
10
+ get_node_location(node),
11
+ ":#{node.children[0]}"
12
+ )
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ module Solargraph
2
+ module Parser
3
+ class Snippet
4
+ attr_reader :range
5
+ attr_reader :text
6
+
7
+ def initialize range, text
8
+ @range = range
9
+ @text = text
10
+ end
11
+ end
12
+ end
13
+ end
@@ -10,6 +10,14 @@ module Solargraph
10
10
  def initialize access: :reader, **splat
11
11
  super(splat)
12
12
  @access = access
13
+ if access == :writer
14
+ parameters.push(
15
+ Pin::Parameter.new(name: 'value', decl: :arg, closure: self)
16
+ )
17
+ if return_type.defined?
18
+ docstring.add_tag YARD::Tags::Tag.new(:param, '', return_type.to_s.split(', '), 'value')
19
+ end
20
+ end
13
21
  end
14
22
 
15
23
  def completion_item_kind
@@ -49,7 +49,7 @@ module Solargraph
49
49
  LanguageServer::CompletionItemKinds::KEYWORD
50
50
  end
51
51
 
52
- # @return [Integer]
52
+ # @return [Integer, nil]
53
53
  def symbol_kind
54
54
  nil
55
55
  end
@@ -8,10 +8,15 @@ module Solargraph
8
8
  # @return [::Symbol] :public, :private, or :protected
9
9
  attr_reader :visibility
10
10
 
11
+ # @return [Parser::AST::Node]
12
+ attr_reader :node
13
+
11
14
  # @param visibility [::Symbol] :public, :protected, or :private
12
- def initialize visibility: :public, **splat
15
+ # @param explicit [Boolean]
16
+ def initialize visibility: :public, explicit: true, **splat
13
17
  super(splat)
14
18
  @visibility = visibility
19
+ @explicit = explicit
15
20
  end
16
21
 
17
22
  def return_type
@@ -30,14 +35,14 @@ module Solargraph
30
35
  name.end_with?('?') ? ComplexType::BOOLEAN : ComplexType::UNDEFINED
31
36
  end
32
37
 
33
- # @return [Array<String>]
38
+ # @return [Array<Pin::Parameter>]
34
39
  def parameters
35
- []
40
+ @parameters ||= []
36
41
  end
37
42
 
38
43
  # @return [Array<String>]
39
44
  def parameter_names
40
- []
45
+ parameters.map(&:name)
41
46
  end
42
47
 
43
48
  def documentation
@@ -56,12 +61,29 @@ module Solargraph
56
61
  end
57
62
  @documentation += lines.join("\n")
58
63
  end
64
+ return_tags = docstring.tags(:return)
65
+ unless return_tags.empty?
66
+ @documentation += "\n\n" unless @documentation.empty?
67
+ @documentation += "Returns:\n"
68
+ lines = []
69
+ return_tags.each do |r|
70
+ l = "*"
71
+ l += " [#{escape_brackets(r.types.join(', '))}]" unless r.types.nil? or r.types.empty?
72
+ l += " #{r.text}"
73
+ lines.push l
74
+ end
75
+ @documentation += lines.join("\n")
76
+ end
59
77
  @documentation += "\n\n" unless @documentation.empty?
60
78
  @documentation += "Visibility: #{visibility}"
61
79
  end
62
80
  @documentation.to_s
63
81
  end
64
82
 
83
+ def explicit?
84
+ @explicit
85
+ end
86
+
65
87
  private
66
88
 
67
89
  # @return [ComplexType]
@@ -3,7 +3,8 @@
3
3
  module Solargraph
4
4
  module Pin
5
5
  class BaseVariable < Base
6
- include Solargraph::Source::NodeMethods
6
+ include Solargraph::Parser::NodeMethods
7
+ # include Solargraph::Source::NodeMethods
7
8
 
8
9
  # @return [Parser::AST::Node, nil]
9
10
  attr_reader :assignment
@@ -14,10 +15,6 @@ module Solargraph
14
15
  @assignment = assignment
15
16
  end
16
17
 
17
- def signature
18
- @signature ||= resolve_node_signature(@assignment)
19
- end
20
-
21
18
  def completion_item_kind
22
19
  Solargraph::LanguageServer::CompletionItemKinds::VARIABLE
23
20
  end
@@ -44,14 +41,16 @@ module Solargraph
44
41
  types = []
45
42
  returns_from(@assignment).each do |node|
46
43
  # Nil nodes may not have a location
47
- if node.type == :nil
44
+ if node.nil? || node.type == :NIL || node.type == :nil
48
45
  types.push ComplexType::NIL
49
46
  else
50
- pos = Solargraph::Position.new(node.loc.expression.last_line, node.loc.expression.last_column)
47
+ rng = Range.from_node(node)
48
+ next if rng.nil?
49
+ pos = rng.ending
51
50
  clip = api_map.clip_at(location.filename, pos)
52
51
  # Use the return node for inference. The clip might infer from the
53
52
  # first node in a method call instead of the entire call.
54
- chain = Solargraph::Source::NodeChainer.chain(node, nil, clip.in_block?)
53
+ chain = Parser.chain(node, nil, clip.in_block?)
55
54
  result = chain.infer(api_map, closure, clip.locals)
56
55
  types.push result unless result.undefined?
57
56
  end
@@ -34,7 +34,7 @@ module Solargraph
34
34
 
35
35
  # @return [Array<String>]
36
36
  def parameter_names
37
- @parameter_names ||= parameters.map{|p| p.split(/[ =:]/).first.gsub(/^(\*{1,2}|&)/, '')}
37
+ @parameter_names ||= parameters.map(&:name)
38
38
  end
39
39
 
40
40
  def nearly? other
@@ -10,6 +10,10 @@ module Solargraph
10
10
  @visibility = visibility
11
11
  end
12
12
 
13
+ def return_type
14
+ @return_type ||= generate_complex_type
15
+ end
16
+
13
17
  def completion_item_kind
14
18
  Solargraph::LanguageServer::CompletionItemKinds::CONSTANT
15
19
  end
@@ -22,6 +26,18 @@ module Solargraph
22
26
  def path
23
27
  @path ||= context.namespace.to_s.empty? ? name : "#{context.namespace}::#{name}"
24
28
  end
29
+
30
+ private
31
+
32
+ # @return [ComplexType]
33
+ def generate_complex_type
34
+ tags = docstring.tags(:return).map(&:types).flatten.reject(&:nil?)
35
+ if tags.empty?
36
+ tags = docstring.tags(:type).map(&:types).flatten.reject(&:nil?)
37
+ end
38
+ return ComplexType::UNDEFINED if tags.empty?
39
+ ComplexType.try_parse *tags
40
+ end
25
41
  end
26
42
  end
27
43
  end
@@ -38,7 +38,7 @@ module Solargraph
38
38
  # @return [Hash]
39
39
  def signature_help
40
40
  @signature_help ||= {
41
- label: name + '(' + parameters.join(', ') + ')',
41
+ label: name + '(' + parameters.map(&:full).join(', ') + ')',
42
42
  documentation: documentation
43
43
  }
44
44
  end
@@ -48,7 +48,7 @@ module Solargraph
48
48
  # This property is not cached in an instance variable because it can
49
49
  # change when pins get proxied.
50
50
  detail = String.new
51
- detail += "(#{parameters.join(', ')}) " unless !is_a?(Pin::BaseMethod) or parameters.empty?
51
+ detail += "(#{parameters.map(&:full).join(', ')}) " unless !is_a?(Pin::BaseMethod) || parameters.empty?
52
52
  detail += "=#{probed? ? '~' : (proxied? ? '^' : '>')} #{return_type.to_s}" unless return_type.undefined?
53
53
  detail.strip!
54
54
  return nil if detail.empty?
@@ -3,25 +3,22 @@
3
3
  module Solargraph
4
4
  module Pin
5
5
  class Method < BaseMethod
6
- include Source::NodeMethods
6
+ include Solargraph::Parser::NodeMethods
7
7
 
8
8
  # @return [Array<String>]
9
9
  attr_reader :parameters
10
10
 
11
- # @return [Parser::AST::Node]
12
- attr_reader :node
13
-
14
11
  # @param args [Array<String>]
15
12
  # @param node [Parser::AST::Node, nil]
16
- def initialize args: [], node: nil, **splat
13
+ def initialize parameters: [], node: nil, **splat
17
14
  super(splat)
18
- @parameters = args
15
+ @parameters = parameters
19
16
  @node = node
20
17
  end
21
18
 
22
19
  # @return [Array<String>]
23
20
  def parameter_names
24
- @parameter_names ||= parameters.map{|p| p.split(/[ =:]/).first.gsub(/^(\*{1,2}|&)/, '')}
21
+ @parameter_names ||= parameters.map(&:name)
25
22
  end
26
23
 
27
24
  def completion_item_kind
@@ -54,8 +51,18 @@ module Solargraph
54
51
  @overloads ||= docstring.tags(:overload).map do |tag|
55
52
  Solargraph::Pin::Method.new(
56
53
  name: name,
57
- closure: closure,
58
- args: tag.parameters.map(&:first),
54
+ closure: self,
55
+ # args: tag.parameters.map(&:first),
56
+ parameters: tag.parameters.map do |src|
57
+ Pin::Parameter.new(
58
+ location: location,
59
+ closure: self,
60
+ comments: tag.docstring.all.to_s,
61
+ name: src.first,
62
+ presence: location ? location.range : nil,
63
+ decl: :arg
64
+ )
65
+ end,
59
66
  comments: tag.docstring.all.to_s
60
67
  )
61
68
  end
@@ -66,7 +73,9 @@ module Solargraph
66
73
  # @return [Parser::AST::Node, nil]
67
74
  def method_body_node
68
75
  return nil if node.nil?
69
- return node.children[2] if node.type == :def
76
+ return node.children[1].children.last if node.type == :DEFN
77
+ return node.children[2].children.last if node.type == :DEFS
78
+ return node.children[2] if node.type == :def || node.type == :DEFS
70
79
  return node.children[3] if node.type == :defs
71
80
  nil
72
81
  end
@@ -74,19 +83,22 @@ module Solargraph
74
83
  # @param api_map [ApiMap]
75
84
  # @return [ComplexType]
76
85
  def infer_from_return_nodes api_map
86
+ return ComplexType::UNDEFINED if node.nil?
77
87
  result = []
78
88
  has_nil = false
89
+ return ComplexType::NIL if method_body_node.nil?
79
90
  returns_from(method_body_node).each do |n|
80
- if n.nil? || n.type == :nil
91
+ if n.nil? || [:NIL, :nil].include?(n.type)
81
92
  has_nil = true
82
93
  next
83
94
  end
84
- next if n.loc.nil? || n.loc.expression.nil?
95
+ rng = Range.from_node(n)
96
+ next unless rng
85
97
  clip = api_map.clip_at(
86
98
  location.filename,
87
- [n.loc.expression.last_line, n.loc.expression.last_column]
99
+ rng.ending
88
100
  )
89
- chain = Solargraph::Source::NodeChainer.chain(n, location.filename)
101
+ chain = Solargraph::Parser.chain(n, location.filename)
90
102
  type = chain.infer(api_map, self, clip.locals)
91
103
  result.push type unless type.undefined?
92
104
  end
@@ -3,11 +3,65 @@
3
3
  module Solargraph
4
4
  module Pin
5
5
  class Parameter < LocalVariable
6
+ attr_reader :decl
7
+
8
+ attr_reader :asgn_code
9
+
10
+ def initialize decl: :arg, asgn_code: nil, **splat
11
+ super(splat)
12
+ @asgn_code = asgn_code
13
+ @decl = decl
14
+ end
15
+
16
+ def keyword?
17
+ [:kwarg, :kwoptarg].include?(decl)
18
+ end
19
+
20
+ def kwrestarg?
21
+ decl == :kwrestarg || (assignment && [:HASH, :hash].include?(assignment.type))
22
+ end
23
+
24
+ def restarg?
25
+ decl == :restarg
26
+ end
27
+
28
+ def rest?
29
+ decl == :restarg || decl == :kwrestarg
30
+ end
31
+
32
+ def full
33
+ case decl
34
+ when :optarg
35
+ "#{name} = #{asgn_code}"
36
+ when :kwarg
37
+ "#{name}:"
38
+ when :kwoptarg
39
+ "#{name}: #{asgn_code}"
40
+ when :restarg
41
+ "*#{name}"
42
+ when :kwrestarg
43
+ "**#{name}"
44
+ when :block
45
+ "&#{name}"
46
+ else
47
+ name
48
+ end
49
+ end
50
+
6
51
  def return_type
7
52
  if @return_type.nil?
8
- @return_type = ComplexType.new
53
+ @return_type = ComplexType::UNDEFINED
9
54
  found = param_tag
10
55
  @return_type = ComplexType.try_parse(*found.types) unless found.nil? or found.types.nil?
56
+ if @return_type.undefined?
57
+ if decl == :restarg
58
+ @return_type = ComplexType.try_parse('Array')
59
+ elsif decl == :kwrestarg
60
+ @return_type = ComplexType.try_parse('Hash')
61
+ elsif decl == :blockarg
62
+ @return_type = ComplexType.try_parse('Proc')
63
+ end
64
+ end
11
65
  end
12
66
  super
13
67
  @return_type
@@ -62,7 +116,7 @@ module Solargraph
62
116
  # @return [ComplexType]
63
117
  def typify_block_param api_map
64
118
  if closure.is_a?(Pin::Block) && closure.receiver
65
- chain = Source::NodeChainer.chain(closure.receiver, filename)
119
+ chain = Parser.chain(closure.receiver, filename)
66
120
  clip = api_map.clip_at(location.filename, location.range.start)
67
121
  locals = clip.locals - [self]
68
122
  meths = chain.define(api_map, closure, locals)
@@ -6,6 +6,7 @@ module Solargraph
6
6
  autoload :Require, 'solargraph/pin/reference/require'
7
7
  autoload :Superclass, 'solargraph/pin/reference/superclass'
8
8
  autoload :Include, 'solargraph/pin/reference/include'
9
+ autoload :Prepend, 'solargraph/pin/reference/prepend'
9
10
  autoload :Extend, 'solargraph/pin/reference/extend'
10
11
  autoload :Override, 'solargraph/pin/reference/override'
11
12
  end
@@ -4,8 +4,10 @@ module Solargraph
4
4
  module Pin
5
5
  class Reference
6
6
  class Override < Reference
7
+ # @return [Array<YARD::Tags::Tag>]
7
8
  attr_reader :tags
8
9
 
10
+ # @return [Array<Symbol>]
9
11
  attr_reader :delete
10
12
 
11
13
  def initialize location, name, tags, delete = []
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Pin
5
+ class Reference
6
+ class Prepend < Reference
7
+ end
8
+ end
9
+ end
10
+ end
@@ -7,17 +7,15 @@ module Solargraph
7
7
  include YardMixin
8
8
 
9
9
  def initialize code_object, closure = nil, spec = nil
10
- @code_object = code_object
11
- @spec = spec
12
10
  closure ||= Solargraph::Pin::Namespace.new(
13
11
  name: code_object.namespace.to_s,
14
12
  gates: [code_object.namespace.to_s]
15
13
  )
16
14
  super(
17
- location: location,
15
+ location: object_location(code_object, spec),
18
16
  closure: closure,
19
17
  name: code_object.name.to_s,
20
- comments: nil,
18
+ comments: code_object.docstring ? code_object.docstring.all.to_s : '',
21
19
  visibility: code_object.visibility
22
20
  )
23
21
  end
@@ -7,41 +7,57 @@ module Solargraph
7
7
  include YardMixin
8
8
 
9
9
  def initialize code_object, name = nil, scope = nil, visibility = nil, closure = nil, spec = nil
10
- @code_object = code_object
11
- @spec = spec
12
10
  closure ||= Solargraph::Pin::Namespace.new(
13
11
  name: code_object.namespace.to_s,
14
12
  gates: [code_object.namespace.to_s]
15
13
  )
16
14
  super(
17
- location: location,
15
+ location: object_location(code_object, spec),
18
16
  closure: closure,
19
17
  name: name || code_object.name.to_s,
20
- comments: nil,
18
+ comments: code_object.docstring ? code_object.docstring.all.to_s : '',
21
19
  scope: scope || code_object.scope,
22
20
  visibility: visibility || code_object.visibility,
23
- args: nil
21
+ parameters: get_parameters(code_object),
22
+ explicit: code_object.is_explicit?
24
23
  )
25
24
  end
26
25
 
27
- def parameters
28
- @parameters ||= get_parameters(code_object)
29
- end
30
-
31
26
  private
32
27
 
33
28
  def get_parameters code_object
34
29
  return [] unless code_object.is_a?(YARD::CodeObjects::MethodObject)
35
- args = []
36
- code_object.parameters.each do |a|
37
- p = a[0]
38
- unless a[1].nil?
39
- p += ' =' unless p.end_with?(':')
40
- p += " #{a[1]}"
41
- end
42
- args.push p
30
+ code_object.parameters.map do |a|
31
+ Solargraph::Pin::Parameter.new(
32
+ location: location,
33
+ closure: self,
34
+ comments: comments,
35
+ name: arg_name(a),
36
+ presence: nil,
37
+ decl: arg_type(a),
38
+ asgn_code: a[1]
39
+ )
40
+ end
41
+ end
42
+
43
+ def arg_name a
44
+ a[0].match(/[A-Za-z0-9_]*/)[0]
45
+ end
46
+
47
+ def arg_type a
48
+ if a[0].start_with?('**')
49
+ :kwrestarg
50
+ elsif a[0].start_with?('*')
51
+ :restarg
52
+ elsif a[0].start_with?('&')
53
+ :blockarg
54
+ elsif a[1]
55
+ :optarg
56
+ elsif a[0].end_with?(':')
57
+ a[1] ? :kwarg : :kwoptarg
58
+ else
59
+ :arg
43
60
  end
44
- args
45
61
  end
46
62
  end
47
63
  end