Asper Header  1.0.14
The header injector extension
Loading...
Searching...
No Matches
CommentGenerator Class Reference

Intelligent file header generation and management system. More...

Collaboration diagram for CommentGenerator:
Collaboration graph

Public Member Functions

 constructor (languageComment:LazyFileLoader|undefined=undefined, editor:vscode.TextEditor|undefined=undefined, randomLogoInstance:RandomLogo|undefined=undefined)
 Constructor for CommentGenerator class.
 

Protected Member Functions

 locateIfHeaderPresent (comments:string[])
 Scans document to detect existing header presence and boundaries.
 

Detailed Description

Intelligent file header generation and management system.


The CommentGenerator class serves as the central orchestrator for all header-related operations within the AsperHeader extension. It provides comprehensive functionality for creating, updating, and maintaining file headers with rich metadata, ASCII art logos, and language-appropriate comment formatting.

Core Responsibilities:

  • Header Lifecycle Management: Creation, injection, refresh, and validation
  • Language Adaptation: Automatic detection and appropriate comment style selection
  • Template Processing: Dynamic variable substitution in header templates
  • Logo Integration: Seamless integration with RandomLogo for ASCII art
  • Metadata Tracking: Creation timestamps, modification dates, and file properties
  • User Interaction: Prompting for missing information and configuration

Architectural Features:

  • Lazy Loading: Language configurations loaded on-demand for performance
  • Configuration Integration: Deep coupling with Configuration settings
  • Error Resilience: Comprehensive error handling and user feedback
  • Workspace Awareness: Context-sensitive behavior based on workspace state
  • Multi-Language Support: Extensible system supporting diverse programming languages

Header Structure: Generated headers follow a structured format including:

  • Opening decoration and logo placement
  • Project identification and file metadata
  • Creation and modification timestamps
  • Description, purpose, and copyright information
  • Telegraph protocol markers for structured communication
  • Closing decoration and formatting

Performance Considerations:

  • Language configurations cached after first load
  • Header parsing optimized for large files
  • Minimal VS Code API calls to reduce overhead
  • Efficient string manipulation and template processing
Examples
Advanced, Basic, and Integration.

Definition at line 135 of file commentGenerator.ts.

Member Function Documentation

◆ constructor()

CommentGenerator::constructor ( languageComment:LazyFileLoader| undefined = undefined,
editor:vscode.TextEditor| undefined = undefined,
randomLogoInstance:RandomLogo| undefined = undefined )
inline

Constructor for CommentGenerator class.

Parameters
languageCommentOptional lazy loader for language comment configurations
editorOptional VS Code text editor instance
randomLogoInstanceOptional random logo generator instance

Initializes the comment generator with optional dependencies. If any parameter is undefined, appropriate warnings are logged and defaults are used.

Definition at line 180 of file commentGenerator.ts.

◆ locateIfHeaderPresent()

CommentGenerator::locateIfHeaderPresent ( comments:string[])
inlineprotected

Scans document to detect existing header presence and boundaries.

Parameters
commentsArray of comment prefixes [opener, middle, closer]
Returns
true if valid header found, false if no/broken header, undefined on error

Searches the document within maxScanLength lines for header opener and closer patterns. Sets headerInnerStart and headerInnerEnd properties when valid header is found. Detects broken headers (mismatched/missing opener/closer).

Writes a new header to the beginning of the file

Parameters
editorVS Code text editor instance
commentsArray of comment prefixes [opener, middle, closer]
Returns
Promise resolving to status code (success/error)

Generates a complete header using buildTheHeader() and inserts it at the top of the document. Handles shebang line detection and offset calculation.

Main method to inject or update header in active editor

Primary entry point for header injection functionality. Performs:

  1. Validates active editor and file metadata
  2. Determines appropriate comment style for the language
  3. Checks for existing header presence
  4. Updates existing header timestamp OR writes new header

This method is typically called by user command activation.

Definition at line 768 of file commentGenerator.ts.


The documentation for this class was generated from the following file: