|
1 | 1 | import path from 'path'; |
2 | 2 | import fs from 'fs/promises'; |
3 | 3 | import { loadGraph, loadMeta, saveGraph, computeFileHash, getGitCommitHash, isEntryPoint } from '../graph.js'; |
4 | | -import { traverseFiles, detectLanguage } from '../traverser.js'; |
| 4 | +import { traverseFiles, detectLanguage, hasCppSourceFiles, effectiveLanguage } from '../traverser.js'; |
5 | 5 | import { initParser, parseFile } from '../parser.js'; |
6 | 6 | import { detectModuleName } from '../scanner.js'; |
7 | 7 | import { detectChangedFiles, mergeGraphUpdate } from '../differ.js'; |
@@ -37,6 +37,7 @@ export function registerUpdateCommand(program) { |
37 | 37 |
|
38 | 38 | // Step 3: Traverse files and compute current hashes |
39 | 39 | const files = await traverseFiles(rootDir); |
| 40 | + const hasCpp = hasCppSourceFiles(files); |
40 | 41 | const currentHashes = {}; |
41 | 42 |
|
42 | 43 | for (const absPath of files) { |
@@ -66,17 +67,20 @@ export function registerUpdateCommand(program) { |
66 | 67 |
|
67 | 68 | for (const relPath of changedPaths) { |
68 | 69 | const absPath = path.resolve(rootDir, relPath); |
69 | | - const language = detectLanguage(absPath); |
| 70 | + let language = detectLanguage(absPath); |
70 | 71 | if (!language) continue; |
71 | 72 |
|
| 73 | + // Reclassify .h files as C++ when the project contains C++ sources |
| 74 | + language = effectiveLanguage(absPath, language, hasCpp); |
| 75 | + |
72 | 76 | let content; |
73 | 77 | try { |
74 | 78 | content = await fs.readFile(absPath, 'utf-8'); |
75 | 79 | } catch { |
76 | 80 | continue; |
77 | 81 | } |
78 | 82 |
|
79 | | - const hash = computeFileHash(content); |
| 83 | + const hash = currentHashes[relPath]; |
80 | 84 |
|
81 | 85 | let parsed; |
82 | 86 | try { |
|
0 commit comments