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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user