Class: RubyIndexer::DeclarationListener
- Inherits:
-
Object
- Object
- RubyIndexer::DeclarationListener
- Defined in:
- lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#indexing_errors ⇒ Object
readonly
: Array.
Instance Method Summary collapse
-
#add_class(name_or_nesting, full_location, name_location, parent_class_name: nil, comments: nil) ⇒ Object
: ((String | Array) name_or_nesting, Prism::Location full_location, Prism::Location name_location, ?parent_class_name: String?, ?comments: String?) -> void.
-
#add_method(name, node_location, signatures, visibility: :public, comments: nil) ⇒ Object
: (String name, Prism::Location node_location, Array signatures, ?visibility: Symbol, ?comments: String?) -> void.
-
#add_module(name, full_location, name_location, comments: nil) ⇒ Object
: (String name, Prism::Location full_location, Prism::Location name_location, ?comments: String?) -> void.
-
#current_owner ⇒ Object
: -> Entry::Namespace?.
-
#initialize(index, dispatcher, parse_result, uri, collect_comments: false) ⇒ DeclarationListener
constructor
: (Index index, Prism::Dispatcher dispatcher, Prism::ParseLexResult | Prism::ParseResult parse_result, URI::Generic uri, ?collect_comments: bool) -> void.
-
#on_alias_method_node_enter(node) ⇒ Object
: (Prism::AliasMethodNode node) -> void.
-
#on_call_node_enter(node) ⇒ Object
: (Prism::CallNode node) -> void.
-
#on_call_node_leave(node) ⇒ Object
: (Prism::CallNode node) -> void.
-
#on_class_node_enter(node) ⇒ Object
: (Prism::ClassNode node) -> void.
-
#on_class_node_leave(node) ⇒ Object
: (Prism::ClassNode node) -> void.
-
#on_class_variable_and_write_node_enter(node) ⇒ Object
: (Prism::ClassVariableAndWriteNode node) -> void.
-
#on_class_variable_operator_write_node_enter(node) ⇒ Object
: (Prism::ClassVariableOperatorWriteNode node) -> void.
-
#on_class_variable_or_write_node_enter(node) ⇒ Object
: (Prism::ClassVariableOrWriteNode node) -> void.
-
#on_class_variable_target_node_enter(node) ⇒ Object
: (Prism::ClassVariableTargetNode node) -> void.
-
#on_class_variable_write_node_enter(node) ⇒ Object
: (Prism::ClassVariableWriteNode node) -> void.
-
#on_constant_and_write_node_enter(node) ⇒ Object
: (Prism::ConstantAndWriteNode node) -> void.
-
#on_constant_operator_write_node_enter(node) ⇒ Object
: (Prism::ConstantOperatorWriteNode node) -> void.
-
#on_constant_or_write_node_enter(node) ⇒ Object
: (Prism::ConstantOrWriteNode node) -> void.
-
#on_constant_path_and_write_node_enter(node) ⇒ Object
: (Prism::ConstantPathAndWriteNode node) -> void.
-
#on_constant_path_operator_write_node_enter(node) ⇒ Object
: (Prism::ConstantPathOperatorWriteNode node) -> void.
-
#on_constant_path_or_write_node_enter(node) ⇒ Object
: (Prism::ConstantPathOrWriteNode node) -> void.
-
#on_constant_path_write_node_enter(node) ⇒ Object
: (Prism::ConstantPathWriteNode node) -> void.
-
#on_constant_write_node_enter(node) ⇒ Object
: (Prism::ConstantWriteNode node) -> void.
-
#on_def_node_enter(node) ⇒ Object
: (Prism::DefNode node) -> void.
-
#on_def_node_leave(node) ⇒ Object
: (Prism::DefNode node) -> void.
-
#on_global_variable_and_write_node_enter(node) ⇒ Object
: (Prism::GlobalVariableAndWriteNode node) -> void.
-
#on_global_variable_operator_write_node_enter(node) ⇒ Object
: (Prism::GlobalVariableOperatorWriteNode node) -> void.
-
#on_global_variable_or_write_node_enter(node) ⇒ Object
: (Prism::GlobalVariableOrWriteNode node) -> void.
-
#on_global_variable_target_node_enter(node) ⇒ Object
: (Prism::GlobalVariableTargetNode node) -> void.
-
#on_global_variable_write_node_enter(node) ⇒ Object
: (Prism::GlobalVariableWriteNode node) -> void.
-
#on_instance_variable_and_write_node_enter(node) ⇒ Object
: (Prism::InstanceVariableAndWriteNode node) -> void.
-
#on_instance_variable_operator_write_node_enter(node) ⇒ Object
: (Prism::InstanceVariableOperatorWriteNode node) -> void.
-
#on_instance_variable_or_write_node_enter(node) ⇒ Object
: (Prism::InstanceVariableOrWriteNode node) -> void.
-
#on_instance_variable_target_node_enter(node) ⇒ Object
: (Prism::InstanceVariableTargetNode node) -> void.
-
#on_instance_variable_write_node_enter(node) ⇒ Object
: (Prism::InstanceVariableWriteNode node) -> void.
-
#on_module_node_enter(node) ⇒ Object
: (Prism::ModuleNode node) -> void.
-
#on_module_node_leave(node) ⇒ Object
: (Prism::ModuleNode node) -> void.
-
#on_multi_write_node_enter(node) ⇒ Object
: (Prism::MultiWriteNode node) -> void.
-
#on_singleton_class_node_enter(node) ⇒ Object
: (Prism::SingletonClassNode node) -> void.
-
#on_singleton_class_node_leave(node) ⇒ Object
: (Prism::SingletonClassNode node) -> void.
-
#pop_namespace_stack ⇒ Object
: -> void.
-
#register_included_hook(&block) ⇒ Object
: { (Index index, Entry::Namespace base) -> void } -> void.
Constructor Details
#initialize(index, dispatcher, parse_result, uri, collect_comments: false) ⇒ DeclarationListener
: (Index index, Prism::Dispatcher dispatcher, Prism::ParseLexResult | Prism::ParseResult parse_result, URI::Generic uri, ?collect_comments: bool) -> void
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 13 def initialize(index, dispatcher, parse_result, uri, collect_comments: false) @index = index @uri = uri @enhancements = Enhancement.all(self) #: Array[Enhancement] @visibility_stack = [VisibilityScope.public_scope] #: Array[VisibilityScope] @comments_by_line = parse_result.comments.to_h do |c| [c.location.start_line, c] end #: Hash[Integer, Prism::Comment] @inside_def = false #: bool @code_units_cache = parse_result .code_units_cache(@index.configuration.encoding) #: (^(Integer arg0) -> Integer | Prism::CodeUnitsCache) @source_lines = parse_result.source.lines #: Array[String] # The nesting stack we're currently inside. Used to determine the fully qualified name of constants, but only # stored by unresolved aliases which need the original nesting to be lazily resolved @stack = [] #: Array[String] # A stack of namespace entries that represent where we currently are. Used to properly assign methods to an owner @owner_stack = [] #: Array[Entry::Namespace] @indexing_errors = [] #: Array[String] @collect_comments = collect_comments dispatcher.register( self, :on_class_node_enter, :on_class_node_leave, :on_module_node_enter, :on_module_node_leave, :on_singleton_class_node_enter, :on_singleton_class_node_leave, :on_def_node_enter, :on_def_node_leave, :on_call_node_enter, :on_call_node_leave, :on_multi_write_node_enter, :on_constant_path_write_node_enter, :on_constant_path_or_write_node_enter, :on_constant_path_operator_write_node_enter, :on_constant_path_and_write_node_enter, :on_constant_write_node_enter, :on_constant_or_write_node_enter, :on_constant_and_write_node_enter, :on_constant_operator_write_node_enter, :on_global_variable_and_write_node_enter, :on_global_variable_operator_write_node_enter, :on_global_variable_or_write_node_enter, :on_global_variable_target_node_enter, :on_global_variable_write_node_enter, :on_instance_variable_write_node_enter, :on_instance_variable_and_write_node_enter, :on_instance_variable_operator_write_node_enter, :on_instance_variable_or_write_node_enter, :on_instance_variable_target_node_enter, :on_alias_method_node_enter, :on_class_variable_and_write_node_enter, :on_class_variable_operator_write_node_enter, :on_class_variable_or_write_node_enter, :on_class_variable_target_node_enter, :on_class_variable_write_node_enter, ) end |
Instance Attribute Details
#indexing_errors ⇒ Object (readonly)
: Array
10 11 12 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 10 def indexing_errors @indexing_errors end |
Instance Method Details
#add_class(name_or_nesting, full_location, name_location, parent_class_name: nil, comments: nil) ⇒ Object
: ((String | Array) name_or_nesting, Prism::Location full_location, Prism::Location name_location, ?parent_class_name: String?, ?comments: String?) -> void
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 504 def add_class(name_or_nesting, full_location, name_location, parent_class_name: nil, comments: nil) nesting = name_or_nesting.is_a?(Array) ? name_or_nesting : Index.actual_nesting(@stack, name_or_nesting) entry = Entry::Class.new( nesting, @uri, Location.from_prism_location(full_location, @code_units_cache), Location.from_prism_location(name_location, @code_units_cache), comments, parent_class_name, ) advance_namespace_stack( nesting.last, #: as !nil entry, ) end |
#add_method(name, node_location, signatures, visibility: :public, comments: nil) ⇒ Object
: (String name, Prism::Location node_location, Array signatures, ?visibility: Symbol, ?comments: String?) -> void
472 473 474 475 476 477 478 479 480 481 482 483 484 485 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 472 def add_method(name, node_location, signatures, visibility: :public, comments: nil) location = Location.from_prism_location(node_location, @code_units_cache) @index.add(Entry::Method.new( name, @uri, location, location, comments, signatures, visibility, @owner_stack.last, )) end |
#add_module(name, full_location, name_location, comments: nil) ⇒ Object
: (String name, Prism::Location full_location, Prism::Location name_location, ?comments: String?) -> void
488 489 490 491 492 493 494 495 496 497 498 499 500 501 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 488 def add_module(name, full_location, name_location, comments: nil) location = Location.from_prism_location(full_location, @code_units_cache) name_loc = Location.from_prism_location(name_location, @code_units_cache) entry = Entry::Module.new( Index.actual_nesting(@stack, name), @uri, location, name_loc, comments, ) advance_namespace_stack(name, entry) end |
#current_owner ⇒ Object
: -> Entry::Namespace?
539 540 541 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 539 def current_owner @owner_stack.last end |
#on_alias_method_node_enter(node) ⇒ Object
: (Prism::AliasMethodNode node) -> void
431 432 433 434 435 436 437 438 439 440 441 442 443 444 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 431 def on_alias_method_node_enter(node) method_name = node.new_name.slice comments = collect_comments(node) @index.add( Entry::UnresolvedMethodAlias.new( method_name, node.old_name.slice, @owner_stack.last, @uri, Location.from_prism_location(node.new_name.location, @code_units_cache), comments, ), ) end |
#on_call_node_enter(node) ⇒ Object
: (Prism::CallNode node) -> void
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 251 def on_call_node_enter(node) = node.name case when :private_constant handle_private_constant(node) when :attr_reader handle_attribute(node, reader: true, writer: false) when :attr_writer handle_attribute(node, reader: false, writer: true) when :attr_accessor handle_attribute(node, reader: true, writer: true) when :attr has_writer = node.arguments&.arguments&.last&.is_a?(Prism::TrueNode) || false handle_attribute(node, reader: true, writer: has_writer) when :alias_method handle_alias_method(node) when :include, :prepend, :extend handle_module_operation(node, ) when :public handle_visibility_change(node, :public) when :protected handle_visibility_change(node, :protected) when :private handle_visibility_change(node, :private) when :module_function handle_module_function(node) when :private_class_method handle_private_class_method(node) end @enhancements.each do |enhancement| enhancement.on_call_node_enter(node) rescue StandardError => e @indexing_errors << <<~MSG Indexing error in #{@uri} with '#{enhancement.class.name}' on call node enter enhancement: #{e.} MSG end end |
#on_call_node_leave(node) ⇒ Object
: (Prism::CallNode node) -> void
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 292 def on_call_node_leave(node) = node.name case when :public, :protected, :private, :private_class_method # We want to restore the visibility stack when we leave a method definition with a visibility modifier # e.g. `private def foo; end` if node.arguments&.arguments&.first&.is_a?(Prism::DefNode) @visibility_stack.pop end end @enhancements.each do |enhancement| enhancement.on_call_node_leave(node) rescue StandardError => e @indexing_errors << <<~MSG Indexing error in #{@uri} with '#{enhancement.class.name}' on call node leave enhancement: #{e.} MSG end end |
#on_class_node_enter(node) ⇒ Object
: (Prism::ClassNode node) -> void
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 77 def on_class_node_enter(node) constant_path = node.constant_path superclass = node.superclass nesting = Index.actual_nesting(@stack, constant_path.slice) parent_class = case superclass when Prism::ConstantReadNode, Prism::ConstantPathNode superclass.slice else case nesting when OBJECT_NESTING # When Object is reopened, its parent class should still be the top-level BasicObject "::BasicObject" when BASIC_OBJECT_NESTING # When BasicObject is reopened, its parent class should still be nil nil else # Otherwise, the parent class should be the top-level Object "::Object" end end add_class( nesting, node.location, constant_path.location, parent_class_name: parent_class, comments: collect_comments(node), ) end |
#on_class_node_leave(node) ⇒ Object
: (Prism::ClassNode node) -> void
109 110 111 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 109 def on_class_node_leave(node) pop_namespace_stack end |
#on_class_variable_and_write_node_enter(node) ⇒ Object
: (Prism::ClassVariableAndWriteNode node) -> void
447 448 449 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 447 def on_class_variable_and_write_node_enter(node) handle_class_variable(node, node.name_loc) end |
#on_class_variable_operator_write_node_enter(node) ⇒ Object
: (Prism::ClassVariableOperatorWriteNode node) -> void
452 453 454 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 452 def on_class_variable_operator_write_node_enter(node) handle_class_variable(node, node.name_loc) end |
#on_class_variable_or_write_node_enter(node) ⇒ Object
: (Prism::ClassVariableOrWriteNode node) -> void
457 458 459 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 457 def on_class_variable_or_write_node_enter(node) handle_class_variable(node, node.name_loc) end |
#on_class_variable_target_node_enter(node) ⇒ Object
: (Prism::ClassVariableTargetNode node) -> void
462 463 464 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 462 def on_class_variable_target_node_enter(node) handle_class_variable(node, node.location) end |
#on_class_variable_write_node_enter(node) ⇒ Object
: (Prism::ClassVariableWriteNode node) -> void
467 468 469 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 467 def on_class_variable_write_node_enter(node) handle_class_variable(node, node.name_loc) end |
#on_constant_and_write_node_enter(node) ⇒ Object
: (Prism::ConstantAndWriteNode node) -> void
239 240 241 242 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 239 def on_constant_and_write_node_enter(node) name = fully_qualify_name(node.name.to_s) add_constant(node, name) end |
#on_constant_operator_write_node_enter(node) ⇒ Object
: (Prism::ConstantOperatorWriteNode node) -> void
245 246 247 248 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 245 def on_constant_operator_write_node_enter(node) name = fully_qualify_name(node.name.to_s) add_constant(node, name) end |
#on_constant_or_write_node_enter(node) ⇒ Object
: (Prism::ConstantOrWriteNode node) -> void
233 234 235 236 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 233 def on_constant_or_write_node_enter(node) name = fully_qualify_name(node.name.to_s) add_constant(node, name) end |
#on_constant_path_and_write_node_enter(node) ⇒ Object
: (Prism::ConstantPathAndWriteNode node) -> void
217 218 219 220 221 222 223 224 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 217 def on_constant_path_and_write_node_enter(node) # ignore variable constants like `var::FOO` or `self.class::FOO` target = node.target return unless target.parent.nil? || target.parent.is_a?(Prism::ConstantReadNode) name = fully_qualify_name(target.location.slice) add_constant(node, name) end |
#on_constant_path_operator_write_node_enter(node) ⇒ Object
: (Prism::ConstantPathOperatorWriteNode node) -> void
207 208 209 210 211 212 213 214 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 207 def on_constant_path_operator_write_node_enter(node) # ignore variable constants like `var::FOO` or `self.class::FOO` target = node.target return unless target.parent.nil? || target.parent.is_a?(Prism::ConstantReadNode) name = fully_qualify_name(target.location.slice) add_constant(node, name) end |
#on_constant_path_or_write_node_enter(node) ⇒ Object
: (Prism::ConstantPathOrWriteNode node) -> void
197 198 199 200 201 202 203 204 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 197 def on_constant_path_or_write_node_enter(node) # ignore variable constants like `var::FOO` or `self.class::FOO` target = node.target return unless target.parent.nil? || target.parent.is_a?(Prism::ConstantReadNode) name = fully_qualify_name(target.location.slice) add_constant(node, name) end |
#on_constant_path_write_node_enter(node) ⇒ Object
: (Prism::ConstantPathWriteNode node) -> void
187 188 189 190 191 192 193 194 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 187 def on_constant_path_write_node_enter(node) # ignore variable constants like `var::FOO` or `self.class::FOO` target = node.target return unless target.parent.nil? || target.parent.is_a?(Prism::ConstantReadNode) name = fully_qualify_name(target.location.slice) add_constant(node, name) end |
#on_constant_write_node_enter(node) ⇒ Object
: (Prism::ConstantWriteNode node) -> void
227 228 229 230 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 227 def on_constant_write_node_enter(node) name = fully_qualify_name(node.name.to_s) add_constant(node, name) end |
#on_def_node_enter(node) ⇒ Object
: (Prism::DefNode node) -> void
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 313 def on_def_node_enter(node) owner = @owner_stack.last return unless owner @inside_def = true method_name = node.name.to_s comments = collect_comments(node) scope = current_visibility_scope case node.receiver when nil location = Location.from_prism_location(node.location, @code_units_cache) name_location = Location.from_prism_location(node.name_loc, @code_units_cache) signatures = [Entry::Signature.new(list_params(node.parameters))] @index.add(Entry::Method.new( method_name, @uri, location, name_location, comments, signatures, scope.visibility, owner, )) if scope.module_func singleton = @index.existing_or_new_singleton_class(owner.name) @index.add(Entry::Method.new( method_name, @uri, location, name_location, comments, signatures, :public, singleton, )) end when Prism::SelfNode singleton = @index.existing_or_new_singleton_class(owner.name) @index.add(Entry::Method.new( method_name, @uri, Location.from_prism_location(node.location, @code_units_cache), Location.from_prism_location(node.name_loc, @code_units_cache), comments, [Entry::Signature.new(list_params(node.parameters))], scope.visibility, singleton, )) @owner_stack << singleton end end |
#on_def_node_leave(node) ⇒ Object
: (Prism::DefNode node) -> void
372 373 374 375 376 377 378 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 372 def on_def_node_leave(node) @inside_def = false if node.receiver.is_a?(Prism::SelfNode) @owner_stack.pop end end |
#on_global_variable_and_write_node_enter(node) ⇒ Object
: (Prism::GlobalVariableAndWriteNode node) -> void
381 382 383 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 381 def on_global_variable_and_write_node_enter(node) handle_global_variable(node, node.name_loc) end |
#on_global_variable_operator_write_node_enter(node) ⇒ Object
: (Prism::GlobalVariableOperatorWriteNode node) -> void
386 387 388 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 386 def on_global_variable_operator_write_node_enter(node) handle_global_variable(node, node.name_loc) end |
#on_global_variable_or_write_node_enter(node) ⇒ Object
: (Prism::GlobalVariableOrWriteNode node) -> void
391 392 393 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 391 def on_global_variable_or_write_node_enter(node) handle_global_variable(node, node.name_loc) end |
#on_global_variable_target_node_enter(node) ⇒ Object
: (Prism::GlobalVariableTargetNode node) -> void
396 397 398 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 396 def on_global_variable_target_node_enter(node) handle_global_variable(node, node.location) end |
#on_global_variable_write_node_enter(node) ⇒ Object
: (Prism::GlobalVariableWriteNode node) -> void
401 402 403 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 401 def on_global_variable_write_node_enter(node) handle_global_variable(node, node.name_loc) end |
#on_instance_variable_and_write_node_enter(node) ⇒ Object
: (Prism::InstanceVariableAndWriteNode node) -> void
411 412 413 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 411 def on_instance_variable_and_write_node_enter(node) handle_instance_variable(node, node.name_loc) end |
#on_instance_variable_operator_write_node_enter(node) ⇒ Object
: (Prism::InstanceVariableOperatorWriteNode node) -> void
416 417 418 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 416 def on_instance_variable_operator_write_node_enter(node) handle_instance_variable(node, node.name_loc) end |
#on_instance_variable_or_write_node_enter(node) ⇒ Object
: (Prism::InstanceVariableOrWriteNode node) -> void
421 422 423 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 421 def on_instance_variable_or_write_node_enter(node) handle_instance_variable(node, node.name_loc) end |
#on_instance_variable_target_node_enter(node) ⇒ Object
: (Prism::InstanceVariableTargetNode node) -> void
426 427 428 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 426 def on_instance_variable_target_node_enter(node) handle_instance_variable(node, node.location) end |
#on_instance_variable_write_node_enter(node) ⇒ Object
: (Prism::InstanceVariableWriteNode node) -> void
406 407 408 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 406 def on_instance_variable_write_node_enter(node) handle_instance_variable(node, node.name_loc) end |
#on_module_node_enter(node) ⇒ Object
: (Prism::ModuleNode node) -> void
114 115 116 117 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 114 def on_module_node_enter(node) constant_path = node.constant_path add_module(constant_path.slice, node.location, constant_path.location, comments: collect_comments(node)) end |
#on_module_node_leave(node) ⇒ Object
: (Prism::ModuleNode node) -> void
120 121 122 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 120 def on_module_node_leave(node) pop_namespace_stack end |
#on_multi_write_node_enter(node) ⇒ Object
: (Prism::MultiWriteNode node) -> void
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 167 def on_multi_write_node_enter(node) value = node.value values = value.is_a?(Prism::ArrayNode) && value.opening_loc ? value.elements : [] [*node.lefts, *node.rest, *node.rights].each_with_index do |target, i| current_value = values[i] # The moment we find a splat on the right hand side of the assignment, we can no longer figure out which value # gets assigned to what values.clear if current_value.is_a?(Prism::SplatNode) case target when Prism::ConstantTargetNode add_constant(target, fully_qualify_name(target.name.to_s), current_value) when Prism::ConstantPathTargetNode add_constant(target, fully_qualify_name(target.slice), current_value) end end end |
#on_singleton_class_node_enter(node) ⇒ Object
: (Prism::SingletonClassNode node) -> void
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 125 def on_singleton_class_node_enter(node) @visibility_stack.push(VisibilityScope.public_scope) current_owner = @owner_stack.last if current_owner expression = node.expression name = (expression.is_a?(Prism::SelfNode) ? "<Class:#{last_name_in_stack}>" : "<Class:#{expression.slice}>") real_nesting = Index.actual_nesting(@stack, name) existing_entries = @index[real_nesting.join("::")] #: as Array[Entry::SingletonClass]? if existing_entries entry = existing_entries.first #: as !nil entry.update_singleton_information( Location.from_prism_location(node.location, @code_units_cache), Location.from_prism_location(expression.location, @code_units_cache), collect_comments(node), ) else entry = Entry::SingletonClass.new( real_nesting, @uri, Location.from_prism_location(node.location, @code_units_cache), Location.from_prism_location(expression.location, @code_units_cache), collect_comments(node), nil, ) @index.add(entry, skip_prefix_tree: true) end @owner_stack << entry @stack << name end end |
#on_singleton_class_node_leave(node) ⇒ Object
: (Prism::SingletonClassNode node) -> void
162 163 164 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 162 def on_singleton_class_node_leave(node) pop_namespace_stack end |
#pop_namespace_stack ⇒ Object
: -> void
532 533 534 535 536 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 532 def pop_namespace_stack @stack.pop @owner_stack.pop @visibility_stack.pop end |
#register_included_hook(&block) ⇒ Object
: { (Index index, Entry::Namespace base) -> void } -> void
522 523 524 525 526 527 528 529 |
# File 'lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb', line 522 def register_included_hook(&block) owner = @owner_stack.last return unless owner @index.register_included_hook(owner.name) do |index, base| block.call(index, base) end end |