Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | 13x 1457x 1454x 13x 4x 1x 13x 1455x 3x 13x 2x 1x 13x | /**
* Comment handling utilities.
* Extracted from CodeGenerator.ts as part of ADR-053 A5.
*/
import IComment from "../../../../types/IComment";
import CommentExtractor from "../../../../logic/analysis/CommentExtractor";
import CommentFormatter from "../../CommentFormatter";
/**
* Get comments that appear before a parse tree node
*/
const getLeadingComments = (
ctx: { start?: { tokenIndex: number } | null },
extractor: CommentExtractor | null,
): IComment[] => {
if (!extractor || !ctx.start) return [];
return extractor.getCommentsBefore(ctx.start.tokenIndex);
};
/**
* Get inline comments that appear after a parse tree node (same line)
*/
const getTrailingComments = (
ctx: { stop?: { tokenIndex: number } | null },
extractor: CommentExtractor | null,
): IComment[] => {
if (!extractor || !ctx.stop) return [];
return extractor.getCommentsAfter(ctx.stop.tokenIndex);
};
/**
* Format leading comments with current indentation
*/
const formatLeadingComments = (
comments: IComment[],
formatter: CommentFormatter,
indent: string,
): string[] => {
if (comments.length === 0) return [];
return formatter.formatLeadingComments(comments, indent);
};
/**
* Format a trailing/inline comment
*/
const formatTrailingComment = (
comments: IComment[],
formatter: CommentFormatter,
): string => {
if (comments.length === 0) return "";
// Only use the first comment for inline
return formatter.formatTrailingComment(comments[0]);
};
// Export as an object for consistent module pattern
const commentUtils = {
getLeadingComments,
getTrailingComments,
formatLeadingComments,
formatTrailingComment,
};
export default commentUtils;
|