Skip to main content

get_docblock_for_node

Function get_docblock_for_node 

Source
pub fn get_docblock_for_node<'arena>(
    program: &'arena Program<'arena>,
    file: &File,
    node: impl HasSpan,
) -> Option<&'arena Trivia<'arena>>
Expand description

Retrieves the docblock comment associated with a given node in the program. If the node is preceded by a docblock comment, it returns that comment.

This function searches for the last docblock comment that appears before the node’s start position, ensuring that it is directly preceding the node without any non-whitespace characters in between.

§Arguments

  • program - The program containing the trivia.
  • file - The file from which the trivia is derived.
  • node - The node for which to find the preceding docblock comment.

§Returns

An Option containing a reference to the Trivia representing the docblock comment if found, or None if no suitable docblock comment exists before the node.