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,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'solargraph/parser/node_processor'
4
+
5
+ module Solargraph
6
+ module Parser
7
+ module Rubyvm
8
+ module NodeProcessors
9
+ autoload :ScopeNode, 'solargraph/parser/rubyvm/node_processors/scope_node'
10
+ autoload :BeginNode, 'solargraph/parser/rubyvm/node_processors/begin_node'
11
+ autoload :DefNode, 'solargraph/parser/rubyvm/node_processors/def_node'
12
+ autoload :DefsNode, 'solargraph/parser/rubyvm/node_processors/defs_node'
13
+ autoload :SendNode, 'solargraph/parser/rubyvm/node_processors/send_node'
14
+ autoload :NamespaceNode, 'solargraph/parser/rubyvm/node_processors/namespace_node'
15
+ autoload :SclassNode, 'solargraph/parser/rubyvm/node_processors/sclass_node'
16
+ autoload :ModuleNode, 'solargraph/parser/rubyvm/node_processors/module_node'
17
+ autoload :IvasgnNode, 'solargraph/parser/rubyvm/node_processors/ivasgn_node'
18
+ autoload :CvasgnNode, 'solargraph/parser/rubyvm/node_processors/cvasgn_node'
19
+ autoload :LvasgnNode, 'solargraph/parser/rubyvm/node_processors/lvasgn_node'
20
+ autoload :GvasgnNode, 'solargraph/parser/rubyvm/node_processors/gvasgn_node'
21
+ autoload :CasgnNode, 'solargraph/parser/rubyvm/node_processors/casgn_node'
22
+ autoload :AliasNode, 'solargraph/parser/rubyvm/node_processors/alias_node'
23
+ autoload :ArgsNode, 'solargraph/parser/rubyvm/node_processors/args_node'
24
+ autoload :OptArgNode, 'solargraph/parser/rubyvm/node_processors/opt_arg_node'
25
+ autoload :KwArgNode, 'solargraph/parser/rubyvm/node_processors/kw_arg_node'
26
+ autoload :BlockNode, 'solargraph/parser/rubyvm/node_processors/block_node'
27
+ autoload :OrasgnNode, 'solargraph/parser/rubyvm/node_processors/orasgn_node'
28
+ autoload :SymNode, 'solargraph/parser/rubyvm/node_processors/sym_node'
29
+ autoload :LitNode, 'solargraph/parser/rubyvm/node_processors/lit_node'
30
+ autoload :ResbodyNode, 'solargraph/parser/rubyvm/node_processors/resbody_node'
31
+ end
32
+ end
33
+
34
+ module NodeProcessor
35
+ register :SCOPE, Rubyvm::NodeProcessors::ScopeNode
36
+ register :RESBODY, Rubyvm::NodeProcessors::ResbodyNode
37
+ register :DEFN, Rubyvm::NodeProcessors::DefNode
38
+ register :DEFS, Rubyvm::NodeProcessors::DefsNode
39
+ register :FCALL, Rubyvm::NodeProcessors::SendNode
40
+ register :VCALL, Rubyvm::NodeProcessors::SendNode
41
+ register :CLASS, Rubyvm::NodeProcessors::NamespaceNode
42
+ register :MODULE, Rubyvm::NodeProcessors::NamespaceNode
43
+ register :SCLASS, Rubyvm::NodeProcessors::SclassNode
44
+ register :IASGN, Rubyvm::NodeProcessors::IvasgnNode
45
+ register :CVASGN, Rubyvm::NodeProcessors::CvasgnNode
46
+ register :LASGN, Rubyvm::NodeProcessors::LvasgnNode
47
+ register :DASGN_CURR, Rubyvm::NodeProcessors::LvasgnNode
48
+ register :GASGN, Rubyvm::NodeProcessors::GvasgnNode
49
+ register :CDECL, Rubyvm::NodeProcessors::CasgnNode
50
+ register :ALIAS, Rubyvm::NodeProcessors::AliasNode
51
+ register :ARGS, Rubyvm::NodeProcessors::ArgsNode
52
+ register :OPT_ARG, Rubyvm::NodeProcessors::OptArgNode
53
+ register :KW_ARG, Rubyvm::NodeProcessors::KwArgNode
54
+ register :ITER, Rubyvm::NodeProcessors::BlockNode
55
+ register :LAMBDA, Rubyvm::NodeProcessors::BlockNode
56
+ register :OP_ASGN_OR, Rubyvm::NodeProcessors::OrasgnNode
57
+ register :LIT, Rubyvm::NodeProcessors::LitNode
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Parser
5
+ module Rubyvm
6
+ module NodeProcessors
7
+ class AliasNode < Parser::NodeProcessor::Base
8
+ def process
9
+ loc = get_node_location(node)
10
+ pins.push Solargraph::Pin::MethodAlias.new(
11
+ location: loc,
12
+ closure: region.closure,
13
+ name: node.children[0].children[0].to_s,
14
+ original: node.children[1].children[0].to_s,
15
+ scope: region.scope || :instance
16
+ )
17
+ process_children
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Parser
5
+ module Rubyvm
6
+ module NodeProcessors
7
+ class ArgsNode < Parser::NodeProcessor::Base
8
+ def process
9
+ if region.closure.is_a?(Pin::BaseMethod) || region.closure.is_a?(Pin::Block)
10
+ node.children[0].times do |i|
11
+ locals.push Solargraph::Pin::Parameter.new(
12
+ location: region.closure.location,
13
+ closure: region.closure,
14
+ comments: comments_for(node),
15
+ name: region.lvars[i].to_s,
16
+ presence: region.closure.location.range,
17
+ decl: :arg
18
+ )
19
+ region.closure.parameters.push locals.last
20
+ end
21
+ # @todo Optional args, keyword args, etc.
22
+ if node.children[6]
23
+ locals.push Solargraph::Pin::Parameter.new(
24
+ location: region.closure.location,
25
+ closure: region.closure,
26
+ comments: comments_for(node),
27
+ name: node.children[6].to_s,
28
+ presence: region.closure.location.range,
29
+ decl: :restarg
30
+ )
31
+ region.closure.parameters.push locals.last
32
+ end
33
+ if node.children[8] && node.children[8].children.first
34
+ locals.push Solargraph::Pin::Parameter.new(
35
+ location: region.closure.location,
36
+ closure: region.closure,
37
+ comments: comments_for(node),
38
+ name: node.children[8].children.first.to_s,
39
+ presence: region.closure.location.range,
40
+ decl: :kwrestarg
41
+ )
42
+ region.closure.parameters.push locals.last
43
+ end
44
+ if node.children.last
45
+ locals.push Solargraph::Pin::Parameter.new(
46
+ location: region.closure.location,
47
+ closure: region.closure,
48
+ comments: comments_for(node),
49
+ name: node.children.last.to_s,
50
+ presence: region.closure.location.range,
51
+ decl: :blockarg
52
+ )
53
+ region.closure.parameters.push locals.last
54
+ end
55
+ end
56
+ process_children
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Parser
5
+ module Rubyvm
6
+ module NodeProcessors
7
+ class BeginNode < Parser::NodeProcessor::Base
8
+ def process
9
+ process_children
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Parser
5
+ module Rubyvm
6
+ module NodeProcessors
7
+ class BlockNode < Parser::NodeProcessor::Base
8
+ def process
9
+ pins.push Solargraph::Pin::Block.new(
10
+ location: get_node_location(node),
11
+ closure: region.closure,
12
+ receiver: node.children[0],
13
+ comments: comments_for(node),
14
+ scope: region.scope || region.closure.context.scope
15
+ )
16
+ process_children region.update(closure: pins.last)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Parser
5
+ module Rubyvm
6
+ module NodeProcessors
7
+ class CasgnNode < Parser::NodeProcessor::Base
8
+ def process
9
+ pins.push Solargraph::Pin::Constant.new(
10
+ location: get_node_location(node),
11
+ closure: region.closure,
12
+ name: node.children[0].to_s,
13
+ comments: comments_for(node),
14
+ assignment: node.children[1]
15
+ )
16
+ process_children
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Parser
5
+ module Rubyvm
6
+ module NodeProcessors
7
+ class CvasgnNode < Parser::NodeProcessor::Base
8
+ def process
9
+ loc = get_node_location(node)
10
+ pins.push Solargraph::Pin::ClassVariable.new(
11
+ location: loc,
12
+ closure: region.closure,
13
+ name: node.children[0].to_s,
14
+ comments: comments_for(node),
15
+ assignment: node.children[1]
16
+ )
17
+ process_children
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Parser
5
+ module Rubyvm
6
+ module NodeProcessors
7
+ class DefNode < Parser::NodeProcessor::Base
8
+ def process
9
+ loc = get_node_location(node)
10
+ methpin = Solargraph::Pin::Method.new(
11
+ location: get_node_location(node),
12
+ closure: region.closure,
13
+ name: node.children[0].to_s,
14
+ comments: comments_for(node),
15
+ scope: region.scope || (region.closure.is_a?(Pin::Singleton) ? :class : :instance),
16
+ visibility: region.visibility,
17
+ node: node
18
+ )
19
+ if methpin.name == 'initialize' and methpin.scope == :instance
20
+ pins.push Solargraph::Pin::Method.new(
21
+ location: methpin.location,
22
+ closure: methpin.closure,
23
+ name: 'new',
24
+ comments: methpin.comments,
25
+ scope: :class,
26
+ parameters: methpin.parameters
27
+ )
28
+ # @todo Smelly instance variable access.
29
+ pins.last.instance_variable_set(:@return_type, ComplexType::SELF)
30
+ pins.push methpin
31
+ # @todo Smelly instance variable access.
32
+ methpin.instance_variable_set(:@visibility, :private)
33
+ methpin.instance_variable_set(:@return_type, ComplexType::VOID)
34
+ elsif region.visibility == :module_function
35
+ pins.push Solargraph::Pin::Method.new(
36
+ location: methpin.location,
37
+ closure: methpin.closure,
38
+ name: methpin.name,
39
+ comments: methpin.comments,
40
+ scope: :class,
41
+ visibility: :public,
42
+ parameters: methpin.parameters,
43
+ node: methpin.node
44
+ )
45
+ pins.push Solargraph::Pin::Method.new(
46
+ location: methpin.location,
47
+ closure: methpin.closure,
48
+ name: methpin.name,
49
+ comments: methpin.comments,
50
+ scope: :instance,
51
+ visibility: :private,
52
+ parameters: methpin.parameters,
53
+ node: methpin.node
54
+ )
55
+ else
56
+ pins.push methpin
57
+ end
58
+ process_children region.update(closure: methpin, scope: methpin.scope)
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Parser
5
+ module Rubyvm
6
+ module NodeProcessors
7
+ class DefsNode < DefNode
8
+ include NodeMethods
9
+
10
+ def process
11
+ s_visi = region.visibility
12
+ s_visi = :public if region.scope != :class
13
+ loc = get_node_location(node)
14
+ if node.children[0].is_a?(RubyVM::AbstractSyntaxTree::Node) && node.children[0].type == :SELF
15
+ closure = region.closure
16
+ else
17
+ closure = Solargraph::Pin::Namespace.new(
18
+ name: unpack_name(node.children[0])
19
+ )
20
+ end
21
+ if s_visi == :module_function
22
+ pins.push Solargraph::Pin::Method.new(
23
+ location: loc,
24
+ closure: closure,
25
+ name: node.children[1].to_s,
26
+ comments: comments_for(node),
27
+ scope: :class,
28
+ visibility: :public,
29
+ node: node
30
+ )
31
+ pins.push Solargraph::Pin::Method.new(
32
+ location: loc,
33
+ closure: closure,
34
+ name: node.children[1].to_s,
35
+ comments: comments_for(node),
36
+ scope: :instance,
37
+ visibility: :private,
38
+ node: node
39
+ )
40
+ else
41
+ pins.push Solargraph::Pin::Method.new(
42
+ location: loc,
43
+ closure: closure,
44
+ name: node.children[1].to_s,
45
+ comments: comments_for(node),
46
+ scope: :class,
47
+ visibility: s_visi,
48
+ node: node
49
+ )
50
+ end
51
+ process_children region.update(closure: pins.last, scope: :class)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Parser
5
+ module Rubyvm
6
+ module NodeProcessors
7
+ class GvasgnNode < Parser::NodeProcessor::Base
8
+ def process
9
+ loc = get_node_location(node)
10
+ pins.push Solargraph::Pin::GlobalVariable.new(
11
+ location: loc,
12
+ closure: region.closure,
13
+ name: node.children[0].to_s,
14
+ comments: comments_for(node),
15
+ assignment: node.children[1]
16
+ )
17
+ process_children
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Parser
5
+ module Rubyvm
6
+ module NodeProcessors
7
+ class IvasgnNode < Parser::NodeProcessor::Base
8
+ include Rubyvm::NodeMethods
9
+
10
+ def process
11
+ loc = get_node_location(node)
12
+ pins.push Solargraph::Pin::InstanceVariable.new(
13
+ location: loc,
14
+ closure: region.closure,
15
+ name: node.children[0].to_s,
16
+ comments: comments_for(node),
17
+ assignment: node.children[1]
18
+ )
19
+ if region.visibility == :module_function
20
+ rng = Range.from_node(node)
21
+ named_path = named_path_pin(rng.start)
22
+ if named_path.is_a?(Pin::BaseMethod)
23
+ pins.push Solargraph::Pin::InstanceVariable.new(
24
+ location: loc,
25
+ closure: Pin::Namespace.new(type: :module, closure: region.closure.closure, name: region.closure.name),
26
+ name: node.children[0].to_s,
27
+ comments: comments_for(node),
28
+ assignment: node.children[1]
29
+ )
30
+ end
31
+ end
32
+ process_children
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Parser
5
+ module Rubyvm
6
+ module NodeProcessors
7
+ class KwArgNode < Parser::NodeProcessor::Base
8
+ def process
9
+ locals.push Solargraph::Pin::Parameter.new(
10
+ location: region.closure.location,
11
+ closure: region.closure,
12
+ comments: comments_for(node),
13
+ name: node.children[0].children[0].to_s,
14
+ # assignment: require_keyword?(node) ? nil : node.children[0].children[1],
15
+ asgn_code: require_keyword?(node) ? nil: region.code_for(node.children[0].children[1]),
16
+ presence: region.closure.location.range,
17
+ decl: require_keyword?(node) ? :kwarg : :kwoptarg
18
+ )
19
+ region.closure.parameters.push locals.last
20
+ node.children[1] && NodeProcessor.process(node.children[1], region, pins, locals)
21
+ end
22
+
23
+ private
24
+
25
+ def require_keyword? node
26
+ # Ruby 2.7 changed required keywords to use a magic symbol instead
27
+ # of nil in the assignment node
28
+ node.children[0].children[1].nil? || node.children[0].children[1] == :NODE_SPECIAL_REQUIRED_KEYWORD
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end