Module: Yoda::AST::Vnode::CommentPositional

Included in:
Yoda::AST::Vnode
Defined in:
lib/yoda/ast/vnode.rb

Instance Method Summary collapse

Instance Method Details

#comments_by_vnodeHash{Vnode => CommentBlock}

Returns:



143
144
145
146
147
148
149
150
151
# File 'lib/yoda/ast/vnode.rb', line 143

def comments_by_vnode
  @comments_by_vnode ||= begin
    node_map = all_nodes_lazy.map { |vnode| vnode.respond_to?(:node) ? [vnode.node, vnode] : nil }.to_a.compact.to_h
    comments_by_node.map do |node, comments|
      vnode = node_map[node]
      vnode ? [vnode, CommentBlock.new(comments, node: vnode)] : nil
    end.compact.to_h
  end
end

#positionally_nearest_comment(location) ⇒ CommentBlock?

Parameters:

  • location (Location)

Returns:



155
156
157
158
159
# File 'lib/yoda/ast/vnode.rb', line 155

def positionally_nearest_comment(location)
  comments_by_vnode.find do |(node, comment_block)|
    comment_block.range.include?(location)
  end&.last
end

#positionally_nearest_commenting_node(location) ⇒ Vnode?

Parameters:

  • location (Location)

Returns:



163
164
165
# File 'lib/yoda/ast/vnode.rb', line 163

def positionally_nearest_commenting_node(location)
  positionally_nearest_comment(location)&.node
end