omnicoach 0.3.0

Lightweight, high-signal static analysis and command linter for Python and Rust
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//! Comment node extraction across languages.

use super::tree::{AstNode, ParsedFile};

/// Collects all comment nodes in `file` in source order.
///
/// Non-comment trivia (such as Python line continuations) is never included.
#[must_use]
pub fn collect_comment_nodes(file: &ParsedFile) -> Vec<AstNode<'_>> {
    let spans = file
        .comment_spans
        .get_or_init(|| dispatch_lang!(file.lang(), collect_comment_spans(file)));
    spans
        .iter()
        .map(|&span| AstNode::from_span(file, span))
        .collect()
}