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
@@ -4,8 +4,13 @@ module Solargraph
4
4
  class CasgnNode < Base
5
5
  def process
6
6
  here = get_node_start_position(node)
7
- block = block_pin(here)
8
- pins.push Solargraph::Pin::Constant.new(get_node_location(node), region.namespace, node.children[1].to_s, comments_for(node), node.children[2], infer_literal_node_type(node.children[2]), block.context, :public)
7
+ pins.push Solargraph::Pin::Constant.new(
8
+ location: get_node_location(node),
9
+ closure: region.closure,
10
+ name: node.children[1].to_s,
11
+ comments: comments_for(node),
12
+ assignment: node.children[2]
13
+ )
9
14
  process_children
10
15
  end
11
16
  end
@@ -3,9 +3,14 @@ module Solargraph
3
3
  module NodeProcessor
4
4
  class CvasgnNode < Base
5
5
  def process
6
- here = get_node_start_position(node)
7
- context = named_path_pin(here)
8
- pins.push Solargraph::Pin::ClassVariable.new(get_node_location(node), region.namespace, node.children[0].to_s, comments_for(node), node.children[1], infer_literal_node_type(node.children[1]), context.context)
6
+ loc = get_node_location(node)
7
+ pins.push Solargraph::Pin::ClassVariable.new(
8
+ location: loc,
9
+ closure: region.closure,
10
+ name: node.children[0].to_s,
11
+ comments: comments_for(node),
12
+ assignment: node.children[1]
13
+ )
9
14
  process_children
10
15
  end
11
16
  end
@@ -3,50 +3,57 @@ module Solargraph
3
3
  module NodeProcessor
4
4
  class DefNode < Base
5
5
  def process
6
- methpin = Solargraph::Pin::Method.new(get_node_location(node), region.namespace, node.children[0].to_s, comments_for(node), region.scope, region.visibility, method_args, node)
6
+ loc = get_node_location(node)
7
+ methpin = Solargraph::Pin::Method.new(
8
+ location: get_node_location(node),
9
+ closure: region.closure,
10
+ name: node.children[0].to_s,
11
+ comments: comments_for(node),
12
+ scope: region.scope || (region.closure.is_a?(Pin::Singleton) ? :class : :instance),
13
+ visibility: region.visibility,
14
+ args: method_args,
15
+ node: node
16
+ )
7
17
  if methpin.name == 'initialize' and methpin.scope == :instance
8
- pins.push Solargraph::Pin::Method.new(methpin.location, methpin.namespace, 'new', methpin.comments, :class, :public, methpin.parameters, nil)
18
+ pins.push Solargraph::Pin::Method.new(
19
+ location: methpin.location,
20
+ closure: methpin.closure,
21
+ name: 'new',
22
+ comments: methpin.comments,
23
+ scope: :class,
24
+ args: methpin.parameters
25
+ )
9
26
  # @todo Smelly instance variable access.
10
- pins.last.instance_variable_set(:@return_complex_type, ComplexType.try_parse(methpin.namespace))
11
- pins.push Solargraph::Pin::Method.new(methpin.location, methpin.namespace, methpin.name, methpin.comments, methpin.scope, :private, methpin.parameters, methpin.node)
27
+ pins.last.instance_variable_set(:@return_type, ComplexType::SELF)
28
+ pins.push methpin
29
+ # @todo Smelly instance variable access.
30
+ methpin.instance_variable_set(:@visibility, :private)
31
+ methpin.instance_variable_set(:@return_type, ComplexType::VOID)
12
32
  elsif region.visibility == :module_function
13
- pins.push Solargraph::Pin::Method.new(methpin.location, methpin.namespace, methpin.name, methpin.comments, :class, :public, methpin.parameters, methpin.node)
14
- pins.push Solargraph::Pin::Method.new(methpin.location, methpin.namespace, methpin.name, methpin.comments, :instance, :private, methpin.parameters, methpin.node)
33
+ pins.push Solargraph::Pin::Method.new(
34
+ location: methpin.location,
35
+ closure: methpin.closure,
36
+ name: methpin.name,
37
+ comments: methpin.comments,
38
+ scope: :class,
39
+ visibility: :public,
40
+ args: methpin.parameters,
41
+ node: methpin.node
42
+ )
43
+ pins.push Solargraph::Pin::Method.new(
44
+ location: methpin.location,
45
+ closure: methpin.closure,
46
+ name: methpin.name,
47
+ comments: methpin.comments,
48
+ scope: :instance,
49
+ visibility: :private,
50
+ args: methpin.parameters,
51
+ node: methpin.node
52
+ )
15
53
  else
