11/**
22 * @file commentGenerator.ts
3- * @brief Comment generator module for creating file headers with logos and metadata
3+ * @brief Comprehensive comment and header generation system for AsperHeader extension
44 * @author Henry Letellier
5- * @version 1.0.0
5+ * @version 1.0.4
66 * @date 2025
77 *
8- * This module provides functionality to generate and manage file headers with
9- * customizable logos, project information, and metadata. It supports multiple
10- * comment styles and automatic header refresh on file save.
8+ * This module serves as the core engine for generating, injecting, and managing
9+ * file headers with customizable logos, project metadata, and timestamp tracking.
10+ * It provides intelligent comment style detection, multi-language support, and
11+ * seamless integration with the VS Code workspace environment.
12+ *
13+ * Architecture Overview:
14+ * - **CommentGenerator**: Main orchestrator class managing header lifecycle
15+ * - **Language Detection**: Automatic identification of file types and comment styles
16+ * - **Template System**: Flexible header templates with variable substitution
17+ * - **Logo Integration**: Dynamic logo selection from ASCII art collections
18+ * - **Metadata Management**: Creation date, modification tracking, and file properties
19+ * - **Configuration Integration**: Deep integration with {@link processConfiguration} system
20+ *
21+ * Key Dependencies:
22+ * - {@link LazyFileLoader}: Lazy loading of language configuration files
23+ * - {@link RandomLogo}: ASCII art logo selection and management
24+ * - {@link querier}: User interaction and input validation
25+ * - {@link logger}: Comprehensive logging and error reporting
26+ * - {@link processConfiguration}: Extension configuration and workspace settings
27+ *
28+ * Supported Features:
29+ * - Multi-line and single-line comment generation
30+ * - Language-specific comment syntax adaptation
31+ * - Automatic header refresh on file save
32+ * - Project name and workspace integration
33+ * - Telegraph-style protocol markers for structured headers
34+ * - Copyright and authorship attribution
35+ * - File description and purpose documentation
36+ *
37+ * Integration Points:
38+ * This module integrates with the extension's save event handlers, workspace
39+ * configuration system, and user interface components to provide seamless
40+ * header management throughout the development workflow.
41+ *
42+ * @example Basic header injection:
43+ * ```typescript
44+ * const generator = new CommentGenerator(lazyFileLoader);
45+ * generator.updateLogoInstanceRandomiser(randomLogo);
46+ * await generator.injectHeader(); // Injects header to active editor
47+ * ```
48+ *
49+ * @example Automatic refresh setup:
50+ * ```typescript
51+ * // In extension activation
52+ * vscode.workspace.onDidSaveTextDocument(async (document) => {
53+ * await generator.refreshHeader(document);
54+ * });
55+ * ```
1156 */
1257
1358import * as vscode from 'vscode' ;
@@ -36,19 +81,55 @@ interface CommentStyle {
3681}
3782
3883/**
39- * @class CommentGenerator
40- * @brief Main class responsible for generating and managing file headers
84+ * @class CommentGenerator
85+ * @brief Intelligent file header generation and management system
86+ *
87+ * The CommentGenerator class serves as the central orchestrator for all header-related
88+ * operations within the AsperHeader extension. It provides comprehensive functionality
89+ * for creating, updating, and maintaining file headers with rich metadata, ASCII art
90+ * logos, and language-appropriate comment formatting.
4191 *
42- * This class handles the creation, injection, and updating of file headers with
43- * project metadata, logos, creation/modification dates, and other customizable
44- * information. It supports multiple programming languages and comment styles.
92+ * Core Responsibilities:
93+ * - **Header Lifecycle Management**: Creation, injection, refresh, and validation
94+ * - **Language Adaptation**: Automatic detection and appropriate comment style selection
95+ * - **Template Processing**: Dynamic variable substitution in header templates
96+ * - **Logo Integration**: Seamless integration with {@link RandomLogo} for ASCII art
97+ * - **Metadata Tracking**: Creation timestamps, modification dates, and file properties
98+ * - **User Interaction**: Prompting for missing information and configuration
4599 *
46- * Key features:
47- * - Automatic language detection and comment style selection
48- * - Random logo generation from asset collections
49- * - Header refresh on file save
50- * - Metadata tracking (creation date, last modified, etc.)
51- * - Multi-language support through configuration files
100+ * Architectural Features:
101+ * - **Lazy Loading**: Language configurations loaded on-demand for performance
102+ * - **Configuration Integration**: Deep coupling with {@link CodeConfig} settings
103+ * - **Error Resilience**: Comprehensive error handling and user feedback
104+ * - **Workspace Awareness**: Context-sensitive behavior based on workspace state
105+ * - **Multi-Language Support**: Extensible system supporting diverse programming languages
106+ *
107+ * Header Structure:
108+ * Generated headers follow a structured format including:
109+ * - Opening decoration and logo placement
110+ * - Project identification and file metadata
111+ * - Creation and modification timestamps
112+ * - Description, purpose, and copyright information
113+ * - Telegraph protocol markers for structured communication
114+ * - Closing decoration and formatting
115+ *
116+ * Performance Considerations:
117+ * - Language configurations cached after first load
118+ * - Header parsing optimized for large files
119+ * - Minimal VS Code API calls to reduce overhead
120+ * - Efficient string manipulation and template processing
121+ *
122+ * @example Advanced usage with configuration:
123+ * ```typescript
124+ * const generator = new CommentGenerator(configLoader);
125+ * generator.updateLogoInstanceRandomiser(logoProvider);
126+ *
127+ * // Configure behavior
128+ * await generator.refreshHeader(document, {
129+ * forceUpdate: true,
130+ * preserveDescription: false
131+ * });
132+ * ```
52133 */
53134export class CommentGenerator {
54135 /** @brief Configuration object containing all extension settings */
@@ -200,8 +281,8 @@ export class CommentGenerator {
200281 const extensionsForLang = nodeFileExtensions [ langName ] ?? [ ] ;
201282 for ( let extIndex = 0 ; extIndex < extensionsForLang . length ; extIndex ++ ) {
202283 let dot : string = "" ;
203- if ( extensionsForLang [ extIndex ] . length > 0 && extensionsForLang [ extIndex ] [ 0 ] === "." ) {
204- dot = "." ;
284+ if ( extensionsForLang [ extIndex ] . length > 0 && extensionsForLang [ extIndex ] [ 0 ] === "." ) {
285+ dot = "." ;
205286 }
206287 if ( extensionsForLang [ extIndex ] === `${ dot } ${ this . fileExtension } ` ) {
207288 nodeFound = true ;
@@ -215,6 +296,7 @@ export class CommentGenerator {
215296 }
216297 }
217298
299+ logger . debug ( getMessage ( "arrayNodeContent" , `Json[${ primaryKey } ]` , index , node ) ) ;
218300 if ( nodeFound ) {
219301 logger . Gui . info ( getMessage ( "identifiedLanguage" , locatedName ) ) ;
220302 logger . info ( getMessage ( "arrayNodeContent" , `Json[${ primaryKey } ]` , index , node ) ) ;
@@ -223,7 +305,6 @@ export class CommentGenerator {
223305 commentStructure . prompt_comment_opening_type = node . prompt_comment_opening_type ?? false ;
224306 return commentStructure ;
225307 }
226- logger . debug ( getMessage ( "arrayNodeContent" , `Json[${ primaryKey } ]` , index , node ) ) ;
227308 }
228309 logger . error ( getMessage ( "languageNotFound" , String ( this . languageId ) , this . fileExtension ) ) ;
229310 return commentStructure ;
0 commit comments