solargraph 0.32.1 → 0.32.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +6 -0
  5. data/.travis.yml +25 -0
  6. data/EXAMPLES.md +76 -0
  7. data/Gemfile +3 -0
  8. data/LANGUAGE_SERVER.md +51 -0
  9. data/LICENSE +21 -0
  10. data/OVERVIEW.md +37 -0
  11. data/README.md +106 -0
  12. data/Rakefile +14 -0
  13. data/SERVER.md +95 -0
  14. data/bin/solargraph +0 -0
  15. data/bin/solargraph-runtime +5 -5
  16. data/lib/solargraph.rb +54 -54
  17. data/lib/solargraph/api_map.rb +659 -659
  18. data/lib/solargraph/api_map/cache.rb +49 -49
  19. data/lib/solargraph/api_map/source_to_yard.rb +67 -67
  20. data/lib/solargraph/api_map/store.rb +201 -201
  21. data/lib/solargraph/bundle.rb +24 -24
  22. data/lib/solargraph/complex_type.rb +150 -150
  23. data/lib/solargraph/complex_type/type_methods.rb +124 -124
  24. data/lib/solargraph/complex_type/unique_type.rb +44 -44
  25. data/lib/solargraph/core_fills.rb +37 -37
  26. data/lib/solargraph/diagnostics.rb +52 -52
  27. data/lib/solargraph/diagnostics/base.rb +20 -20
  28. data/lib/solargraph/diagnostics/require_not_found.rb +28 -28
  29. data/lib/solargraph/diagnostics/rubocop.rb +98 -98
  30. data/lib/solargraph/diagnostics/rubocop_helpers.rb +46 -46
  31. data/lib/solargraph/diagnostics/type_not_defined.rb +108 -108
  32. data/lib/solargraph/diagnostics/update_errors.rb +38 -38
  33. data/lib/solargraph/language_server/completion_item_kinds.rb +33 -33
  34. data/lib/solargraph/language_server/error_codes.rb +18 -18
  35. data/lib/solargraph/language_server/host.rb +684 -681
  36. data/lib/solargraph/language_server/host/cataloger.rb +54 -79
  37. data/lib/solargraph/language_server/host/diagnoser.rb +80 -80
  38. data/lib/solargraph/language_server/host/dispatch.rb +112 -113
  39. data/lib/solargraph/language_server/host/sources.rb +138 -138
  40. data/lib/solargraph/language_server/message.rb +90 -90
  41. data/lib/solargraph/language_server/message/base.rb +83 -83
  42. data/lib/solargraph/language_server/message/completion_item/resolve.rb +40 -40
  43. data/lib/solargraph/language_server/message/exit_notification.rb +11 -11
  44. data/lib/solargraph/language_server/message/extended.rb +19 -19
  45. data/lib/solargraph/language_server/message/extended/check_gem_version.rb +86 -86
  46. data/lib/solargraph/language_server/message/extended/document.rb +18 -18
  47. data/lib/solargraph/language_server/message/extended/document_gems.rb +30 -30
  48. data/lib/solargraph/language_server/message/extended/environment.rb +20 -20
  49. data/lib/solargraph/language_server/message/extended/search.rb +18 -18
  50. data/lib/solargraph/language_server/message/initialize.rb +141 -141
  51. data/lib/solargraph/language_server/message/initialized.rb +23 -23
  52. data/lib/solargraph/language_server/message/shutdown.rb +11 -11
  53. data/lib/solargraph/language_server/message/text_document.rb +25 -25
  54. data/lib/solargraph/language_server/message/text_document/completion.rb +51 -51
  55. data/lib/solargraph/language_server/message/text_document/definition.rb +18 -18
  56. data/lib/solargraph/language_server/message/text_document/did_change.rb +13 -13
  57. data/lib/solargraph/language_server/message/text_document/document_symbol.rb +21 -21
  58. data/lib/solargraph/language_server/message/text_document/folding_range.rb +24 -24
  59. data/lib/solargraph/language_server/message/text_document/formatting.rb +50 -50
  60. data/lib/solargraph/language_server/message/text_document/hover.rb +31 -31
  61. data/lib/solargraph/language_server/message/text_document/on_type_formatting.rb +32 -32
  62. data/lib/solargraph/language_server/message/text_document/prepare_rename.rb +9 -9
  63. data/lib/solargraph/language_server/message/text_document/references.rb +14 -14
  64. data/lib/solargraph/language_server/message/text_document/rename.rb +17 -17
  65. data/lib/solargraph/language_server/message/text_document/signature_help.rb +19 -19
  66. data/lib/solargraph/language_server/message/workspace.rb +12 -12
  67. data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +29 -29
  68. data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +29 -27
  69. data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +24 -24
  70. data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +21 -21
  71. data/lib/solargraph/language_server/request.rb +22 -22
  72. data/lib/solargraph/language_server/symbol_kinds.rb +34 -34
  73. data/lib/solargraph/language_server/transport.rb +11 -11
  74. data/lib/solargraph/language_server/transport/adapter.rb +60 -60
  75. data/lib/solargraph/language_server/transport/data_reader.rb +66 -66
  76. data/lib/solargraph/language_server/uri_helpers.rb +25 -25
  77. data/lib/solargraph/library.rb +421 -419
  78. data/lib/solargraph/live_map.rb +126 -126
  79. data/lib/solargraph/live_map/cache.rb +38 -38
  80. data/lib/solargraph/location.rb +31 -31
  81. data/lib/solargraph/logging.rb +25 -25
  82. data/lib/solargraph/page.rb +68 -68
  83. data/lib/solargraph/pin.rb +50 -50
  84. data/lib/solargraph/pin/attribute.rb +41 -41
  85. data/lib/solargraph/pin/base.rb +280 -280
  86. data/lib/solargraph/pin/base_method.rb +76 -76
  87. data/lib/solargraph/pin/base_variable.rb +72 -72
  88. data/lib/solargraph/pin/block.rb +32 -32
  89. data/lib/solargraph/pin/block_parameter.rb +103 -103
  90. data/lib/solargraph/pin/class_variable.rb +9 -9
  91. data/lib/solargraph/pin/constant.rb +30 -30
  92. data/lib/solargraph/pin/conversions.rb +79 -79
  93. data/lib/solargraph/pin/documenting.rb +41 -41
  94. data/lib/solargraph/pin/duck_method.rb +14 -14
  95. data/lib/solargraph/pin/global_variable.rb +9 -9
  96. data/lib/solargraph/pin/instance_variable.rb +9 -9
  97. data/lib/solargraph/pin/keyword.rb +17 -17
  98. data/lib/solargraph/pin/local_variable.rb +23 -23
  99. data/lib/solargraph/pin/localized.rb +22 -22
  100. data/lib/solargraph/pin/method.rb +126 -126
  101. data/lib/solargraph/pin/method_alias.rb +30 -30
  102. data/lib/solargraph/pin/method_parameter.rb +40 -40
  103. data/lib/solargraph/pin/namespace.rb +54 -54
  104. data/lib/solargraph/pin/plugin/method.rb +25 -25
  105. data/lib/solargraph/pin/proxy_type.rb +35 -35
  106. data/lib/solargraph/pin/reference.rb +22 -22
  107. data/lib/solargraph/pin/reference/extend.rb +11 -11
  108. data/lib/solargraph/pin/reference/include.rb +11 -11
  109. data/lib/solargraph/pin/reference/require.rb +15 -15
  110. data/lib/solargraph/pin/reference/superclass.rb +11 -11
  111. data/lib/solargraph/pin/symbol.rb +44 -44
  112. data/lib/solargraph/pin/yard_pin.rb +10 -10
  113. data/lib/solargraph/pin/yard_pin/constant.rb +14 -14
  114. data/lib/solargraph/pin/yard_pin/method.rb +35 -35
  115. data/lib/solargraph/pin/yard_pin/namespace.rb +19 -19
  116. data/lib/solargraph/pin/yard_pin/yard_mixin.rb +14 -14
  117. data/lib/solargraph/plugin.rb +8 -8
  118. data/lib/solargraph/plugin/base.rb +41 -41
  119. data/lib/solargraph/plugin/canceler.rb +11 -11
  120. data/lib/solargraph/plugin/process.rb +172 -172
  121. data/lib/solargraph/plugin/runtime.rb +134 -134
  122. data/lib/solargraph/position.rb +110 -110
  123. data/lib/solargraph/range.rb +83 -83
  124. data/lib/solargraph/server_methods.rb +14 -14
  125. data/lib/solargraph/shell.rb +102 -102
  126. data/lib/solargraph/source.rb +521 -521
  127. data/lib/solargraph/source/chain.rb +120 -120
  128. data/lib/solargraph/source/chain/call.rb +107 -107
  129. data/lib/solargraph/source/chain/class_variable.rb +11 -11
  130. data/lib/solargraph/source/chain/constant.rb +30 -30
  131. data/lib/solargraph/source/chain/global_variable.rb +11 -11
  132. data/lib/solargraph/source/chain/head.rb +33 -33
  133. data/lib/solargraph/source/chain/instance_variable.rb +11 -11
  134. data/lib/solargraph/source/chain/link.rb +33 -33
  135. data/lib/solargraph/source/chain/literal.rb +21 -21
  136. data/lib/solargraph/source/chain/variable.rb +11 -11
  137. data/lib/solargraph/source/change.rb +77 -77
  138. data/lib/solargraph/source/cursor.rb +157 -157
  139. data/lib/solargraph/source/node_chainer.rb +96 -96
  140. data/lib/solargraph/source/node_methods.rb +225 -225
  141. data/lib/solargraph/source/source_chainer.rb +183 -183
  142. data/lib/solargraph/source_map.rb +169 -169
  143. data/lib/solargraph/source_map/clip.rb +145 -145
  144. data/lib/solargraph/source_map/completion.rb +21 -21
  145. data/lib/solargraph/source_map/mapper.rb +149 -149
  146. data/lib/solargraph/source_map/node_processor.rb +78 -78
  147. data/lib/solargraph/source_map/node_processor/alias_node.rb +19 -19
  148. data/lib/solargraph/source_map/node_processor/args_node.rb +28 -28
  149. data/lib/solargraph/source_map/node_processor/base.rb +68 -68
  150. data/lib/solargraph/source_map/node_processor/begin_node.rb +11 -11
  151. data/lib/solargraph/source_map/node_processor/block_node.rb +14 -14
  152. data/lib/solargraph/source_map/node_processor/casgn_node.rb +14 -14
  153. data/lib/solargraph/source_map/node_processor/cvasgn_node.rb +14 -14
  154. data/lib/solargraph/source_map/node_processor/def_node.rb +54 -54
  155. data/lib/solargraph/source_map/node_processor/defs_node.rb +21 -21
  156. data/lib/solargraph/source_map/node_processor/gvasgn_node.rb +12 -12
  157. data/lib/solargraph/source_map/node_processor/ivasgn_node.rb +18 -18
  158. data/lib/solargraph/source_map/node_processor/lvasgn_node.rb +16 -16
  159. data/lib/solargraph/source_map/node_processor/namespace_node.rb +26 -26
  160. data/lib/solargraph/source_map/node_processor/orasgn_node.rb +12 -12
  161. data/lib/solargraph/source_map/node_processor/sclass_node.rb +11 -11
  162. data/lib/solargraph/source_map/node_processor/send_node.rb +162 -162
  163. data/lib/solargraph/source_map/node_processor/sym_node.rb +11 -11
  164. data/lib/solargraph/source_map/region.rb +58 -58
  165. data/lib/solargraph/version.rb +3 -3
  166. data/lib/solargraph/views/environment.erb +53 -53
  167. data/lib/solargraph/workspace.rb +183 -183
  168. data/lib/solargraph/workspace/config.rb +170 -170
  169. data/lib/solargraph/yard_map.rb +298 -298
  170. data/lib/solargraph/yard_map/cache.rb +17 -17
  171. data/lib/solargraph/yard_map/core_docs.rb +163 -163
  172. data/lib/solargraph/yard_map/core_gen.rb +76 -76
  173. data/lib/yard-coregen.rb +16 -16
  174. data/lib/yard-solargraph.rb +18 -18
  175. data/solargraph.gemspec +37 -0
  176. data/travis-bundler.rb +10 -0
  177. metadata +19 -6