16
54
  pins.push methpin
17
55
  end
18
- process_children
19
- end
20
-
21
- private
22
-
23
- def method_args
24
- return [] if node.nil?
25
- list = nil
26
- args = []
27
- node.children.each { |c|
28
- if c.kind_of?(AST::Node) and c.type == :args
29
- list = c
30
- break
31
- end
32
- }
33
- return args if list.nil?
34
- list.children.each { |c|
35
- if c.type == :arg
36
- args.push c.children[0].to_s
37
- elsif c.type == :restarg
38
- args.push "*#{c.children[0]}"
39
- elsif c.type == :optarg
40
- args.push "#{c.children[0]} = #{region.code_for(c.children[1])}"
41
- elsif c.type == :kwarg
42
- args.push "#{c.children[0]}:"
43
- elsif c.type == :kwoptarg
44
- args.push "#{c.children[0]}: #{region.code_for(c.children[1])}"
45
- elsif c.type == :blockarg
46
- args.push "&#{c.children[0]}"
47
- end
48
- }
49
- args
56
+ process_children region.update(closure: methpin, scope: methpin.scope)
50
57
  end
51
58
  end
52
59
  end
@@ -5,15 +5,25 @@ module Solargraph
5
5
  def process
6
6
  s_visi = region.visibility
7
7
  s_visi = :public if s_visi == :module_function || region.scope != :class
8
+ loc = get_node_location(node)
8
9
  if node.children[0].is_a?(AST::Node) && node.children[0].type == :self
9
- dfqn = region.namespace
10
+ closure = region.closure
10
11
  else
11
- dfqn = unpack_name(node.children[0])
12
- end
13
- unless dfqn.nil?
14
- pins.push Solargraph::Pin::Method.new(get_node_location(node), dfqn, "#{node.children[1]}", comments_for(node), :class, s_visi, method_args, node)
15
- process_children region.update(namespace: dfqn)
12
+ closure = Solargraph::Pin::Namespace.new(
13
+ name: unpack_name(node.children[0])
14
+ )
16
15
  end
16
+ pins.push Solargraph::Pin::Method.new(
17
+ location: loc,
18
+ closure: closure,
19
+ name: node.children[1].to_s,
20
+ comments: comments_for(node),
21
+ scope: :class,
22
+ visibility: s_visi,
23
+ args: method_args,
24
+ node: node
25
+ )
26
+ process_children region.update(closure: pins.last, scope: :class)
17
27
  end
18
28
  end
19
29
  end
@@ -3,7 +3,14 @@ module Solargraph
3
3
  module NodeProcessor
4
4
  class GvasgnNode < Base
5
5
  def process
6
- pins.push Solargraph::Pin::GlobalVariable.new(get_node_location(node), region.namespace, node.children[0].to_s, comments_for(node), node.children[1], infer_literal_node_type(node.children[1]), pins.first.context)
6
+ loc = get_node_location(node)
7
+ pins.push Solargraph::Pin::GlobalVariable.new(
8
+ location: loc,
9
+ closure: region.closure,
10
+ name: node.children[0].to_s,
11
+ comments: comments_for(node),
12
+ assignment: node.children[1]
13
+ )
7
14
  process_children
8
15
  end
9
16
  end
@@ -3,12 +3,26 @@ module Solargraph
3
3
  module NodeProcessor
4
4
  class IvasgnNode < Base
5
5
  def process
6
- here = get_node_start_position(node)
7
- named_path = named_path_pin(here)
8
- pins.push Solargraph::Pin::InstanceVariable.new(get_node_location(node), region.namespace,node.children[0].to_s, comments_for(node), node.children[1], infer_literal_node_type(node.children[1]), named_path.context)
9
- if region.visibility == :module_function and named_path.kind == Pin::METHOD
10
- other = ComplexType.try_parse("Module<#{named_path.context.namespace}>")
11
- pins.push Solargraph::Pin::InstanceVariable.new(get_node_location(node), region.namespace,node.children[0].to_s, comments_for(node), node.children[1], infer_literal_node_type(node.children[1]), other)
6
+ loc = get_node_location(node)
7
+ pins.push Solargraph::Pin::InstanceVariable.new(
8
+ location: loc,
9
+ closure: region.closure,
10
+ name: node.children[0].to_s,
11
+ comments: comments_for(node),
12
+ assignment: node.children[1]
13
+ )
14
+ if region.visibility == :module_function
15
+ here = get_node_start_position(node)
16
+ named_path = named_path_pin(here)
17
+ if named_path.kind == Pin::METHOD
18
+ pins.push Solargraph::Pin::InstanceVariable.new(
19
+ location: loc,
20
+ closure: Pin::Namespace.new(type: :module, closure: region.closure.closure, name: region.closure.name),
21
+ name: node.children[0].to_s,
22
+ comments: comments_for(node),
23
+ assignment: node.children[1]
24
+ )
25
+ end
12
26
  end
