@opichi/smartcode
Version:
Universal code intelligence MCP server - analyze any codebase with TypeScript excellence and multi-language support
185 lines • 4.6 kB
TypeScript
/**
* TypeScript/JavaScript Code Analyzer using TypeScript Compiler API
* Provides fast, precise code analysis for MCP tools
*/
export interface Symbol {
name: string;
kind: string;
file: string;
line: number;
column: number;
signature?: string;
documentation?: string;
modifiers?: string[];
}
export interface Match {
file: string;
line: number;
column: number;
content: string;
context: string[];
functionContext?: string;
matchedText?: string;
importance?: number;
}
export interface FileStructure {
file: string;
imports: ImportInfo[];
exports: ExportInfo[];
functions: FunctionInfo[];
classes: ClassInfo[];
interfaces: InterfaceInfo[];
types: TypeInfo[];
variables: VariableInfo[];
}
export interface ImportInfo {
name: string;
from: string;
isDefault: boolean;
isNamespace: boolean;
}
export interface ExportInfo {
name: string;
kind: string;
isDefault: boolean;
}
export interface FunctionInfo {
name: string;
parameters: ParameterInfo[];
returnType?: string;
isAsync: boolean;
isExported: boolean;
line: number;
documentation?: string;
}
export interface ClassInfo {
name: string;
methods: MethodInfo[];
properties: PropertyInfo[];
extends?: string;
implements: string[];
isExported: boolean;
line: number;
documentation?: string;
}
export interface InterfaceInfo {
name: string;
properties: PropertyInfo[];
extends: string[];
isExported: boolean;
line: number;
documentation?: string;
}
export interface TypeInfo {
name: string;
definition: string;
isExported: boolean;
line: number;
documentation?: string;
}
export interface VariableInfo {
name: string;
type?: string;
isConst: boolean;
isExported: boolean;
line: number;
value?: string;
}
export interface ParameterInfo {
name: string;
type?: string;
isOptional: boolean;
defaultValue?: string;
}
export interface MethodInfo {
name: string;
parameters: ParameterInfo[];
returnType?: string;
isAsync: boolean;
isStatic: boolean;
visibility: 'public' | 'private' | 'protected';
line: number;
documentation?: string;
}
export interface PropertyInfo {
name: string;
type?: string;
isOptional: boolean;
isReadonly: boolean;
visibility: 'public' | 'private' | 'protected';
line: number;
documentation?: string;
}
export interface SearchOptions {
fileTypes?: string[];
includePatterns?: string[];
excludePatterns?: string[];
caseSensitive?: boolean;
wholeWord?: boolean;
regex?: boolean;
}
export declare class TypeScriptAnalyzer {
private projectRoot;
private program;
private typeChecker;
constructor(projectRoot: string);
/**
* Initialize the TypeScript program for analysis
*/
private initializeProgram;
/**
* Find tsconfig.json in project hierarchy
*/
private findTsConfig;
/**
* Find all TypeScript/JavaScript source files
*/
private findSourceFiles;
/**
* Find symbols by name across the project
*/
findSymbols(name: string, scope?: string): Promise<Symbol[]>;
/**
* Search for code patterns across the project with enhanced context and filtering
*/
searchCode(pattern: string, options?: SearchOptions): Promise<Match[]>;
/**
* Filter and rank files by importance for more relevant search results
*/
private filterAndRankFiles;
/**
* Calculate importance score for a match based on context
*/
private calculateMatchImportance;
/**
* Analyze complete structure of a file
*/
analyzeFile(filePath: string): Promise<FileStructure | null>;
/**
* Analyze non-TypeScript files using simple text parsing
*/
private analyzeGenericFile;
/**
* Create symbol from TypeScript node
*/
private createSymbolFromNode;
private getNodeName;
private getNodeKind;
private getNodeSignature;
private getNodeDocumentation;
private getNodeModifiers;
private extractImports;
private extractExports;
private extractFunctionInfo;
private extractClassInfo;
private extractInterfaceInfo;
private extractTypeInfo;
private extractVariables;
private extractParameters;
/**
* Detect the surrounding function/method context for a given line number
*/
private detectSurroundingFunction;
private escapeRegex;
}
//# sourceMappingURL=typescript.d.ts.map