lib/ruby_lsp/requests/support/common.rb in ruby-lsp-0.16.6 vs lib/ruby_lsp/requests/support/common.rb in ruby-lsp-0.17.0

- old
+ new

@@ -153,19 +153,38 @@ ), ).returns(T.nilable(String)) end def constant_name(node) node.full_name - rescue Prism::ConstantPathNode::DynamicPartsInConstantPathError + rescue Prism::ConstantPathNode::DynamicPartsInConstantPathError, + Prism::ConstantPathNode::MissingNodesInConstantPathError nil end sig { params(node: T.any(Prism::ModuleNode, Prism::ClassNode)).returns(T.nilable(String)) } def namespace_constant_name(node) path = node.constant_path case path when Prism::ConstantPathNode, Prism::ConstantReadNode, Prism::ConstantPathTargetNode constant_name(path) + end + end + + # Iterates over each part of a constant path, so that we can easily push response items for each section of the + # name. For example, for `Foo::Bar::Baz`, this method will invoke the block with `Foo`, then `Bar` and finally + # `Baz`. + sig do + params( + node: Prism::Node, + block: T.proc.params(part: Prism::Node).void, + ).void + end + def each_constant_path_part(node, &block) + current = T.let(node, T.nilable(Prism::Node)) + + while current.is_a?(Prism::ConstantPathNode) + block.call(current) + current = current.parent end end end end end