13
27
  process_children
14
28
  end
@@ -4,10 +4,16 @@ module Solargraph
4
4
  class LvasgnNode < Base
5
5
  def process
6
6
  here = get_node_start_position(node)
7
- context = named_path_pin(here)
8
- block = block_pin(here)
9
- presence = Range.new(here, block.location.range.ending)
10
- pins.push Solargraph::Pin::LocalVariable.new(get_node_location(node), region.namespace, node.children[0].to_s, comments_for(node), node.children[1], infer_literal_node_type(node.children[1]), context.context, block, presence)
7
+ presence = Range.new(here, region.closure.location.range.ending)
8
+ loc = get_node_location(node)
9
+ locals.push Solargraph::Pin::LocalVariable.new(
10
+ location: loc,
11
+ closure: region.closure,
12
+ name: node.children[0].to_s,
13
+ assignment: node.children[1],
14
+ comments: comments_for(node),
15
+ presence: presence
16
+ )
11
17
  process_children
12
18
  end
13
19
  end
@@ -3,22 +3,28 @@ module Solargraph
3
3
  module NodeProcessor
4
4
  class NamespaceNode < Base
5
5
  def process
6
- visibility = :public
7
- if node.children[0].kind_of?(AST::Node) and node.children[0].children[0].kind_of?(AST::Node) and node.children[0].children[0].type == :cbase
8
- tree = pack_name(node.children[0])
9
- tree.shift if tree.first.empty?
10
- else
11
- tree = region.namespace.empty? ? [] : [region.namespace]
12
- tree.concat pack_name(node.children[0])
13
- end
14
- fqn = tree.join('::')
15
6
  sc = nil
16
7
  if node.type == :class and !node.children[1].nil?
17
8
  sc = unpack_name(node.children[1])
18
9
  end
19
- pins.push Solargraph::Pin::Namespace.new(get_node_location(node), tree[0..-2].join('::') || '', pack_name(node.children[0]).last.to_s, comments_for(node), node.type, visibility)
20
- pins.push Pin::Reference::Superclass.new(pins.last.location, pins.last.path, sc) unless sc.nil?
21
- process_children region.update(namespace: fqn, scope: :instance, visibility: :public)
10
+ loc = get_node_location(node)
11
+ nspin = Solargraph::Pin::Namespace.new(
12
+ type: node.type,
13
+ location: loc,
14
+ closure: region.closure,
15
+ name: unpack_name(node.children[0]),
16
+ comments: comments_for(node),
17
+ visibility: :public
18
+ )
19
+ pins.push nspin
20
+ unless sc.nil?
21
+ pins.push Pin::Reference::Superclass.new(
22
+ location: loc,
23
+ closure: pins.last,
24
+ name: sc
25
+ )
26
+ end
27
+ process_children region.update(closure: nspin, visibility: :public)
22
28
  end
23
29
  end
24
30
  end
@@ -4,7 +4,7 @@ module Solargraph
4
4
  class OrasgnNode < Base
5
5
  def process
6
6
  new_node = node.updated(node.children[0].type, node.children[0].children + [node.children[1]])
7
- NodeProcessor.process(new_node, region, pins)
7
+ NodeProcessor.process(new_node, region, pins, locals)
8
8
  end
9
9
  end
10
10
  end
@@ -0,0 +1,30 @@
1
+ module Solargraph
2
+ class SourceMap
3
+ module NodeProcessor
4
+ class ResbodyNode < Base
5
+ def process
6
+ if node.children[1]
7
+ here = get_node_start_position(node.children[1])
8
+ presence = Range.new(here, region.closure.location.range.ending)
9
+ loc = get_node_location(node.children[1])
10
+ types = if node.children[0].nil?
11
+ ['Exception']
12
+ else
13
+ node.children[0].children.map do |child|
14
+ unpack_name(child)
15
+ end
16
+ end
17
+ locals.push Solargraph::Pin::LocalVariable.new(
18
+ location: loc,
19
+ closure: region.closure,
20
+ name: node.children[1].children[0].to_s,
21
+ comments: "@type [#{types.join(',')}]",
22
+ presence: presence
23
+ )
24
+ end
25
+ NodeProcessor.process(node.children[2], region, pins, locals)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -3,7 +3,13 @@ module Solargraph
3
3
  module NodeProcessor
