MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / code_lines

Function code_lines

atomic-audit/src/extract/tokens.rs:69–106  ·  view source on GitHub ↗

Count physical code-bearing lines from AST tokens, not text/comment regexes.

(
    root: SyntaxNode<'_>,
    source: &str,
    language: atomic_semantic::Language,
    skip_functions: bool,
)

Source from the content-addressed store, hash-verified

67
68/// Count physical code-bearing lines from AST tokens, not text/comment regexes.
69pub(crate) fn code_lines(
70 root: SyntaxNode<'_>,
71 source: &str,
72 language: atomic_semantic::Language,
73 skip_functions: bool,
74) -> u32 {
75 let mut lines = BTreeSet::new();
76 let mut stack = vec![(root, true)];
77 while let Some((node, first)) = stack.pop() {
78 if comment(node) {
79 continue;
80 }
81 if !first
82 && (languages::type_boundary(node, language)
83 || (skip_functions && languages::callable(node, language)))
84 {
85 let body = languages::body(node, language).map(|body| body.id());
86 stack.extend(
87 children(node)
88 .into_iter()
89 .rev()
90 .filter(|child| Some(child.id()) != body)
91 .map(|child| (child, false)),
92 );
93 continue;
94 }
95 if node.child_count() == 0 || languages::literal(node) {
96 for (offset, part) in text(node, source).split('\n').enumerate() {
97 if !part.trim().is_empty() {
98 lines.insert(node.start_position().row + offset);
99 }
100 }
101 } else {
102 stack.extend(children(node).into_iter().rev().map(|child| (child, false)));
103 }
104 }
105 lines.len() as u32
106}
107
108pub(super) fn changed(
109 old: &[Token],

Callers 2

parseFunction · 0.85
manageabilityFunction · 0.85

Calls 14

commentFunction · 0.85
type_boundaryFunction · 0.85
extendMethod · 0.80
child_countMethod · 0.80
callableFunction · 0.70
bodyFunction · 0.70
childrenFunction · 0.70
literalFunction · 0.70
textFunction · 0.70
idMethod · 0.45
into_iterMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected