solargraph 0.32.5 → 0.33.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/README.md +2 -11
  4. data/lib/solargraph.rb +1 -2
  5. data/lib/solargraph/api_map.rb +93 -63
  6. data/lib/solargraph/api_map/cache.rb +16 -1
  7. data/lib/solargraph/api_map/source_to_yard.rb +16 -7
  8. data/lib/solargraph/api_map/store.rb +55 -12
  9. data/lib/solargraph/complex_type.rb +58 -14
  10. data/lib/solargraph/complex_type/type_methods.rb +2 -2
  11. data/lib/solargraph/complex_type/unique_type.rb +33 -4
  12. data/lib/solargraph/core_fills.rb +40 -12
  13. data/lib/solargraph/diagnostics.rb +4 -3
  14. data/lib/solargraph/diagnostics/base.rb +6 -0
  15. data/lib/solargraph/diagnostics/require_not_found.rb +17 -10
  16. data/lib/solargraph/diagnostics/rubocop_helpers.rb +2 -0
  17. data/lib/solargraph/diagnostics/type_check.rb +51 -0
  18. data/lib/solargraph/diagnostics/update_errors.rb +1 -0
  19. data/lib/solargraph/language_server/host.rb +55 -25
  20. data/lib/solargraph/language_server/host/diagnoser.rb +1 -2
  21. data/lib/solargraph/language_server/host/dispatch.rb +4 -8
  22. data/lib/solargraph/language_server/host/sources.rb +1 -1
  23. data/lib/solargraph/language_server/message.rb +1 -0
  24. data/lib/solargraph/language_server/message/completion_item/resolve.rb +4 -2
  25. data/lib/solargraph/language_server/message/initialize.rb +9 -0
  26. data/lib/solargraph/language_server/message/initialized.rb +1 -0
  27. data/lib/solargraph/language_server/message/text_document.rb +1 -0
  28. data/lib/solargraph/language_server/message/text_document/code_action.rb +15 -0
  29. data/lib/solargraph/language_server/message/text_document/completion.rb +1 -1
  30. data/lib/solargraph/language_server/message/text_document/definition.rb +25 -5
  31. data/lib/solargraph/language_server/message/text_document/hover.rb +1 -1
  32. data/lib/solargraph/language_server/message/text_document/signature_help.rb +4 -0
  33. data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +8 -4
  34. data/lib/solargraph/language_server/transport/adapter.rb +12 -15
  35. data/lib/solargraph/library.rb +23 -6
  36. data/lib/solargraph/location.rb +4 -0
  37. data/lib/solargraph/pin.rb +7 -3
  38. data/lib/solargraph/pin/attribute.rb +14 -13
  39. data/lib/solargraph/pin/base.rb +56 -43
  40. data/lib/solargraph/pin/base_method.rb +41 -18
  41. data/lib/solargraph/pin/base_variable.rb +17 -15
  42. data/lib/solargraph/pin/block.rb +22 -4
  43. data/lib/solargraph/pin/closure.rb +28 -0
  44. data/lib/solargraph/pin/common.rb +59 -0
  45. data/lib/solargraph/pin/constant.rb +4 -4
  46. data/lib/solargraph/pin/conversions.rb +8 -8
  47. data/lib/solargraph/pin/duck_method.rb +3 -3
  48. data/lib/solargraph/pin/instance_variable.rb +30 -0
  49. data/lib/solargraph/pin/keyword.rb +1 -1
  50. data/lib/solargraph/pin/local_variable.rb +3 -3
  51. data/lib/solargraph/pin/localized.rb +9 -5
  52. data/lib/solargraph/pin/method.rb +26 -40
  53. data/lib/solargraph/pin/method_alias.rb +9 -6
  54. data/lib/solargraph/pin/namespace.rb +33 -10
  55. data/lib/solargraph/pin/parameter.rb +150 -0
  56. data/lib/solargraph/pin/proxy_type.rb +8 -8
  57. data/lib/solargraph/pin/reference.rb +1 -12
  58. data/lib/solargraph/pin/reference/override.rb +18 -0
  59. data/lib/solargraph/pin/reference/require.rb +2 -1
  60. data/lib/solargraph/pin/singleton.rb +9 -0
  61. data/lib/solargraph/pin/symbol.rb +9 -4
  62. data/lib/solargraph/pin/yard_pin/constant.rb +12 -3
  63. data/lib/solargraph/pin/yard_pin/method.rb +18 -6
  64. data/lib/solargraph/pin/yard_pin/namespace.rb +13 -1
  65. data/lib/solargraph/position.rb +1 -1
  66. data/lib/solargraph/range.rb +4 -0
  67. data/lib/solargraph/shell.rb +83 -4
  68. data/lib/solargraph/source.rb +32 -12
  69. data/lib/solargraph/source/chain.rb +48 -28
  70. data/lib/solargraph/source/chain/call.rb +37 -38
  71. data/lib/solargraph/source/chain/constant.rb +1 -1
  72. data/lib/solargraph/source/chain/head.rb +2 -8
  73. data/lib/solargraph/source/chain/instance_variable.rb +1 -1
  74. data/lib/solargraph/source/chain/link.rb +2 -0
  75. data/lib/solargraph/source/cursor.rb +59 -24
  76. data/lib/solargraph/source/node_chainer.rb +0 -2
  77. data/lib/solargraph/source/node_methods.rb +12 -6
  78. data/lib/solargraph/source/source_chainer.rb +38 -44
  79. data/lib/solargraph/source_map.rb +11 -18
  80. data/lib/solargraph/source_map/clip.rb +13 -15
  81. data/lib/solargraph/source_map/mapper.rb +37 -26
  82. data/lib/solargraph/source_map/node_processor.rb +13 -8
  83. data/lib/solargraph/source_map/node_processor/alias_node.rb +8 -8
  84. data/lib/solargraph/source_map/node_processor/args_node.rb +10 -16
  85. data/lib/solargraph/source_map/node_processor/base.rb +47 -4
  86. data/lib/solargraph/source_map/node_processor/block_node.rb +9 -4
  87. data/lib/solargraph/source_map/node_processor/casgn_node.rb +7 -2
  88. data/lib/solargraph/source_map/node_processor/cvasgn_node.rb +8 -3
  89. data/lib/solargraph/source_map/node_processor/def_node.rb +45 -38
  90. data/lib/solargraph/source_map/node_processor/defs_node.rb +16 -6
  91. data/lib/solargraph/source_map/node_processor/gvasgn_node.rb +8 -1
  92. data/lib/solargraph/source_map/node_processor/ivasgn_node.rb +20 -6
  93. data/lib/solargraph/source_map/node_processor/lvasgn_node.rb +10 -4
  94. data/lib/solargraph/source_map/node_processor/namespace_node.rb +18 -12
  95. data/lib/solargraph/source_map/node_processor/orasgn_node.rb +1 -1
  96. data/lib/solargraph/source_map/node_processor/resbody_node.rb +30 -0
  97. data/lib/solargraph/source_map/node_processor/sclass_node.rb +7 -1
  98. data/lib/solargraph/source_map/node_processor/send_node.rb +102 -52
  99. data/lib/solargraph/source_map/node_processor/sym_node.rb +4 -1
  100. data/lib/solargraph/source_map/region.rb +9 -8
  101. data/lib/solargraph/type_checker.rb +282 -0
  102. data/lib/solargraph/type_checker/param_def.rb +47 -0
  103. data/lib/solargraph/type_checker/problem.rb +25 -0
  104. data/lib/solargraph/version.rb +1 -1
  105. data/lib/solargraph/views/environment.erb +1 -1
  106. data/lib/solargraph/workspace.rb +2 -2
  107. data/lib/solargraph/workspace/config.rb +0 -8
  108. data/lib/solargraph/yard_map.rb +25 -69
  109. data/lib/solargraph/yard_map/core_docs.rb +8 -3
  110. data/lib/solargraph/yard_map/core_gen.rb +1 -3
  111. data/lib/solargraph/yard_map/mapper.rb +85 -0
  112. data/lib/yard-solargraph.rb +2 -0
  113. metadata +14 -14
  114. data/lib/solargraph/diagnostics/type_not_defined.rb +0 -108
  115. data/lib/solargraph/live_map.rb +0 -126
  116. data/lib/solargraph/live_map/cache.rb +0 -38
  117. data/lib/solargraph/pin/block_parameter.rb +0 -103
  118. data/lib/solargraph/pin/method_parameter.rb +0 -40
  119. data/lib/solargraph/pin/plugin/method.rb +0 -25
  120. data/lib/solargraph/plugin.rb +0 -8
  121. data/lib/solargraph/plugin/base.rb +0 -41
  122. data/lib/solargraph/plugin/canceler.rb +0 -11
  123. data/lib/solargraph/plugin/process.rb +0 -172
  124. data/lib/solargraph/plugin/runtime.rb +0 -134
  125. data/lib/yard-coregen.rb +0 -16
@@ -44,20 +44,6 @@ module Solargraph
44
44
  @requires ||= pins.select{|p| p.kind == Pin::REQUIRE_REFERENCE}
45
45
  end
46
46
 
47
- # @param position [Position, Array(Integer, Integer)]
48
- # @return [Boolean]
49
- def string_at? position
50
- position = Position.normalize(position)
51
- @source.string_at?(position)
52
- end
53
-
54
- # @param position [Position, Array(Integer, Integer)]
55
- # @return [Boolean]
56
- def comment_at? position
57
- position = Position.normalize(position)
58
- @source.comment_at?(position)
59
- end
60
-
61
47
  # @return [Array<Pin::Base>]
62
48
  def document_symbols
63
49
  @document_symbols ||= pins.select { |pin|
@@ -72,7 +58,7 @@ module Solargraph
72
58
  end
73
59
 
74
60
  # @param position [Position]
75
- # @return [Solargraph::SourceMap::Fragment]
61
+ # @return [Source::Cursor]
76
62
  def cursor_at position
77
63
  Source::Cursor.new(source, position)
78
64
  end
@@ -87,7 +73,7 @@ module Solargraph
87
73
  # @return [Array<Solargraph::Pin::Base>]
88
74
  def locate_pins location
89
75
  # return nil unless location.start_with?("#{filename}:")
90
- pins.select { |pin| pin.location == location }
76
+ (pins + locals).select { |pin| pin.location == location }
91
77
  end
92
78
 
93
79
  def locate_named_path_pin line, character
@@ -118,6 +104,13 @@ module Solargraph
118
104
  source.references name
119
105
  end
120
106
 
107
+ # @param location [Location]
108
+ # @return [Array<Pin::LocalVariable>]
109
+ def locals_at(location)
110
+ return [] if location.filename != filename
111
+ locals.select { |pin| pin.visible_at?(location) }
112
+ end
113
+
121
114
  class << self
122
115
  # @param filename [String]
123
116
  # @return [SourceMap]
@@ -146,7 +139,7 @@ module Solargraph
146
139
 
147
140
  # @param line [Integer]
148
141
  # @param character [Integer]
149
- # @param *kinds [Array<Symbol>]
142
+ # @param kinds [Array<Symbol>]
150
143
  # @return [Pin::Base]
151
144
  def _locate_pin line, character, *kinds
152
145
  position = Position.new(line, character)
@@ -155,7 +148,7 @@ module Solargraph
155
148
  found = pin if (kinds.empty? || kinds.include?(pin.kind)) && pin.location.range.contain?(position)
156
149
  break if pin.location.range.start.line > line
157
150
  end
158
- # @todo Assuming the root pin is always valid
151
+ # Assuming the root pin is always valid
159
152
  found || pins.first
160
153
  end
161
154
 
@@ -14,13 +14,14 @@ module Solargraph
14
14
  # @return [Array<Pin::Base>]
15
15
  def define
16
16
  return [] if cursor.comment? || cursor.chain.literal?
17
- result = cursor.chain.define(api_map, context_pin, locals)
17
+ result = cursor.chain.define(api_map, block, locals)
18
18
  result.concat((source_map.pins + source_map.locals).select{ |p| p.name == cursor.word && p.location.range.contain?(cursor.position) }) if result.empty?
19
19
  result
20
20
  end
21
21
 
22
22
  # @return [Completion]
23
23
  def complete
24
+ return package_completions([]) if !source_map.source.parsed? || cursor.string?
24
25
  return package_completions(api_map.get_symbols) if cursor.chain.literal? && cursor.chain.links.last.word == '<Symbol>'
25
26
  return Completion.new([], cursor.range) if cursor.chain.literal? || cursor.comment?
26
27
  result = []
@@ -37,21 +38,21 @@ module Solargraph
37
38
  type = ComplexType::UNDEFINED
38
39
  end
39
40
  end
40
- result.concat api_map.get_constants(type.undefined? ? '' : type.namespace, cursor.start_of_constant? ? '' : context_pin.context.namespace)
41
+ result.concat api_map.get_constants(type.undefined? ? '' : type.namespace, cursor.start_of_constant? ? '' : context_pin.full_context.namespace)
41
42
  else
42
- type = cursor.chain.base.infer(api_map, context_pin, locals)
43
- result.concat api_map.get_complex_type_methods(type, context_pin.context.namespace, cursor.chain.links.length == 1)
43
+ type = cursor.chain.base.infer(api_map, block, locals)
44
+ result.concat api_map.get_complex_type_methods(type, block.binder.namespace, cursor.chain.links.length == 1)
44
45
  if cursor.chain.links.length == 1
45
46
  if cursor.word.start_with?('@@')
46
- return package_completions(api_map.get_class_variable_pins(context_pin.context.namespace))
47
+ return package_completions(api_map.get_class_variable_pins(context_pin.full_context.namespace))
47
48
  elsif cursor.word.start_with?('@')
48
- return package_completions(api_map.get_instance_variable_pins(context_pin.context.namespace, context_pin.context.scope))
49
+ return package_completions(api_map.get_instance_variable_pins(block.binder.namespace, block.binder.scope))
49
50
  elsif cursor.word.start_with?('$')
50
51
  return package_completions(api_map.get_global_variable_pins)
51
52
  end
52
53
  result.concat locals
53
54
  result.concat api_map.get_constants('', context_pin.context.namespace)
54
- result.concat api_map.get_methods(context_pin.context.namespace, scope: context_pin.context.scope, visibility: [:public, :private, :protected])
55
+ result.concat api_map.get_methods(block.binder.namespace, scope: block.binder.scope, visibility: [:public, :private, :protected])
55
56
  result.concat api_map.get_methods('Kernel')
56
57
  result.concat ApiMap.keywords
57
58
  result.concat yielded_self_pins
@@ -63,13 +64,15 @@ module Solargraph
63
64
  # @return [Array<Pin::Base>]
64
65
  def signify
65
66
  return [] unless cursor.argument?
66
- clip = Clip.new(api_map, cursor.recipient)
67
- clip.define.select{|pin| pin.kind == Pin::METHOD}
67
+ chain = Source::NodeChainer.chain(cursor.recipient_node, cursor.filename)
68
+ chain.define(api_map, context_pin, locals).select { |pin| pin.is_a?(Pin::Method) }
68
69
  end
69
70
 
70
71
  # @return [ComplexType]
71
72
  def infer
72
- cursor.chain.infer(api_map, context_pin, locals)
73
+ result = cursor.chain.infer(api_map, block, locals)
74
+ return result unless result.tag == 'self'
75
+ ComplexType.try_parse(cursor.chain.base.infer(api_map, block, locals).namespace)
73
76
  end
74
77
 
75
78
  # Get an array of all the locals that are visible from the cursors's
@@ -117,11 +120,6 @@ module Solargraph
117
120
  receiver_pin = chain.define(api_map, context_pin, locals).first
118
121
  return [] if receiver_pin.nil?
119
122
  result = []
120
- ys = receiver_pin.docstring.tag(:yieldself)
121
- unless ys.nil? || ys.types.empty?
122
- ysct = ComplexType.try_parse(*ys.types).qualify(api_map, receiver_pin.context.namespace)
123
- result.concat api_map.get_complex_type_methods(ysct, ysct.namespace, true)
124
- end
125
123
  ys = receiver_pin.docstring.tag(:yieldpublic)
126
124
  unless ys.nil? || ys.types.empty?
127
125
  ysct = ComplexType.try_parse(*ys.types).qualify(api_map, receiver_pin.context.namespace)
@@ -21,13 +21,12 @@ module Solargraph
21
21
  @filename = source.filename
22
22
  @code = source.code
23
23
  @comments = source.comments
24
- @pins = NodeProcessor.process(source.node, Region.new(source: source))
24
+ @pins, @locals = NodeProcessor.process(source.node, Region.new(source: source))
25
25
  process_comment_directives
26
- locals = @pins.select{|p| [Pin::LocalVariable, Pin::MethodParameter, Pin::BlockParameter].include?(p.class)}
27
- [@pins - locals, locals]
26
+ [@pins, @locals]
28
27
  rescue Exception => e
29
28
  Solargraph.logger.warn "Error mapping #{source.filename}: [#{e.class}] #{e.message}"
30
- Solargraph.logger.warn e.backtrace
29
+ Solargraph.logger.warn e.backtrace.join("\n")
31
30
  [[], []]
32
31
  end
33
32
 
@@ -35,7 +34,7 @@ module Solargraph
35
34
  s = Position.new(0, 0)
36
35
  e = Position.from_offset(code, code.length)
37
36
  location = Location.new(filename, Range.new(s, e))
38
- [[Pin::Namespace.new(location, '', '', '', :class, :public)], []]
37
+ [[Pin::Namespace.new(location: location, name: '')], []]
39
38
  end
40
39
 
41
40
  class << self
@@ -52,15 +51,8 @@ module Solargraph
52
51
  @pins ||= []
53
52
  end
54
53
 
55
- # @param node [Parser::AST::Node]
56
- # @return [Solargraph::Pin::Namespace]
57
- def namespace_for(node)
58
- position = Position.new(node.loc.line, node.loc.column)
59
- namespace_at(position)
60
- end
61
-
62
- def namespace_at(position)
63
- @pins.select{|pin| pin.kind == Pin::NAMESPACE and pin.location.range.contain?(position)}.last
54
+ def closure_at(position)
55
+ @pins.select{|pin| pin.is_a?(Pin::Closure) and pin.location.range.contain?(position)}.last
64
56
  end
65
57
 
66
58
  def process_comment source_position, comment_position, comment
@@ -77,25 +69,42 @@ module Solargraph
77
69
  location = Location.new(@filename, Range.new(comment_position, comment_position))
78
70
  case directive.tag.tag_name
79
71
  when 'method'
80
- namespace = namespace_at(source_position)
81
- gen_src = Solargraph::SourceMap.load_string("def #{directive.tag.name};end")
82
- gen_pin = gen_src.pins.select{ |p| p.kind == Pin::METHOD }.first
72
+ namespace = closure_at(source_position)
73
+ region = Region.new(source: @source, closure: namespace)
74
+ src_node = Solargraph::Source.parse("def #{directive.tag.name};end", @filename, location.range.start.line)
75
+ gen_pin = Solargraph::SourceMap::NodeProcessor.process(src_node, region).first.last
83
76
  return if gen_pin.nil?
84
- @pins.push Solargraph::Pin::Method.new(location, namespace.path, gen_pin.name, docstring.all, :instance, :public, gen_pin.parameters, nil)
77
+ # @todo: Smelly instance variable access
78
+ gen_pin.instance_variable_set(:@comments, docstring.all)
79
+ @pins.push gen_pin
85
80
  when 'attribute'
86
- namespace = namespace_at(source_position)
81
+ namespace = closure_at(source_position)
87
82
  t = (directive.tag.types.nil? || directive.tag.types.empty?) ? nil : directive.tag.types.flatten.join('')
88
83
  if t.nil? || t.include?('r')
89
- # location, namespace, name, docstring, access
90
- pins.push Solargraph::Pin::Attribute.new(location, namespace.path, directive.tag.name, docstring.all, :reader, :instance, :public)
84
+ pins.push Solargraph::Pin::Attribute.new(
85
+ location: location,
86
+ closure: namespace,
87
+ name: directive.tag.name,
88
+ comments: docstring.all,
89
+ access: :reader,
90
+ scope: namespace.is_a?(Pin::Singleton) ? :class : :instance,
91
+ visibility: :public
92
+ )
91
93
  end
92
94
  if t.nil? || t.include?('w')
93
- pins.push Solargraph::Pin::Attribute.new(location, namespace.path, "#{directive.tag.name}=", docstring.all, :writer, :instance, :public)
95
+ pins.push Solargraph::Pin::Attribute.new(
96
+ location: location,
97
+ closure: namespace,
98
+ name: "#{directive.tag.name}=",
99
+ comments: docstring.all,
100
+ access: :writer,
101
+ scope: namespace.is_a?(Pin::Singleton) ? :class : :instance,
102
+ visibility: :public
103
+ )
94
104
  end
95
105
  when 'parse'
96
- # @todo Parse and map directive.tag.text
97
- ns = namespace_at(comment_position)
98
- region = Region.new(source: @source, namespace: ns.path)
106
+ ns = closure_at(source_position)
107
+ region = Region.new(source: @source, closure: ns)
99
108
  begin
100
109
  node = Solargraph::Source.parse(directive.tag.text, @filename, comment_position.line)
101
110
  NodeProcessor.process(node, region, @pins)
@@ -103,8 +112,10 @@ module Solargraph
103
112
  # @todo Handle parser errors in !parse directives
104
113
  end
105
114
  when 'domain'
106
- namespace = namespace_at(source_position)
115
+ namespace = closure_at(source_position)
107
116
  namespace.domains.concat directive.tag.types unless directive.tag.types.nil?
117
+ when 'override'
118
+ pins.push Pin::Reference::Override.new(location, directive.tag.name, docstring.tags)
108
119
  end
109
120
  end
110
121
 
@@ -22,6 +22,7 @@ module Solargraph
22
22
  autoload :BlockNode, 'solargraph/source_map/node_processor/block_node'
23
23
  autoload :OrasgnNode, 'solargraph/source_map/node_processor/orasgn_node'
24
24
  autoload :SymNode, 'solargraph/source_map/node_processor/sym_node'
25
+ autoload :ResbodyNode, 'solargraph/source_map/node_processor/resbody_node'
25
26
 
26
27
  class << self
27
28
  @@processors ||= {}
@@ -41,9 +42,8 @@ module Solargraph
41
42
  register :source, BeginNode
42
43
  register :begin, BeginNode
43
44
  register :kwbegin, BeginNode
44
- # # @todo Is this the best way to handle rescue nodes?
45
45
  register :rescue, BeginNode
46
- register :resbody, BeginNode
46
+ register :resbody, ResbodyNode
47
47
  register :def, DefNode
48
48
  register :defs, DefsNode
49
49
  register :send, SendNode
@@ -64,14 +64,19 @@ module Solargraph
64
64
  # @param node [Parser::AST::Node]
65
65
  # @param region [Region]
66
66
  # @param pins [Array<Pin::Base>]
67
- # @return [Array<Pin::Base>]
68
- def self.process node, region = Region.new(nil, '', :instance, :public, []), pins = []
69
- pins.push Pin::Namespace.new(region.source.location, '', '', nil, :class, :public) if pins.empty?
70
- return pins unless node.is_a?(Parser::AST::Node) #&& @@processors.key?(node.type)
67
+ # @return [Array(Array<Pin::Base>, Array<Pin::Base>)]
68
+ def self.process node, region = Region.new, pins = [], locals = []
69
+ if pins.empty?
70
+ pins.push Pin::Namespace.new(
71
+ location: region.source.location,
72
+ name: ''
73
+ )
74
+ end
75
+ return [pins, locals] unless node.is_a?(Parser::AST::Node)
71
76
  klass = @@processors[node.type] || BeginNode
72
- processor = klass.new(node, region, pins)
77
+ processor = klass.new(node, region, pins, locals)
73
78
  processor.process
74
- processor.pins
79
+ [processor.pins, processor.locals]
75
80
  end
76
81
  end
77
82
  end
@@ -3,14 +3,14 @@ module Solargraph
3
3
  module NodeProcessor
4
4
  class AliasNode < Base
5
5
  def process
6
- pin = pins.select{|p| [Solargraph::Pin::Method, Solargraph::Pin::Attribute].include?(p.class) && p.name == node.children[1].children[0].to_s && p.namespace == region.namespace && p.scope == region.scope}.first
7
- if pin.nil?
8
- pins.push Solargraph::Pin::MethodAlias.new(get_node_location(node), region.namespace, node.children[0].children[0].to_s, region.scope, node.children[1].children[0].to_s)
9
- elsif pin.is_a?(Solargraph::Pin::Method)
10
- pins.push Solargraph::Pin::Method.new(get_node_location(node), pin.namespace, node.children[0].children[0].to_s, comments_for(node) || pin.comments, pin.scope, pin.visibility, pin.parameters, pin.node)
11
- elsif pin.is_a?(Solargraph::Pin::Attribute)
12
- pins.push Solargraph::Pin::Attribute.new(get_node_location(node), pin.namespace, node.children[0].children[0].to_s, comments_for(node) || pin.comments, pin.access, pin.scope, pin.visibility)
13
- end
6
+ loc = get_node_location(node)
7
+ pins.push Solargraph::Pin::MethodAlias.new(
8
+ location: loc,
9
+ closure: region.closure,
10
+ name: node.children[0].children[0].to_s,
11
+ original: node.children[1].children[0].to_s,
12
+ scope: region.scope || :instance
13
+ )
14
14
  process_children
15
15
  end
16
16
  end
@@ -3,22 +3,16 @@ module Solargraph
3
3
  module NodeProcessor
4
4
  class ArgsNode < Base
5
5
  def process
6
- return if node.children.empty?
7
- here = get_node_start_position(node)
8
- context = named_path_pin(here)
9
- block = block_pin(here)
10
- if block.kind == Solargraph::Pin::BLOCK
11
- pi = 0
12
- node.children.each do |u|
13
- pins.push Solargraph::Pin::BlockParameter.new(get_node_location(u), region.namespace, "#{u.children[0]}", comments_for(node), block)
14
- block.parameters.push pins.last
15
- pi += 1
16
- end
17
- else
18
- node.children.each do |u|
19
- presence = Range.new(here, block.location.range.ending)
20
- pins.push Solargraph::Pin::MethodParameter.new(get_node_location(u), region.namespace, u.children[0].to_s, comments_for(node), u.children[1], infer_literal_node_type(u.children[1]), context, block, presence)
21
- end
6
+ node.children.each do |u|
7
+ loc = get_node_location(u)
8
+ locals.push Solargraph::Pin::Parameter.new(
9
+ location: loc,
10
+ closure: region.closure,
11
+ comments: comments_for(node),
12
+ name: u.children[0].to_s,
13
+ assignment: u.children[1],
14
+ presence: region.closure.location.range
15
+ )
22
16
  end
23
17
  process_children
24
18
  end
@@ -13,13 +13,17 @@ module Solargraph
13
13
  # @return [Array<Pin::Base>]
14
14
  attr_reader :pins
15
15
 
16
+ # @return [Array<Pin::Base>]
17
+ attr_reader :locals
18
+
16
19
  # @param node [Parser::AST::Node]
17
20
  # @param region [Region]
18
21
  # @param pins [Array<Pin::Base>]
19
- def initialize node, region, pins
22
+ def initialize node, region, pins, locals
20
23
  @node = node
21
24
  @region = region
22
25
  @pins = pins
26
+ @locals = locals
23
27
  end
24
28
 
25
29
  protected
@@ -38,7 +42,7 @@ module Solargraph
38
42
  def process_children subregion = region
39
43
  node.children.each do |child|
40
44
  next unless child.is_a?(Parser::AST::Node)
41
- NodeProcessor.process(child, subregion, pins)
45
+ NodeProcessor.process(child, subregion, pins, locals)
42
46
  end
43
47
  end
44
48
 
@@ -56,11 +60,50 @@ module Solargraph
56
60
  end
57
61
 
58
62
  def named_path_pin position
59
- pins.select{|pin| [Pin::NAMESPACE, Pin::METHOD].include?(pin.kind) and pin.location.range.contain?(position)}.last
63
+ pins.select{|pin| [Pin::NAMESPACE, Pin::METHOD].include?(pin.kind) && pin.location.range.contain?(position)}.last
60
64
  end
61
65
 
66
+ # @todo Candidate for deprecation
62
67
  def block_pin position
63
- pins.select{|pin| [Pin::BLOCK, Pin::NAMESPACE, Pin::METHOD].include?(pin.kind) and pin.location.range.contain?(position)}.last
68
+ pins.select{|pin| [Pin::BLOCK, Pin::NAMESPACE, Pin::METHOD].include?(pin.kind) && pin.location.range.contain?(position)}.last
69
+ end
70
+
71
+ # @todo Candidate for deprecation
72
+ def closure_pin position
73
+ pins.select{|pin| pin.is_a?(Pin::Closure) && pin.location.range.contain?(position)}.last
74
+ end
75
+
76
+ private
77
+
78
+ def method_args
79
+ return [] if node.nil?
80
+ list = nil
81
+ args = []
82
+ node.children.each { |c|
83
+ if c.kind_of?(AST::Node) and c.type == :args
84
+ list = c
85
+ break
86
+ end
87
+ }
88
+ return args if list.nil?
89
+ list.children.each { |c|
90
+ if c.type == :arg
91
+ args.push c.children[0].to_s
92
+ elsif c.type == :restarg
93
+ args.push "*#{c.children[0]}"
94
+ elsif c.type == :optarg
95
+ args.push "#{c.children[0]} = #{region.code_for(c.children[1])}"
96
+ elsif c.type == :kwarg
97
+ args.push "#{c.children[0]}:"
98
+ elsif c.type == :kwoptarg
99
+ args.push "#{c.children[0]}: #{region.code_for(c.children[1])}"
100
+ elsif c.type == :kwrestarg
101
+ args.push "**#{c.children[0]}"
102
+ elsif c.type == :blockarg
103
+ args.push "&#{c.children[0]}"
104
+ end
105
+ }
106
+ args
64
107
  end
65
108
  end
66
109
  end
@@ -3,10 +3,15 @@ module Solargraph
3
3
  module NodeProcessor
4
4
  class BlockNode < Base
5
5
  def process
6
- here = get_node_start_position(node)
7
- named_path = named_path_pin(here)
8
- pins.push Solargraph::Pin::Block.new(get_node_location(node), region.namespace, '', comments_for(node), node.children[0], named_path.context)
9
- process_children
6
+ pins.push Solargraph::Pin::Block.new(
7
+ location: get_node_location(node),
8
+ closure: region.closure,
9
+ receiver: node.children[0],
10
+ comments: comments_for(node),
11
+ scope: region.scope || region.closure.context.scope,
12
+ args: method_args
13
+ )
14
+ process_children region.update(closure: pins.last)
10
15
  end
11
16
  end
12
17
  end