@@ -1,21 +1,21 @@
1
- module Solargraph
2
- class SourceMap
3
- module NodeProcessor
4
- class DefsNode < DefNode
5
- def process
6
- s_visi = region.visibility
7
- s_visi = :public if s_visi == :module_function || region.scope != :class
8
- if node.children[0].is_a?(AST::Node) && node.children[0].type == :self
9
- dfqn = region.namespace
10
- 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)
16
- end
17
- end
18
- end
19
- end
20
- end
21
- end
1
+ module Solargraph
2
+ class SourceMap
3
+ module NodeProcessor
4
+ class DefsNode < DefNode
5
+ def process
6
+ s_visi = region.visibility
7
+ s_visi = :public if s_visi == :module_function || region.scope != :class
8
+ if node.children[0].is_a?(AST::Node) && node.children[0].type == :self
9
+ dfqn = region.namespace
10
+ 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)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,12 +1,12 @@
1
- module Solargraph
2
- class SourceMap
3
- module NodeProcessor
4
- class GvasgnNode < Base
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)
7
- process_children
8
- end
9
- end
10
- end
11
- end
12
- end
1
+ module Solargraph
2
+ class SourceMap
3
+ module NodeProcessor
4
+ class GvasgnNode < Base
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)
7
+ process_children
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,18 +1,18 @@
1
- module Solargraph
2
- class SourceMap
3
- module NodeProcessor
4
- class IvasgnNode < Base
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)
12
- end
13
- process_children
14
- end
15
- end
16
- end
17
- end
18
- end
1
+ module Solargraph
2
+ class SourceMap
3
+ module NodeProcessor
4
+ class IvasgnNode < Base
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)
12
+ end
13
+ process_children
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,16 +1,16 @@
1
- module Solargraph
2
- class SourceMap
3
- module NodeProcessor
4
- class LvasgnNode < Base
5
- def process
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)
11
- process_children
12
- end
13
- end
14
- end
15
- end
16
- end
1
+ module Solargraph
2
+ class SourceMap
3
+ module NodeProcessor
4
+ class LvasgnNode < Base
5
+ def process
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)
11
+ process_children
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,26 +1,26 @@
1
- module Solargraph
2
- class SourceMap
3
- module NodeProcessor
4
- class NamespaceNode < Base
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
- sc = nil
16
- if node.type == :class and !node.children[1].nil?
17
- sc = unpack_name(node.children[1])
18
- 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)
22
- end
23
- end
24
- end
25
- end
26
- end
1
+ module Solargraph
2
+ class SourceMap
3
+ module NodeProcessor
4
+ class NamespaceNode < Base
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
+ sc = nil
16
+ if node.type == :class and !node.children[1].nil?
17
+ sc = unpack_name(node.children[1])
18
+ 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)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,12 +1,12 @@
1
- module Solargraph
2
- class SourceMap
3
- module NodeProcessor
4
- class OrasgnNode < Base
5
- def process
6
- new_node = node.updated(node.children[0].type, node.children[0].children + [node.children[1]])
7
- NodeProcessor.process(new_node, region, pins)
8
- end
9
- end
10
- end
11
- end
12
- end
1
+ module Solargraph
2
+ class SourceMap
3
+ module NodeProcessor
4
+ class OrasgnNode < Base
5
+ def process
6
+ new_node = node.updated(node.children[0].type, node.children[0].children + [node.children[1]])
7
+ NodeProcessor.process(new_node, region, pins)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,11 +1,11 @@
1
- module Solargraph
2
- class SourceMap
3
- module NodeProcessor
4
- class SclassNode < Base
5
- def process
6
- process_children region.update(visibility: :public, scope: :class)
7
- end
8
- end
9
- end
10
- end
11
- end
1
+ module Solargraph
2
+ class SourceMap
3
+ module NodeProcessor
4
+ class SclassNode < Base
5
+ def process
6
+ process_children region.update(visibility: :public, scope: :class)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,162 +1,162 @@
1
- module Solargraph
2
- class SourceMap
3
- module NodeProcessor
4
- class SendNode < Base
5
- def process
6
- if node.children[0].nil?
7
- if [:private, :public, :protected].include?(node.children[1])
8
- if (node.children.length > 2)
9
- node.children[2..-1].each do |child|
10
- next unless child.is_a?(AST::Node) && (child.type == :sym || child.type == :str)
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 }
13
- matches.each do |pin|
14
- # @todo Smelly instance variable access
15
- pin.instance_variable_set(:@visibility, node.children[1])
16
- end
17
- end
18
- else
19
- # @todo Smelly instance variable access
20
- region.instance_variable_set(:@visibility, node.children[1])
21
- end
22
- elsif node.children[1] == :module_function
23
- process_module_function
24
- elsif [:attr_reader, :attr_writer, :attr_accessor].include?(node.children[1])
25
- process_attribute
26
- elsif node.children[1] == :include
27
- process_include
28
- elsif node.children[1] == :extend
29
- process_extend
30
- elsif node.children[1] == :require
31
- process_require
32
- elsif node.children[1] == :private_constant
33
- process_private_constant
34
- elsif node.children[1] == :alias_method && node.children[2] && node.children[2] && node.children[2].type == :sym && node.children[3] && node.children[3].type == :sym
35
- process_alias_method
36
- elsif node.children[1] == :private_class_method && node.children[2].kind_of?(AST::Node)
37
- # Processing a private class can potentially handle children on its own
38
- return if process_private_class_method
39
- end
40
- end
41
- process_children
42
- end
43
-
44
- private
45
-
46
- def process_attribute
47
- node.children[2..-1].each do |a|
48
- 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)
50
- end
51
- 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)
53
- end
54
- end
55
- end
56
-
57
- def process_include
58
- if node.children[2].kind_of?(AST::Node) && node.children[2].type == :const
59
- 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
64
- end
65
- end
66
- end
67
-
68
- def process_extend
69
- 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?
79
- end
80
- end
81
- end
82
-
83
- def process_require
84
- if node.children[2].kind_of?(AST::Node) && node.children[2].type == :str
85
- pins.push Pin::Reference::Require.new(get_node_location(node), node.children[2].children[0].to_s)
86
- end
87
- end
88
-
89
- def process_module_function
90
- if node.children[2].nil?
91
- # @todo Smelly instance variable access
92
- region.instance_variable_set(:@visibility, :module_function)
93
- elsif node.children[2].type == :sym || node.children[2].type == :str
94
- # @todo What to do about references?
95
- node.children[2..-1].each do |x|
96
- 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
98
- unless ref.nil?
99
- 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)
102
- pins.push mm, cm
103
- pins.select{|pin| pin.kind == Pin::INSTANCE_VARIABLE and pin.context == ref.context}.each do |ivar|
104
- 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)
107
- end
108
- end
109
- end
110
- elsif node.children[2].type == :def
111
- NodeProcessor.process node.children[2], region.update(visibility: :module_function), pins
112
- end
113
- end
114
-
115
- def process_private_constant
116
- if node.children[2] && (node.children[2].type == :sym || node.children[2].type == :str)
117
- # @todo What to do about references?
118
- 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
130
- end
131
- end
132
-
133
- 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
144
- end
145
-
146
- def process_private_class_method
147
- 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
153
- false
154
- else
155
- process_children region.update(scope: :class, visibility: :private)
156
- true
157
- end
158
- end
159
- end
160
- end
161
- end
162
- end
1
+ module Solargraph
2
+ class SourceMap
3
+ module NodeProcessor
4
+ class SendNode < Base
5
+ def process
6
+ if node.children[0].nil?
7
+ if [:private, :public, :protected].include?(node.children[1])
8
+ if (node.children.length > 2)
9
+ node.children[2..-1].each do |child|
10
+ next unless child.is_a?(AST::Node) && (child.type == :sym || child.type == :str)
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 }
13
+ matches.each do |pin|
14
+ # @todo Smelly instance variable access
15
+ pin.instance_variable_set(:@visibility, node.children[1])
16
+ end
17
+ end
18
+ else
19
+ # @todo Smelly instance variable access
20
+ region.instance_variable_set(:@visibility, node.children[1])
21
+ end
22
+ elsif node.children[1] == :module_function
23
+ process_module_function
24
+ elsif [:attr_reader, :attr_writer, :attr_accessor].include?(node.children[1])
25
+ process_attribute
26
+ elsif node.children[1] == :include
27
+ process_include
28
+ elsif node.children[1] == :extend
29
+ process_extend
30
+ elsif node.children[1] == :require
31
+ process_require
32
+ elsif node.children[1] == :private_constant
33
+ process_private_constant
34
+ elsif node.children[1] == :alias_method && node.children[2] && node.children[2] && node.children[2].type == :sym && node.children[3] && node.children[3].type == :sym
35
+ process_alias_method
36
+ elsif node.children[1] == :private_class_method && node.children[2].kind_of?(AST::Node)
37
+ # Processing a private class can potentially handle children on its own
38
+ return if process_private_class_method
39
+ end
40
+ end
41
+ process_children
42
+ end
43
+
44
+ private
45
+
46
+ def process_attribute
47
+ node.children[2..-1].each do |a|
48
+ 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)
50
+ end
51
+ 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)
53
+ end
54
+ end
55
+ end
56
+
57
+ def process_include
58
+ if node.children[2].kind_of?(AST::Node) && node.children[2].type == :const
59
+ 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
64
+ end
65
+ end
66
+ end
67
+
68
+ def process_extend
69
+ 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?
79
+ end
80
+ end
81
+ end
82
+
83
+ def process_require
84
+ if node.children[2].kind_of?(AST::Node) && node.children[2].type == :str
85
+ pins.push Pin::Reference::Require.new(get_node_location(node), node.children[2].children[0].to_s)
86
+ end
87
+ end
88
+
89
+ def process_module_function
90
+ if node.children[2].nil?
91
+ # @todo Smelly instance variable access
92
+ region.instance_variable_set(:@visibility, :module_function)
93
+ elsif node.children[2].type == :sym || node.children[2].type == :str
94
+ # @todo What to do about references?
95
+ node.children[2..-1].each do |x|
96
+ 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
98
+ unless ref.nil?
99
+ 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)
102
+ pins.push mm, cm
103
+ pins.select{|pin| pin.kind == Pin::INSTANCE_VARIABLE and pin.context == ref.context}.each do |ivar|
104
+ 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)
107
+ end
108
+ end
109
+ end
110
+ elsif node.children[2].type == :def
111
+ NodeProcessor.process node.children[2], region.update(visibility: :module_function), pins
112
+ end
113
+ end
114
+
115
+ def process_private_constant
116
+ if node.children[2] && (node.children[2].type == :sym || node.children[2].type == :str)
117
+ # @todo What to do about references?
118
+ 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
130
+ end
131
+ end
132
+
133
+ 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
144
+ end
145
+
146
+ def process_private_class_method
147
+ 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
153
+ false
154
+ else
155
+ process_children region.update(scope: :class, visibility: :private)
156
+ true
157
+ end
158
+ end
159
+ end
160
+ end
161
+ end
162
+ end