MCPcopy
hub / github.com/colbymchenry/codegraph / detectLanguage

Function detectLanguage

src/extraction/grammars.ts:280–297  ·  view source on GitHub ↗
(filePath: string, source?: string, overrides?: Record<string, Language>)

Source from the content-addressed store, hash-verified

278 * `EXTENSION_MAP`. Omitting it is byte-identical to the zero-config behavior.
279 */
280export function detectLanguage(filePath: string, source?: string, overrides?: Record<string, Language>): Language {
281 // Play `conf/routes` has no grammar — route through the no-symbol path; the
282 // Play framework resolver extracts route nodes from it.
283 if (isPlayRoutesFile(filePath)) return 'yaml';
284 const ext = filePath.substring(filePath.lastIndexOf('.')).toLowerCase();
285 // Shopify OS 2.0 JSON templates / section groups → the Liquid extractor (it
286 // links each section `"type"` to its `sections/<type>.liquid`).
287 if (isShopifyLiquidJson(filePath)) return 'liquid';
288 const lang = (overrides && overrides[ext]) || EXTENSION_MAP[ext] || 'unknown';
289
290 // .h files could be C, C++, or Objective-C — check source content
291 if (lang === 'c' && ext === '.h' && source) {
292 if (looksLikeCpp(source)) return 'cpp';
293 if (looksLikeObjc(source)) return 'objc';
294 }
295
296 return lang;
297}
298
299/**
300 * Heuristic: does a .h file contain C++ constructs?

Callers 10

indexAllMethod · 0.90
parseFileMethod · 0.90
storeResultMethod · 0.90
indexFileWithContentMethod · 0.90
syncMethod · 0.90
parse-worker.tsFile · 0.90
constructorMethod · 0.90
extractFromSourceFunction · 0.90
extraction.test.tsFile · 0.90

Calls 4

isPlayRoutesFileFunction · 0.85
isShopifyLiquidJsonFunction · 0.85
looksLikeCppFunction · 0.85
looksLikeObjcFunction · 0.85

Tested by

no test coverage detected