@bobmatnyc/ai-code-review
Version:
A TypeScript-based tool for automated code reviews using AI models from Google Gemini, Anthropic Claude, and OpenRouter
170 lines (169 loc) • 4.34 kB
TypeScript
/**
* @fileoverview TreeSitter-based semantic analyzer for intelligent code chunking
*
* This module provides the core semantic analysis engine that uses TreeSitter
* to parse code into AST representations and extract meaningful structural
* information for AI-guided chunking decisions.
*/
import { SemanticAnalysisResult, SemanticAnalysisConfig } from './types';
/**
* TreeSitter semantic analyzer engine
*/
export declare class SemanticAnalyzer {
private parsers;
private config;
private aiGuidedChunking;
constructor(config?: Partial<SemanticAnalysisConfig>);
/**
* Initialize TreeSitter parsers for supported languages
*/
private initializeParsers;
/**
* Perform semantic analysis on code content
*/
analyzeCode(content: string, filePath: string, language?: string): Promise<SemanticAnalysisResult>;
/**
* Perform the core semantic analysis
*/
private performAnalysis;
/**
* Extract declarations from the AST
*/
private extractDeclarations;
/**
* Extract TypeScript/JavaScript declarations
*/
private extractTSDeclarations;
/**
* Extract Python declarations
*/
private extractPythonDeclarations;
/**
* Extract Ruby declarations
*/
private extractRubyDeclarations;
/**
* Extract PHP declarations
*/
private extractPHPDeclarations;
/**
* Create a Declaration object from an AST node
*/
private createDeclarationFromNode;
/**
* Extract the name from an AST node based on node type
*/
private extractNodeName;
/**
* Extract dependencies from a node
*/
private extractDependencies;
/**
* Calculate cyclomatic complexity for a node
*/
private calculateNodeComplexity;
/**
* Determine export status of a declaration
*/
private determineExportStatus;
/**
* Extract documentation/comments for a node
*/
private extractDocumentation;
/**
* Extract child declarations (e.g., methods in a class)
*/
private extractChildDeclarations;
/**
* Extract modifiers from a node
*/
private extractModifiers;
/**
* Extract import relationships
*/
private extractImports;
/**
* Check if a node represents an import
*/
private isImportNode;
/**
* Create an ImportRelationship from a node
*/
private createImportRelationship;
/**
* Extract imported name from import node
*/
private extractImportedName;
/**
* Extract import source from import node
*/
private extractImportSource;
/**
* Determine the type of import
*/
private determineImportType;
/**
* Calculate complexity metrics for the entire file
*/
private calculateComplexity;
/**
* Calculate maximum nesting depth
*/
private calculateMaxNesting;
/**
* Check if node represents a block structure
*/
private isBlockNode;
/**
* Check if node adds to complexity
*/
private isComplexityNode;
/**
* Calculate Halstead complexity metrics
*/
private calculateHalsteadMetrics;
/**
* Check if node is an operator
*/
private isOperator;
/**
* Check if node is an operand
*/
private isOperand;
/**
* Generate AI-guided chunking recommendation
*/
private generateChunkingRecommendation;
/**
* Generate rule-based chunking recommendation as fallback
*/
private generateRuleBasedChunking;
/**
* Traverse AST node recursively
*/
private traverseNode;
/**
* Detect programming language from file path
*/
private detectLanguage;
/**
* Check if language is supported
*/
private isLanguageSupported;
/**
* Get list of supported languages
*/
getSupportedLanguages(): string[];
/**
* Update configuration
*/
updateConfig(config: Partial<SemanticAnalysisConfig>): void;
}
/**
* Default semantic analyzer instance
*/
export declare const semanticAnalyzer: SemanticAnalyzer;
/**
* Convenience function for analyzing code
*/
export declare function analyzeCodeSemantics(content: string, filePath: string, language?: string): Promise<SemanticAnalysisResult>;