(chunk: CodeChunk)
| 1019 | } |
| 1020 | |
| 1021 | private generateSummary(chunk: CodeChunk): string { |
| 1022 | const analyzer = chunk.framework ? analyzerRegistry.get(chunk.framework) : null; |
| 1023 | |
| 1024 | if (analyzer && analyzer.summarize) { |
| 1025 | try { |
| 1026 | const summary = analyzer.summarize(chunk); |
| 1027 | // Only use analyzer summary if it's meaningful (not the generic fallback) |
| 1028 | if (summary && !summary.startsWith('Code in ') && !summary.includes(': lines ')) { |
| 1029 | return summary; |
| 1030 | } |
| 1031 | } catch (error) { |
| 1032 | console.warn('Analyzer summary failed:', error); |
| 1033 | } |
| 1034 | } |
| 1035 | |
| 1036 | // Enhanced generic summary |
| 1037 | const fileName = path.basename(chunk.filePath); |
| 1038 | const componentName = chunk.metadata?.componentName; |
| 1039 | const componentType = chunk.componentType; |
| 1040 | |
| 1041 | // Try to extract a meaningful name from content |
| 1042 | const classMatch = (chunk.content ?? '').match( |
| 1043 | /(?:export\s+)?(?:class|interface|type|enum|function)\s+(\w+)/ |
| 1044 | ); |
| 1045 | const name = componentName || (classMatch ? classMatch[1] : null); |
| 1046 | |
| 1047 | if (name && componentType) { |
| 1048 | return `${ |
| 1049 | componentType.charAt(0).toUpperCase() + componentType.slice(1) |
| 1050 | } '${name}' in ${fileName}.`; |
| 1051 | } else if (name) { |
| 1052 | return `'${name}' defined in ${fileName}.`; |
| 1053 | } else if (componentType) { |
| 1054 | return `${componentType.charAt(0).toUpperCase() + componentType.slice(1)} in ${fileName}.`; |
| 1055 | } |
| 1056 | |
| 1057 | // Last resort: describe the file type |
| 1058 | const ext = path.extname(fileName).slice(1); |
| 1059 | const langMap: Record<string, string> = { |
| 1060 | ts: 'TypeScript', |
| 1061 | js: 'JavaScript', |
| 1062 | html: 'HTML template', |
| 1063 | scss: 'SCSS styles', |
| 1064 | css: 'CSS styles', |
| 1065 | json: 'JSON config' |
| 1066 | }; |
| 1067 | return `${langMap[ext] || ext.toUpperCase()} in ${fileName}.`; |
| 1068 | } |
| 1069 | |
| 1070 | private generateSnippet(content: string, maxLines: number = 20): string { |
| 1071 | const lines = content.split('\n'); |
no test coverage detected