feat: Add content-based C++ detection for .h headers

Addresses C++ classes missing from .h files where extension-based detection defaults to 'c' language which has no class extraction support. Adds looksLikeCpp() heuristic that scans first 8KB for C++-specific patterns (namespace, class, template, access specifiers) to promote .h files to 'cpp' language when C++ constructs are detected. Ensures cpp grammar is loaded alongside c to handle potential .h promotion during parsing.
This commit is contained in:
Colby McHenry
2026-04-06 23:38:13 -05:00
parent 237fb3b206
commit 4a8d2f0396
5 changed files with 36 additions and 11 deletions
+2 -2
View File
@@ -106,7 +106,7 @@ export class TreeSitterExtractor {
constructor(filePath: string, source: string, language?: Language) {
this.filePath = filePath;
this.source = source;
this.language = language || detectLanguage(filePath);
this.language = language || detectLanguage(filePath, source);
this.extractor = EXTRACTORS[this.language] || null;
}
@@ -2087,7 +2087,7 @@ export function extractFromSource(
source: string,
language?: Language
): ExtractionResult {
const detectedLanguage = language || detectLanguage(filePath);
const detectedLanguage = language || detectLanguage(filePath, source);
const fileExtension = path.extname(filePath).toLowerCase();
// Use custom extractor for Svelte