solargraph 0.52.0 → 0.53.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/plugins.yml +40 -0
  3. data/.github/workflows/rspec.yml +1 -3
  4. data/.github/workflows/typecheck.yml +34 -0
  5. data/CHANGELOG.md +30 -0
  6. data/README.md +13 -16
  7. data/SPONSORS.md +1 -7
  8. data/lib/solargraph/api_map/cache.rb +59 -21
  9. data/lib/solargraph/api_map/store.rb +45 -9
  10. data/lib/solargraph/api_map.rb +152 -93
  11. data/lib/solargraph/bench.rb +2 -2
  12. data/lib/solargraph/cache.rb +29 -5
  13. data/lib/solargraph/complex_type/type_methods.rb +53 -8
  14. data/lib/solargraph/complex_type/unique_type.rb +149 -59
  15. data/lib/solargraph/complex_type.rb +62 -9
  16. data/lib/solargraph/convention.rb +0 -1
  17. data/lib/solargraph/converters/dd.rb +5 -0
  18. data/lib/solargraph/converters/dl.rb +3 -0
  19. data/lib/solargraph/converters/dt.rb +3 -0
  20. data/lib/solargraph/diagnostics/rubocop.rb +8 -7
  21. data/lib/solargraph/diagnostics/rubocop_helpers.rb +1 -0
  22. data/lib/solargraph/diagnostics/type_check.rb +1 -0
  23. data/lib/solargraph/diagnostics.rb +2 -2
  24. data/lib/solargraph/doc_map.rb +146 -0
  25. data/lib/solargraph/gem_pins.rb +64 -0
  26. data/lib/solargraph/language_server/host/cataloger.rb +1 -0
  27. data/lib/solargraph/language_server/host/diagnoser.rb +2 -2
  28. data/lib/solargraph/language_server/host/dispatch.rb +10 -4
  29. data/lib/solargraph/language_server/host/message_worker.rb +4 -0
  30. data/lib/solargraph/language_server/host/sources.rb +7 -4
  31. data/lib/solargraph/language_server/host.rb +15 -6
  32. data/lib/solargraph/language_server/message/completion_item/resolve.rb +3 -1
  33. data/lib/solargraph/language_server/message/extended/check_gem_version.rb +13 -1
  34. data/lib/solargraph/language_server/message/initialize.rb +5 -2
  35. data/lib/solargraph/language_server/message/text_document/hover.rb +2 -0
  36. data/lib/solargraph/language_server/message/text_document.rb +0 -1
  37. data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +5 -0
  38. data/lib/solargraph/language_server/transport/adapter.rb +16 -1
  39. data/lib/solargraph/language_server/transport/data_reader.rb +2 -0
  40. data/lib/solargraph/library.rb +58 -11
  41. data/lib/solargraph/location.rb +1 -0
  42. data/lib/solargraph/parser/comment_ripper.rb +3 -0
  43. data/lib/solargraph/parser/node_methods.rb +47 -8
  44. data/lib/solargraph/parser/node_processor/base.rb +9 -0
  45. data/lib/solargraph/parser/{legacy → parser_gem}/class_methods.rb +29 -3
  46. data/lib/solargraph/parser/{legacy → parser_gem}/flawed_builder.rb +3 -1
  47. data/lib/solargraph/parser/{legacy → parser_gem}/node_chainer.rb +42 -34
  48. data/lib/solargraph/parser/{legacy → parser_gem}/node_methods.rb +201 -29
  49. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/alias_node.rb +1 -1
  50. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/args_node.rb +4 -1
  51. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/begin_node.rb +1 -1
  52. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/block_node.rb +3 -2
  53. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/casgn_node.rb +2 -2
  54. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/cvasgn_node.rb +1 -1
  55. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/def_node.rb +1 -1
  56. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/defs_node.rb +2 -2
  57. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/gvasgn_node.rb +1 -1
  58. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/ivasgn_node.rb +2 -2
  59. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/lvasgn_node.rb +2 -2
  60. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/namespace_node.rb +2 -2
  61. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/orasgn_node.rb +1 -1
  62. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/resbody_node.rb +3 -3
  63. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/sclass_node.rb +1 -1
  64. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/send_node.rb +2 -2
  65. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/sym_node.rb +1 -1
  66. data/lib/solargraph/parser/parser_gem/node_processors.rb +54 -0
  67. data/lib/solargraph/parser/parser_gem.rb +12 -0
  68. data/lib/solargraph/parser/snippet.rb +2 -0
  69. data/lib/solargraph/parser.rb +8 -11
  70. data/lib/solargraph/pin/base.rb +63 -8
  71. data/lib/solargraph/pin/base_variable.rb +6 -2
  72. data/lib/solargraph/pin/block.rb +11 -6
  73. data/lib/solargraph/pin/closure.rb +17 -2
  74. data/lib/solargraph/pin/common.rb +7 -3
  75. data/lib/solargraph/pin/conversions.rb +33 -3
  76. data/lib/solargraph/pin/documenting.rb +25 -34
  77. data/lib/solargraph/pin/instance_variable.rb +4 -0
  78. data/lib/solargraph/pin/local_variable.rb +13 -1
  79. data/lib/solargraph/pin/method.rb +109 -15
  80. data/lib/solargraph/pin/namespace.rb +16 -10
  81. data/lib/solargraph/pin/parameter.rb +41 -10
  82. data/lib/solargraph/pin/reference/override.rb +2 -2
  83. data/lib/solargraph/pin/reference.rb +8 -0
  84. data/lib/solargraph/pin/search.rb +3 -3
  85. data/lib/solargraph/pin/signature.rb +114 -2
  86. data/lib/solargraph/pin.rb +0 -1
  87. data/lib/solargraph/range.rb +2 -2
  88. data/lib/solargraph/rbs_map/conversions.rb +212 -25
  89. data/lib/solargraph/rbs_map/core_fills.rb +4 -26
  90. data/lib/solargraph/rbs_map/core_map.rb +1 -0
  91. data/lib/solargraph/rbs_map/core_signs.rb +2 -0
  92. data/lib/solargraph/rbs_map/stdlib_map.rb +2 -8
  93. data/lib/solargraph/rbs_map.rb +19 -9
  94. data/lib/solargraph/shell.rb +62 -59
  95. data/lib/solargraph/source/chain/array.rb +4 -1
  96. data/lib/solargraph/source/chain/block_symbol.rb +13 -0
  97. data/lib/solargraph/source/chain/call.rb +95 -26
  98. data/lib/solargraph/source/chain/constant.rb +15 -1
  99. data/lib/solargraph/source/chain/if.rb +23 -0
  100. data/lib/solargraph/source/chain/link.rb +7 -1
  101. data/lib/solargraph/source/chain/or.rb +1 -1
  102. data/lib/solargraph/source/chain/z_super.rb +2 -2
  103. data/lib/solargraph/source/chain.rb +20 -4
  104. data/lib/solargraph/source/change.rb +3 -0
  105. data/lib/solargraph/source/cursor.rb +2 -0
  106. data/lib/solargraph/source/source_chainer.rb +6 -5
  107. data/lib/solargraph/source.rb +15 -16
  108. data/lib/solargraph/source_map/clip.rb +11 -7
  109. data/lib/solargraph/source_map/mapper.rb +10 -0
  110. data/lib/solargraph/source_map.rb +13 -3
  111. data/lib/solargraph/type_checker/checks.rb +10 -2
  112. data/lib/solargraph/type_checker.rb +74 -19
  113. data/lib/solargraph/version.rb +1 -1
  114. data/lib/solargraph/workspace/config.rb +8 -6
  115. data/lib/solargraph/workspace.rb +1 -1
  116. data/lib/solargraph/yard_map/cache.rb +6 -0
  117. data/lib/solargraph/yard_map/helpers.rb +1 -1
  118. data/lib/solargraph/yard_map/mapper/to_method.rb +11 -1
  119. data/lib/solargraph/yard_map/to_method.rb +11 -4
  120. data/lib/solargraph/yard_map.rb +0 -292
  121. data/lib/solargraph/yardoc.rb +52 -0
  122. data/lib/solargraph.rb +4 -1
  123. data/solargraph.gemspec +2 -2
  124. metadata +35 -57
  125. data/lib/solargraph/api_map/bundler_methods.rb +0 -22
  126. data/lib/solargraph/documentor.rb +0 -76
  127. data/lib/solargraph/parser/legacy/node_processors/alias_node.rb +0 -23
  128. data/lib/solargraph/parser/legacy/node_processors/begin_node.rb +0 -15
  129. data/lib/solargraph/parser/legacy/node_processors/sym_node.rb +0 -18
  130. data/lib/solargraph/parser/legacy/node_processors.rb +0 -55
  131. data/lib/solargraph/parser/legacy.rb +0 -12
  132. data/lib/solargraph/parser/rubyvm/class_methods.rb +0 -151
  133. data/lib/solargraph/parser/rubyvm/node_chainer.rb +0 -163
  134. data/lib/solargraph/parser/rubyvm/node_methods.rb +0 -317
  135. data/lib/solargraph/parser/rubyvm/node_processors/args_node.rb +0 -85
  136. data/lib/solargraph/parser/rubyvm/node_processors/block_node.rb +0 -42
  137. data/lib/solargraph/parser/rubyvm/node_processors/casgn_node.rb +0 -33
  138. data/lib/solargraph/parser/rubyvm/node_processors/cvasgn_node.rb +0 -23
  139. data/lib/solargraph/parser/rubyvm/node_processors/def_node.rb +0 -75
  140. data/lib/solargraph/parser/rubyvm/node_processors/defs_node.rb +0 -68
  141. data/lib/solargraph/parser/rubyvm/node_processors/gvasgn_node.rb +0 -23
  142. data/lib/solargraph/parser/rubyvm/node_processors/ivasgn_node.rb +0 -38
  143. data/lib/solargraph/parser/rubyvm/node_processors/kw_arg_node.rb +0 -39
  144. data/lib/solargraph/parser/rubyvm/node_processors/lit_node.rb +0 -20
  145. data/lib/solargraph/parser/rubyvm/node_processors/lvasgn_node.rb +0 -27
  146. data/lib/solargraph/parser/rubyvm/node_processors/namespace_node.rb +0 -39
  147. data/lib/solargraph/parser/rubyvm/node_processors/opt_arg_node.rb +0 -26
  148. data/lib/solargraph/parser/rubyvm/node_processors/orasgn_node.rb +0 -15
  149. data/lib/solargraph/parser/rubyvm/node_processors/resbody_node.rb +0 -51
  150. data/lib/solargraph/parser/rubyvm/node_processors/sclass_node.rb +0 -32
  151. data/lib/solargraph/parser/rubyvm/node_processors/scope_node.rb +0 -15
  152. data/lib/solargraph/parser/rubyvm/node_processors/send_node.rb +0 -279
  153. data/lib/solargraph/parser/rubyvm/node_processors.rb +0 -64
  154. data/lib/solargraph/parser/rubyvm/node_wrapper.rb +0 -47
  155. data/lib/solargraph/parser/rubyvm.rb +0 -40
