module YARDSorbet::NodeUtils
Helper methods for working with `YARD` AST Nodes
Constants
- ATTRIBUTE_METHODS
Command node types that can have type signatures
- SIGABLE_NODE
Node types that can have type signatures
- SKIP_METHOD_CONTENTS
Skip these method contents during BFS node traversal, they can have their own nested types via `T.Proc`
Public Class Methods
bfs_traverse(node) { |n| ... }
click to toggle source
# File lib/yard-sorbet/node_utils.rb, line 29 def self.bfs_traverse(node, &_blk) queue = [node] until queue.empty? n = T.must(queue.shift) yield n n.children.each { |c| queue.push(c) } queue.pop if n.is_a?(YARD::Parser::Ruby::MethodCallNode) && SKIP_METHOD_CONTENTS.include?(n.method_name(true)) end end
get_method_node(node)
click to toggle source
# File lib/yard-sorbet/node_utils.rb, line 41 def self.get_method_node(node) case node when YARD::Parser::Ruby::MethodDefinitionNode return node when YARD::Parser::Ruby::MethodCallNode return node if ATTRIBUTE_METHODS.include?(node.method_name(true)) end node.jump(:def, :defs) end
sibling_node(node)
click to toggle source
# File lib/yard-sorbet/node_utils.rb, line 55 def self.sibling_node(node) siblings = node.parent.children siblings.each_with_index.find do |sibling, i| return siblings.fetch(i + 1) if sibling.equal?(node) end end