4
4
  class SclassNode < Base
5
5
  def process
6
- process_children region.update(visibility: :public, scope: :class)
6
+ # @todo Temporarily skipping remote metaclasses
7
+ return unless node.children[0].is_a?(AST::Node) && node.children[0].type == :self
8
+ pins.push Solargraph::Pin::Singleton.new(
9
+ location: get_node_location(node),
10
+ closure: region.closure
11
+ )
12
+ process_children region.update(visibility: :public, scope: :class, closure: pins.last)
7
13
  end
8
14
  end
9
15
  end
@@ -9,7 +9,7 @@ module Solargraph
9
9
  node.children[2..-1].each do |child|
10
10
  next unless child.is_a?(AST::Node) && (child.type == :sym || child.type == :str)
11
11
  name = child.children[0].to_s
12
- matches = pins.select{ |pin| [Pin::METHOD, Pin::ATTRIBUTE].include?(pin.kind) && pin.name == name && pin.namespace == region.namespace && pin.context.scope == region.scope }
12
+ matches = pins.select{ |pin| [Pin::METHOD, Pin::ATTRIBUTE].include?(pin.kind) && pin.name == name && pin.namespace == region.closure.full_context.namespace && pin.context.scope == (region.scope || :instance)}
13
13
  matches.each do |pin|
14
14
  # @todo Smelly instance variable access
15
15
  pin.instance_variable_set(:@visibility, node.children[1])
@@ -27,7 +27,7 @@ module Solargraph
27
27
  process_include
28
28
  elsif node.children[1] == :extend
29
29
  process_extend
30
- elsif node.children[1] == :require
30
+ elsif node.children[1] == :require
31
31
  process_require
32
32
  elsif node.children[1] == :private_constant
33
33
  process_private_constant
@@ -43,113 +43,163 @@ module Solargraph
43
43
 
44
44
  private
45
45
 
46
+ # @return [void]
46
47
  def process_attribute
47
48
  node.children[2..-1].each do |a|
49
+ loc = get_node_location(node)
50
+ clos = region.closure
51
+ cmnt = comments_for(node)
48
52
  if node.children[1] == :attr_reader || node.children[1] == :attr_accessor
49
- pins.push Solargraph::Pin::Attribute.new(get_node_location(node), region.namespace, "#{a.children[0]}", comments_for(node), :reader, region.scope, region.visibility)
53
+ pins.push Solargraph::Pin::Attribute.new(
54
+ location: loc,
55
+ closure: clos,
56
+ name: a.children[0].to_s,
57
+ comments: cmnt,
58
+ access: :reader,
59
+ scope: region.scope || :instance,
60
+ visibility: region.visibility
61
+ )
50
62
  end
51
63
  if node.children[1] == :attr_writer || node.children[1] == :attr_accessor
52
- pins.push Solargraph::Pin::Attribute.new(get_node_location(node), region.namespace, "#{a.children[0]}=", comments_for(node), :writer, region.scope, region.visibility)
64
+ pins.push Solargraph::Pin::Attribute.new(
65
+ location: loc,
66
+ closure: clos,
67
+ name: "#{a.children[0]}=",
68
+ comments: cmnt,
69
+ access: :writer,
70
+ scope: region.scope || :instance,
71
+ visibility: region.visibility
72
+ )
53
73
  end
54
74
  end
55
75
  end
56
76
 
77
+ # @return [void]
57
78
  def process_include
58
79
  if node.children[2].kind_of?(AST::Node) && node.children[2].type == :const
80
+ cp = region.closure
59
81
  node.children[2..-1].each do |i|
60
- nspin = pins.select{|pin| pin.kind == Pin::NAMESPACE and pin.path == region.namespace}.last
61
- unless nspin.nil?
62
- pins.push Pin::Reference::Include.new(get_node_location(node), nspin.path, unpack_name(i))
63
- end
82
+ pins.push Pin::Reference::Include.new(
83
+ location: get_node_location(i),
84
+ closure: cp,
85
+ name: unpack_name(i)
86
+ )
64
87
  end
