MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / extractFromSource

Function extractFromSource

src/extraction/tree-sitter.ts:6661–6767  ·  view source on GitHub ↗
(
  filePath: string,
  source: string,
  language?: Language,
  frameworkNames?: string[]
)

Source from the content-addressed store, hash-verified

6659 * Their nodes/references/errors are merged into the returned result.
6660 */
6661export function extractFromSource(
6662 filePath: string,
6663 source: string,
6664 language?: Language,
6665 frameworkNames?: string[]
6666): ExtractionResult {
6667 const detectedLanguage = language || detectLanguage(filePath, source);
6668 const fileExtension = path.extname(filePath).toLowerCase();
6669
6670 let result: ExtractionResult;
6671
6672 // Use custom extractor for Svelte
6673 if (detectedLanguage === 'svelte') {
6674 const extractor = new SvelteExtractor(filePath, source);
6675 result = extractor.extract();
6676 } else if (detectedLanguage === 'vue') {
6677 // Use custom extractor for Vue
6678 const extractor = new VueExtractor(filePath, source);
6679 result = extractor.extract();
6680 } else if (detectedLanguage === 'astro') {
6681 // Use custom extractor for Astro (frontmatter + template delegation)
6682 const extractor = new AstroExtractor(filePath, source);
6683 result = extractor.extract();
6684 } else if (detectedLanguage === 'liquid') {
6685 // Use custom extractor for Liquid
6686 const extractor = new LiquidExtractor(filePath, source);
6687 result = extractor.extract();
6688 } else if (detectedLanguage === 'razor') {
6689 // Use custom extractor for ASP.NET Razor (.cshtml) / Blazor (.razor) markup
6690 const extractor = new RazorExtractor(filePath, source);
6691 result = extractor.extract();
6692 } else if (detectedLanguage === 'xml') {
6693 // Custom extractor for MyBatis mapper XML. Non-mapper XML returns just a
6694 // file node so the watcher tracks it without emitting symbols.
6695 const extractor = new MyBatisExtractor(filePath, source);
6696 result = extractor.extract();
6697 } else if (detectedLanguage === 'cfml' || detectedLanguage === 'cfscript') {
6698 // Custom extractor for CFML (.cfc/.cfm) — dialect-switches between the
6699 // tag-based cfml grammar and the bare-script cfscript grammar. Standalone
6700 // `.cfs` files (language 'cfscript') are always pure script (never `<`-led),
6701 // so routing them through here too gets them the same anonymous-component
6702 // filename fallback as a bare-script `.cfc` — without it a `.cfs` whose
6703 // `component { ... }` declares no name (the grammar has no `name` field;
6704 // CFML never spells one in source) stays `<anonymous>`.
6705 const extractor = new CfmlExtractor(filePath, source, detectedLanguage);
6706 result = extractor.extract();
6707 } else if (isFileLevelOnlyLanguage(detectedLanguage)) {
6708 // No symbol extraction at this stage — files are tracked at the file-record
6709 // level only. Framework extractors (Drupal routing yml, Spring `@Value`
6710 // resolution against application.yml/application.properties) run later and
6711 // add per-file nodes/references when they apply.
6712 result = { nodes: [], edges: [], unresolvedReferences: [], errors: [], durationMs: 0 };
6713 } else if (
6714 detectedLanguage === 'pascal' &&
6715 (fileExtension === '.dfm' || fileExtension === '.fmx')
6716 ) {
6717 // Use custom extractor for DFM/FMX form files
6718 const extractor = new DfmExtractor(filePath, source);

Callers 15

extractFromSourceMethod · 0.90
parseFileMethod · 0.90
indexFileWithContentMethod · 0.90
parse-worker.tsFile · 0.90
assertParityFunction · 0.90
assertParityFunction · 0.90
assertParityFunction · 0.90
assertParityFunction · 0.90

Calls 8

extractMethod · 0.95
detectLanguageFunction · 0.90
isFileLevelOnlyLanguageFunction · 0.90
tryKernelExtractFunction · 0.90
takeDeferredPreParseFunction · 0.90
getAllFrameworkResolversFunction · 0.90
getApplicableFrameworksFunction · 0.90
extractMethod · 0.65

Tested by 15

assertParityFunction · 0.72
assertParityFunction · 0.72
assertParityFunction · 0.72
assertParityFunction · 0.72
assertParityFunction · 0.72
assertParityFunction · 0.72
assertParityFunction · 0.72
methodNodesFunction · 0.72
resultFunction · 0.72
assertParityFunction · 0.72
assertParityFunction · 0.72
docFunction · 0.72