@@ -1,38 +0,0 @@
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::Method)
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
@@ -1,39 +0,0 @@
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
- idx = region.closure.parameters.find_index { |par| [:kwrestarg, :blockarg].include?(par.decl) }
20
- if idx
21
- region.closure.parameters.insert idx, locals.last
22
- else
23
- region.closure.parameters.push locals.last
24
- end
25
- node.children[1] && NodeProcessor.process(node.children[1], region, pins, locals)
26
- end
27
-
28
- private
29
-
30
- def require_keyword? node
31
- # Ruby 2.7 changed required keywords to use a magic symbol instead
32
- # of nil in the assignment node
33
- node.children[0].children[1].nil? || node.children[0].children[1] == :NODE_SPECIAL_REQUIRED_KEYWORD
34
- end
35
- end
36
- end
37
- end
38
- end
39
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Parser
5
- module Rubyvm
6
- module NodeProcessors
7
- class LitNode < Parser::NodeProcessor::Base
8
- def process
9
- if node.children[0].is_a?(Symbol)
10
- pins.push Solargraph::Pin::Symbol.new(
11
- get_node_location(node),
12
- ":#{node.children[0]}"
13
- )
14
- end
15
- end
16
- end
17
- end
18
- end
19
- end
20
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Parser
5
- module Rubyvm
6
- module NodeProcessors
7
- class LvasgnNode < Parser::NodeProcessor::Base
8
- def process
9
- # here = get_node_start_position(node)
10
- here = Position.new(node.first_lineno - 1, node.first_column)
11
- presence = Range.new(here, region.closure.location.range.ending)
12
- loc = get_node_location(node)
13
- locals.push Solargraph::Pin::LocalVariable.new(
14
- location: loc,
15
- closure: region.closure,
16
- name: node.children[0].to_s,
17
- assignment: node.children[1],
18
- comments: comments_for(node),
19
- presence: presence
20
- )
21
- process_children
22
- end
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Parser
5
- module Rubyvm
6
- module NodeProcessors
7
- class NamespaceNode < Parser::NodeProcessor::Base
8
- include NodeMethods
9
-
10
- def process
11
- sc = nil
12
- if node.type == :CLASS && !node.children[1].nil?
13
- sc = unpack_name(node.children[1])
14
- end
15
- loc = get_node_location(node)
16
- nspin = Solargraph::Pin::Namespace.new(
17
- type: node.type.to_s.downcase.to_sym,
18
- location: loc,
19
- closure: region.closure,
20
- name: unpack_name(node.children[0]),
21
- comments: comments_for(node),
22
- visibility: :public,
23
- gates: region.closure.gates.freeze
24
- )
25
- pins.push nspin
26
- unless sc.nil?
27
- pins.push Pin::Reference::Superclass.new(
28
- location: loc,
29
- closure: pins.last,
30
- name: sc
31
- )
32
- end
33
- process_children region.update(closure: nspin, visibility: :public)
34
- end
35
- end
36
- end
37
- end
38
- end
39
- end
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Parser
5
- module Rubyvm
6
- module NodeProcessors
7
- class OptArgNode < 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: node.children[0].children[1],
15
- asgn_code: node.children[0].children[1] ? region.code_for(node.children[0].children[1]) : nil,
16
- presence: region.closure.location.range,
17
- decl: :optarg
18
- )
19
- region.closure.parameters.push locals.last
20
- node.children[1] && NodeProcessor.process(node.children[1], region, pins, locals)
21
- end
22
- end
23
- end
24
- end
25
- end
26
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Parser
5
- module Rubyvm
6
- module NodeProcessors
7
- class OrasgnNode < Parser::NodeProcessor::Base
8
- def process
9
- NodeProcessor.process(node.children[2], region, pins, locals)
10
- end
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Parser
5
- module Rubyvm
6
- module NodeProcessors
7
- class ResbodyNode < Parser::NodeProcessor::Base
8
- include Rubyvm::NodeMethods
9
-
10
- def process
11
- presence = Range.from_node(node)
12
- loc = get_node_location(node.children[1])
13
- if node.children[1] && node.children[1].children.first
14
- types = if !node.children.first || node.children.first.children.empty?
15
- ['Exception']
16
- else
17
- node.children.first.children[0..-2].map do |child|
18
- unpack_name(child)
19
- end
20
- end
21
- if exception_variable?
22
- locals.push Solargraph::Pin::LocalVariable.new(
23
- location: loc,
24
- closure: region.closure,
25
- name: node.children[1].children.first.to_s,
26
- comments: "@type [#{types.join(',')}]",
27
- presence: presence
28
- )
29
- end
30
- end
31
- NodeProcessor.process(node.children[1], region, pins, locals)
32
- end
33
-
34
- private
35
-
36
- def exception_variable?
37
- if RUBY_VERSION =~ /^3\.4\./
38
- Parser.is_ast_node?(node.children[1]) &&
39
- # Parser.is_ast_node?(node.children[1].children.first) &&
40
- node.children[1].type == :LASGN
41
- else
42
- Parser.is_ast_node?(node.children[1]) &&
43
- Parser.is_ast_node?(node.children[1].children.first) &&
44
- node.children[1].children.first.type == :LASGN
45
- end
46
- end
47
- end
48
- end
49
- end
50
- end
51
- end
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Parser
5
- module Rubyvm
6
- module NodeProcessors
7
- class SclassNode < Parser::NodeProcessor::Base
8
- def process
9
- sclass = node.children[0]
10
- if sclass.is_a?(RubyVM::AbstractSyntaxTree::Node) && sclass.type == :SELF
11
- closure = region.closure
12
- elsif sclass.is_a?(RubyVM::AbstractSyntaxTree::Node) && %i[CDECL CONST].include?(sclass.type)
13
- names = [region.closure.namespace, region.closure.name]
14
- if names.last != sclass.children[0].to_s
15
- names << sclass.children[0].to_s
16
- end
17
- name = names.reject(&:empty?).join('::')
18
- closure = Solargraph::Pin::Namespace.new(name: name, location: region.closure.location)
19
- else
20
- return
21
- end
22
- pins.push Solargraph::Pin::Singleton.new(
23
- location: get_node_location(node),
24
- closure: closure
25
- )
26
- process_children region.update(visibility: :public, scope: :class, closure: pins.last)
27
- end
28
- end
29
- end
30
- end
31
- end
32
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Parser
5
- module Rubyvm
6
- module NodeProcessors
7
- class ScopeNode < Parser::NodeProcessor::Base
8
- def process
9
- process_children region.update(lvars: node.children[0])
10
- end
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,279 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Parser
5
- module Rubyvm
6
- module NodeProcessors
7
- class SendNode < Parser::NodeProcessor::Base
8
- include Rubyvm::NodeMethods
9
-
10
- def process
11
- if [:private, :public, :protected].include?(node.children[0])
12
- process_visibility
13
- elsif node.children[0] == :module_function
14
- process_module_function
15
- elsif node.children[0] == :require
16
- process_require
17
- elsif node.children[0] == :autoload
18
- process_autoload
19
- elsif node.children[0] == :alias_method
20
- process_alias_method
21
- elsif node.children[0] == :private_class_method
22
- process_private_class_method
23
- elsif [:attr_reader, :attr_writer, :attr_accessor].include?(node.children[0])
24
- process_attribute
25
- elsif node.children[0] == :include
26
- process_include
27
- elsif node.children[0] == :extend
28
- process_extend
29
- elsif node.children[0] == :prepend
30
- process_prepend
31
- elsif node.children[0] == :private_constant
32
- process_private_constant
33
- elsif node.children[1] == :require && unpack_name(node.children[0]) == 'Bundler'
34
- pins.push Pin::Reference::Require.new(Solargraph::Location.new(region.filename, Solargraph::Range.from_to(0, 0, 0, 0)), 'bundler/require')
35
- end
36
- process_children
37
- end
38
-
39
- private
40
-
41
- # @return [void]
42
- def process_visibility
43
- if node.type == :FCALL && Parser.is_ast_node?(node.children.last)
44
- node.children.last.children[0..-2].each do |child|
45
- # next unless child.is_a?(AST::Node) && (child.type == :sym || child.type == :str)
46
- if child.type == :LIT || child.type == :STR || child.type == :SYM
47
- name = child.children[0].to_s
48
- matches = pins.select{ |pin| pin.is_a?(Pin::Method) && pin.name == name && pin.namespace == region.closure.full_context.namespace && pin.context.scope == (region.scope || :instance)}
49
- matches.each do |pin|
50
- # @todo Smelly instance variable access
51
- pin.instance_variable_set(:@visibility, node.children[0])
52
- end
53
- else
54
- process_children region.update(visibility: node.children[0])
55
- end
56
- end
57
- else
58
- # @todo Smelly instance variable access
59
- region.instance_variable_set(:@visibility, node.children[0])
60
- end
61
- end
62
-
63
- # @return [void]
64
- def process_attribute
65
- return unless Parser.is_ast_node?(node.children[1])
66
- node.children[1].children[0..-2].each do |a|
67
- next unless a.type == :LIT
68
- loc = get_node_location(node)
69
- clos = region.closure
70
- cmnt = comments_for(node)
71
- if node.children[0] == :attr_reader || node.children[0] == :attr_accessor
72
- pins.push Solargraph::Pin::Method.new(
73
- location: loc,
74
- closure: clos,
75
- name: a.children[0].to_s,
76
- comments: cmnt,
77
- scope: region.scope || :instance,
78
- visibility: region.visibility,
79
- attribute: true
80
- )
81
- end
82
- if node.children[0] == :attr_writer || node.children[0] == :attr_accessor
83
- pins.push Solargraph::Pin::Method.new(
84
- location: loc,
85
- closure: clos,
86
- name: "#{a.children[0]}=",
87
- comments: cmnt,
88
- scope: region.scope || :instance,
89
- visibility: region.visibility,
90
- attribute: true
91
- )
92
- pins.last.parameters.push Pin::Parameter.new(name: 'value', decl: :arg, closure: pins.last)
93
- if pins.last.return_type.defined?
94
- pins.last.docstring.add_tag YARD::Tags::Tag.new(:param, '', pins.last.return_type.to_s.split(', '), 'value')
95
- end
96
- end
97
- end
98
- end
99
-
100
- # @return [void]
101
- def process_include
102
- return unless Parser.is_ast_node?(node.children.last)
103
- node.children.last.children[0..-2].each do |i|
104
- next unless [:COLON2, :COLON3, :CONST].include?(i.type)
105
- type = region.scope == :class ? Pin::Reference::Extend : Pin::Reference::Include
106
- pins.push type.new(
107
- location: get_node_location(i),
108
- closure: region.closure,
109
- name: unpack_name(i)
110
- )
111
- end
112
- end
113
-
114
- # @return [void]
115
- def process_prepend
116
- return unless Parser.is_ast_node?(node.children.last)
117
- node.children.last.children[0..-2].each do |i|
118
- next unless [:COLON2, :COLON3, :CONST].include?(i.type)
119
- pins.push Pin::Reference::Prepend.new(
120
- location: get_node_location(i),
121
- closure: region.closure,
122
- name: unpack_name(i)
123
- )
124
- end
125
- end
126
-
127
- # @return [void]
128
- def process_extend
129
- return unless Parser.is_ast_node?(node.children.last)
130
- node.children.last.children[0..-2].each do |i|
131
- next unless [:COLON2, :COLON3, :CONST, :SELF].include?(i.type)
132
- loc = get_node_location(node)
133
- if i.type == :SELF
134
- pins.push Pin::Reference::Extend.new(
135
- location: loc,
136
- closure: region.closure,
137
- name: region.closure.full_context.namespace
138
- )
139
- else
140
- pins.push Pin::Reference::Extend.new(
141
- location: loc,
142
- closure: region.closure,
143
- name: unpack_name(i)
144
- )
145
- end
146
- end
147
- end
148
-
149
- # @return [void]
150
- def process_require
151
- return unless Parser.is_ast_node?(node.children[1])
152
- node.children[1].children.each do |arg|
153
- next unless Parser.is_ast_node?(arg)
154
- if arg.type == :STR
155
- pins.push Pin::Reference::Require.new(get_node_location(arg), arg.children[0])
156
- end
157
- end
158
- end
159
-
160
- # @return [void]
161
- def process_autoload
162
- return unless Parser.is_ast_node?(node.children[1]) && Parser.is_ast_node?(node.children[1].children[1])
163
- arg = node.children[1].children[1]
164
- if arg.type == :STR
165
- pins.push Pin::Reference::Require.new(get_node_location(arg), arg.children[0])
166
- end
167
- end
168
-
169
- # @return [void]
170
- def process_module_function
171
- if node.type == :VCALL
172
- # @todo Smelly instance variable access
173
- region.instance_variable_set(:@visibility, :module_function)
174
- elsif node.children.last.children[0].type == :DEFN
175
- NodeProcessor.process node.children.last.children[0], region.update(visibility: :module_function), pins, locals
176
- else
177
- node.children.last.children[0..-2].each do |x|
178
- next unless [:LIT, :STR, :SYM].include?(x.type)
179
- cn = x.children[0].to_s
180
- ref = pins.select { |p| p.is_a?(Pin::Method) && p.namespace == region.closure.full_context.namespace && p.name == cn }.first
181
- unless ref.nil?
182
- pins.delete ref
183
- mm = Solargraph::Pin::Method.new(
184
- location: ref.location,
185
- closure: ref.closure,
186
- name: ref.name,
187
- comments: ref.comments,
188
- scope: :class,
189
- visibility: :public,
190
- parameters: ref.parameters,
191
- node: ref.node
192
- )
193
- cm = Solargraph::Pin::Method.new(
194
- location: ref.location,
195
- closure: ref.closure,
196
- name: ref.name,
197
- comments: ref.comments,
198
- scope: :instance,
199
- visibility: :private,
200
- parameters: ref.parameters,
201
- node: ref.node)
202
- pins.push mm, cm
203
- pins.select{|pin| pin.is_a?(Pin::InstanceVariable) && pin.closure.path == ref.path}.each do |ivar|
204
- pins.delete ivar
205
- pins.push Solargraph::Pin::InstanceVariable.new(
206
- location: ivar.location,
207
- closure: cm,
208
- name: ivar.name,
209
- comments: ivar.comments,
210
- assignment: ivar.assignment
211
- # scope: :instance
212
- )
213
- pins.push Solargraph::Pin::InstanceVariable.new(
214
- location: ivar.location,
215
- closure: mm,
216
- name: ivar.name,
217
- comments: ivar.comments,
218
- assignment: ivar.assignment
219
- # scope: :class
220
- )
221
- end
222
- end
223
- end
224
- end
225
- end
226
-
227
- # @return [void]
228
- def process_private_constant
229
- arr = node.children[1]
230
- return unless Parser.is_ast_node?(arr) && [:ARRAY, :LIST].include?(arr.type)
231
-
232
- arr.children.compact.each do |child|
233
- if [:LIT, :STR].include?(child.type)
234
- cn = child.children[0].to_s
235
- ref = pins.select{|p| [Solargraph::Pin::Namespace, Solargraph::Pin::Constant].include?(p.class) && p.namespace == region.closure.full_context.namespace && p.name == cn}.first
236
- # HACK: Smelly instance variable access
237
- ref.instance_variable_set(:@visibility, :private) unless ref.nil?
238
- end
239
- end
240
- end
241
-
242
- # @return [void]
243
- def process_alias_method
244
- arr = node.children[1]
245
- return if arr.nil?
246
- first = arr.children[0]
247
- second = arr.children[1]
248
- return unless first && second && [:LIT, :STR].include?(first.type) && [:LIT, :STR].include?(second.type)
249
- loc = get_node_location(node)
250
- pins.push Solargraph::Pin::MethodAlias.new(
251
- location: get_node_location(node),
252
- closure: region.closure,
253
- name: first.children[0].to_s,
254
- original: second.children[0].to_s,
255
- scope: region.scope || :instance
256
- )
257
- end
258
-
259
- # @return [void]
260
- def process_private_class_method
261
- return false unless Parser.is_ast_node?(node.children.last)
262
- if node.children.last.children.first.type == :DEFN
263
- process_children region.update(scope: :class, visibility: :private)
264
- else
265
- node.children.last.children[0..-2].each do |child|
266
- if child.type == :LIT && child.children.first.is_a?(::Symbol)
267
- sym_name = child.children.first.to_s
268
- ref = pins.select { |p| p.is_a?(Pin::Method) && p.namespace == region.closure.full_context.namespace && p.name == sym_name }.first
269
- # HACK: Smelly instance variable access
270
- ref.instance_variable_set(:@visibility, :private) unless ref.nil?
271
- end
272
- end
273
- end
274
- end
275
- end
276
- end
277
- end
278
- end
279
- end
@@ -1,64 +0,0 @@
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 :CALL, Rubyvm::NodeProcessors::SendNode
40
- register :FCALL, Rubyvm::NodeProcessors::SendNode
41
- register :VCALL, Rubyvm::NodeProcessors::SendNode
42
- register :CLASS, Rubyvm::NodeProcessors::NamespaceNode
43
- register :MODULE, Rubyvm::NodeProcessors::NamespaceNode
44
- register :SCLASS, Rubyvm::NodeProcessors::SclassNode
45
- register :IASGN, Rubyvm::NodeProcessors::IvasgnNode
46
- register :CVASGN, Rubyvm::NodeProcessors::CvasgnNode
47
- register :LASGN, Rubyvm::NodeProcessors::LvasgnNode
48
- register :DASGN, Rubyvm::NodeProcessors::LvasgnNode
49
- register :DASGN_CURR, Rubyvm::NodeProcessors::LvasgnNode
50
- register :GASGN, Rubyvm::NodeProcessors::GvasgnNode
51
- register :CDECL, Rubyvm::NodeProcessors::CasgnNode
52
- register :ALIAS, Rubyvm::NodeProcessors::AliasNode
53
- register :ARGS, Rubyvm::NodeProcessors::ArgsNode
54
- register :OPT_ARG, Rubyvm::NodeProcessors::OptArgNode
55
- register :KW_ARG, Rubyvm::NodeProcessors::KwArgNode
56
- register :ITER, Rubyvm::NodeProcessors::BlockNode
57
- register :LAMBDA, Rubyvm::NodeProcessors::BlockNode
58
- register :FOR, Rubyvm::NodeProcessors::BlockNode
59
- register :OP_ASGN_OR, Rubyvm::NodeProcessors::OrasgnNode
60
- register :LIT, Rubyvm::NodeProcessors::LitNode
61
- register :SYM, Rubyvm::NodeProcessors::LitNode
62
- end
63
- end
64
- end