/** * Symbol Extraction & Complexity Metrics Engine (SMCP-090) * * Extracts symbols (functions, classes, imports, exports) from code files * and calculates complexity metrics. Uses Tree-sitter for AST parsing. * * Features: * - Extract functions, classes, methods, interfaces * - Extract imports and exports * - Calculate cyclomatic complexity * - Calculate nesting depth * - Calculate overall complexity score * - Fast extraction (< 100ms per typical file) * * Inspired by code-index-mcp's get_file_summary capability. * * @module symbolExtractor */ import { type ASTLanguage } from './treeSitterParser.js'; /** * Information about a symbol (function, class, method, etc.) */ export interface SymbolInfo { /** Symbol name */ name: string; /** Symbol type */ type: 'function' | 'class' | 'method' | 'interface' | 'type' | 'enum' | 'struct' | 'trait' | 'variable' | 'constant'; /** Start line (1-based) */ startLine: number; /** End line (1-based) */ endLine: number; /** Function/method signature (for functions/methods) */ signature?: string; /** Docstring or comment */ docstring?: string; /** Whether the symbol is exported */ isExported?: boolean; /** Whether the symbol is async (for functions/methods) */ isAsync?: boolean; /** Whether the symbol is static (for methods) */ isStatic?: boolean; /** Visibility modifier */ visibility?: 'public' | 'private' | 'protected'; /** Parameter count (for functions/methods) */ paramCount?: number; /** Return type (if available) */ returnType?: string; /** Parent symbol name (for methods in classes) */ parentName?: string; /** Decorators/annotations */ decorators?: string[]; /** Cyclomatic complexity (for functions/methods) */ complexity?: number; /** Maximum nesting depth */ nestingDepth?: number; } /** * Import information */ export interface ImportInfo { /** The module/package being imported */ module: string; /** Named imports (e.g., { foo, bar } from 'module') */ names?: string[]; /** Default import name */ defaultImport?: string; /** Whether it's a namespace import (import * as X) */ isNamespace?: boolean; /** Line number */ line: number; } /** * Export information */ export interface ExportInfo { /** Exported name */ name: string; /** Export type */ type: 'named' | 'default' | 'reexport' | 'namespace'; /** Original name if renamed (export { foo as bar }) */ originalName?: string; /** Source module for re-exports */ sourceModule?: string; /** Line number */ line: number; } /** * Complexity metrics for a file */ export interface ComplexityMetrics { /** Total cyclomatic complexity (sum of all functions) */ cyclomaticComplexity: number; /** Maximum nesting depth in the file */ maxNestingDepth: number; /** Average function complexity */ avgFunctionComplexity: number; /** Number of decision points (if, while, for, &&, ||, etc.) */ decisionPoints: number; /** Overall complexity score (0-100) */ overallScore: number; } /** * File summary with symbols and complexity metrics */ export interface FileSummary { /** Absolute file path */ path: string; /** Relative file path (from project root) */ relativePath: string; /** Detected programming language */ language: ASTLanguage | string; /** Total lines of code */ lines: number; /** Lines of actual code (excluding blank lines and comments) */ codeLines: number; /** Number of blank lines */ blankLines: number; /** Number of comment lines */ commentLines: number; /** Functions and methods */ functions: SymbolInfo[]; /** Classes, interfaces, structs, etc. */ classes: SymbolInfo[]; /** Import statements */ imports: ImportInfo[]; /** Export statements */ exports: ExportInfo[]; /** Complexity metrics */ complexity: ComplexityMetrics; /** File size in bytes */ size: number; /** Extraction duration in milliseconds */ extractionTimeMs: number; } /** * Options for symbol extraction */ export interface SymbolExtractionOptions { /** Include complexity metrics (default: true) */ includeComplexity?: boolean; /** Include docstrings (default: true) */ includeDocstrings?: boolean; /** Maximum file size to process in bytes (default: 1MB) */ maxFileSize?: number; } /** * Default extraction options */ export declare const DEFAULT_EXTRACTION_OPTIONS: Required; /** * Extract file summary with symbols and complexity metrics * * @param sourceCode - Source code content * @param absolutePath - Absolute file path * @param relativePath - Relative file path from project root * @param options - Extraction options * @returns FileSummary or null if extraction fails */ export declare function extractFileSummary(sourceCode: string, absolutePath: string, relativePath: string, options?: SymbolExtractionOptions): Promise; /** * Quick check if a file type supports symbol extraction * * @param filePath - File path to check * @returns true if symbol extraction is supported */ export declare function supportsSymbolExtraction(filePath: string): boolean; /** * Get the list of supported languages for symbol extraction * * @returns Array of supported language names */ export declare function getSupportedLanguages(): ASTLanguage[]; //# sourceMappingURL=symbolExtractor.d.ts.map