65
88
  end
66
89
  end
67
90
 
91
+ # @return [void]
68
92
  def process_extend
69
93
  node.children[2..-1].each do |i|
70
- nspin = pins.select{|pin| pin.kind == Pin::NAMESPACE and pin.path == region.namespace}.last
71
- unless nspin.nil?
72
- ref = nil
73
- if i.type == :self
74
- ref = Pin::Reference::Extend.new(get_node_location(node), nspin.path, nspin.path)
75
- elsif i.type == :const
76
- ref = Pin::Reference::Extend.new(get_node_location(node), nspin.path, unpack_name(i))
77
- end
78
- pins.push ref unless ref.nil?
94
+ loc = get_node_location(node)
95
+ if i.type == :self
96
+ pins.push Pin::Reference::Extend.new(
97
+ location: loc,
98
+ closure: region.closure,
99
+ name: region.closure.full_context.namespace
100
+ )
101
+ else
102
+ pins.push Pin::Reference::Extend.new(
103
+ location: loc,
104
+ closure: region.closure,
105
+ name: unpack_name(i)
106
+ )
79
107
  end
80
108
  end
81
109
  end
82
110
 
111
+ # @return [void]
83
112
  def process_require
84
113
  if node.children[2].kind_of?(AST::Node) && node.children[2].type == :str
85
114
  pins.push Pin::Reference::Require.new(get_node_location(node), node.children[2].children[0].to_s)
86
115
  end
87
116
  end
88
117
 
118
+ # @return [void]
89
119
  def process_module_function
90
120
  if node.children[2].nil?
91
121
  # @todo Smelly instance variable access
92
122
  region.instance_variable_set(:@visibility, :module_function)
93
123
  elsif node.children[2].type == :sym || node.children[2].type == :str
94
- # @todo What to do about references?
95
124
  node.children[2..-1].each do |x|
96
125
  cn = x.children[0].to_s
97
- ref = pins.select{|p| [Solargraph::Pin::Method, Solargraph::Pin::Attribute].include?(p.class) && p.namespace == region.namespace && p.name == cn}.first
126
+ ref = pins.select{|p| [Solargraph::Pin::Method, Solargraph::Pin::Attribute].include?(p.class) && p.namespace == region.closure.full_context.namespace && p.name == cn}.first
98
127
  unless ref.nil?
99
128
  pins.delete ref
100
- mm = Solargraph::Pin::Method.new(ref.location, ref.namespace, ref.name, ref.comments, :class, :public, ref.parameters, ref.node)
101
- cm = Solargraph::Pin::Method.new(ref.location, ref.namespace, ref.name, ref.comments, :instance, :private, ref.parameters, ref.node)
129
+ mm = Solargraph::Pin::Method.new(
130
+ location: ref.location,
131
+ closure: ref.closure,
132
+ name: ref.name,
133
+ comments: ref.comments,
134
+ scope: :class,
135
+ visibility: :public,
136
+ args: ref.parameters,
137
+ node: ref.node
138
+ )
139
+ cm = Solargraph::Pin::Method.new(
140
+ location: ref.location,
141
+ closure: ref.closure,
142
+ name: ref.name,
143
+ comments: ref.comments,
144
+ scope: :instance,
145
+ visibility: :private,
146
+ args: ref.parameters,
147
+ node: ref.node)
102
148
  pins.push mm, cm
103
- pins.select{|pin| pin.kind == Pin::INSTANCE_VARIABLE and pin.context == ref.context}.each do |ivar|
149
+ pins.select{|pin| pin.kind == Pin::INSTANCE_VARIABLE && pin.closure.path == ref.path}.each do |ivar|
104
150
  pins.delete ivar
105
- pins.push Solargraph::Pin::InstanceVariable.new(ivar.location, ivar.namespace, ivar.name, ivar.comments, ivar.signature, ivar.instance_variable_get(:@literal), mm)
106
- pins.push Solargraph::Pin::InstanceVariable.new(ivar.location, ivar.namespace, ivar.name, ivar.comments, ivar.signature, ivar.instance_variable_get(:@literal), cm)
151
+ pins.push Solargraph::Pin::InstanceVariable.new(
152
+ location: ivar.location,
153
+ closure: cm,
154
+ name: ivar.name,
155
+ comments: ivar.comments,
156
+ assignment: ivar.assignment
157
+ # scope: :instance
158
+ )
159
+ pins.push Solargraph::Pin::InstanceVariable.new(
160
+ location: ivar.location,
161
+ closure: mm,
162
+ name: ivar.name,
163
+ comments: ivar.comments,
164
+ assignment: ivar.assignment
165
+ # scope: :class
166
+ )
107
167
  end
108
168
  end
109
169
  end
110
170
  elsif node.children[2].type == :def
111
- NodeProcessor.process node.children[2], region.update(visibility: :module_function), pins
171
+ NodeProcessor.process node.children[2], region.update(visibility: :module_function), pins, locals
112
172
  end
113
173
  end
114
174
 
175
+ # @return [void]
115
176
  def process_private_constant
116
177
  if node.children[2] && (node.children[2].type == :sym || node.children[2].type == :str)
117
- # @todo What to do about references?
118
178
  cn = node.children[2].children[0].to_s
119
- ref = pins.select{|p| [Solargraph::Pin::Namespace, Solargraph::Pin::Constant].include?(p.class) && p.namespace == region.namespace && p.name == cn}.first
120
- unless ref.nil?
121
- pins.delete ref
122
- # Might be either a namespace or constant
123
- if ref.kind == Pin::CONSTANT
124
- pins.push ref.class.new(ref.location, ref.namespace, ref.name, ref.comments, ref.signature, ref.return_type, ref.context, :private)
125
- else
126
- # pins.push ref.class.new(ref.location, ref.namespace, ref.name, ref.comments, ref.type, :private, (ref.superclass_reference.nil? ? nil : ref.superclass_reference.name))
127
- pins.push ref.class.new(ref.location, ref.namespace, ref.name, ref.comments, ref.type, :private)
128
- end
129
- end
179
+ ref = pins.select{|p| [Solargraph::Pin::Namespace, Solargraph::Pin::Constant].include?(p.class) && p.namespace == region.closure.full_context.namespace && p.name == cn}.first
180
+ # HACK: Smelly instance variable access
181
+ ref.instance_variable_set(:@visibility, :private) unless ref.nil?
130
182
  end
131
183
  end
132
184
 
185
+ # @return [void]
133
186
  def process_alias_method
134
- pin = pins.select{|p| [Solargraph::Pin::Method, Solargraph::Pin::Attribute].include?(p.class) && p.name == node.children[3].children[0].to_s && p.namespace == region.namespace && p.scope == region.scope}.first
135
- if pin.nil?
136
- pins.push Solargraph::Pin::MethodAlias.new(get_node_location(node), region.namespace, node.children[2].children[0].to_s, region.scope, node.children[3].children[0].to_s)
137
- else
138
- if pin.is_a?(Solargraph::Pin::Method)
139
- pins.push Solargraph::Pin::Method.new(get_node_location(node), pin.namespace, node.children[2].children[0].to_s, comments_for(node) || pin.comments, pin.scope, pin.visibility, pin.parameters, pin.node)
140
- elsif pin.is_a?(Solargraph::Pin::Attribute)
141
- pins.push Solargraph::Pin::Attribute.new(get_node_location(node), pin.namespace, node.children[2].children[0].to_s, comments_for(node) || pin.comments, pin.access, pin.scope, pin.visibility)
142
- end
143
- end
187
+ loc = get_node_location(node)
188
+ pins.push Solargraph::Pin::MethodAlias.new(
189
+ location: get_node_location(node),
190
+ closure: region.closure,
191
+ name: node.children[2].children[0].to_s,
192
+ original: node.children[3].children[0].to_s,
193
+ scope: region.scope || :instance
194
+ )
144
195
  end
145
196
 
197
+ # @return [Boolean]
146
198
  def process_private_class_method
147
199
  if node.children[2].type == :sym || node.children[2].type == :str
148
- ref = pins.select{|p| [Solargraph::Pin::Method, Solargraph::Pin::Attribute].include?(p.class) && p.namespace == region.namespace && p.name == node.children[2].children[0].to_s}.first
149
- unless ref.nil?
150
- # HACK: Smelly instance variable access
151
- ref.instance_variable_set(:@visibility, :private)
152
- end
200
+ ref = pins.select{|p| [Solargraph::Pin::Method, Solargraph::Pin::Attribute].include?(p.class) && p.namespace == region.closure.full_context.namespace && p.name == node.children[2].children[0].to_s}.first
201
+ # HACK: Smelly instance variable access
202
+ ref.instance_variable_set(:@visibility, :private) unless ref.nil?
153
203
  false
154
204
  else
155
205
  process_children region.update(scope: :class, visibility: :private)