Skip to content

Commit 3185cd3

Browse files
feat(phase-3): Task 3.3.4 - add import metadata extraction
Sub-task 3.3.4: Implement Import Metadata Extraction - Added extractFileImports() method to extract all import statements from a file - Imported extractImportInfo() from metadata-extractor (Phase 2) - Imported ImportInfo type from types/metadata - Returns array of ImportInfo to be included in all chunks Implementation: - Queries tree for import_statement nodes - Uses extractImportInfo() from Phase 2 to parse each import - Returns ImportInfo[] with source, symbols, isDefault, isDynamic, alias - Gracefully handles extraction errors (import extraction is optional) Benefits: - All chunks will have import context as metadata - Addresses Issue RooCodeInc#3 from CHUNKING_ANALYSIS.md (lost import context) - Enables understanding of dependencies and types - Complements Phase 2's metadata extraction This will be integrated in Sub-task 3.3.5 to populate the imports field in CodeBlock: - Extract imports once per file - Include in all chunks from that file - Provides type and dependency context File modified: src/services/code-index/processors/parser.ts (+29 lines) Sub-task 3.3.4 complete! Next: Sub-task 3.3.5 - Implement Smart Chunking Logic
1 parent 3db6c45 commit 3185cd3

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/services/code-index/processors/parser.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import {
1717
import { TelemetryService } from "@roo-code/telemetry"
1818
import { TelemetryEventName } from "@roo-code/types"
1919
import { sanitizeErrorMessage } from "../shared/validation-helpers"
20-
import { extractSymbolMetadata } from "./metadata-extractor"
20+
import { extractSymbolMetadata, extractImportInfo } from "./metadata-extractor"
21+
import { ImportInfo } from "../types/metadata"
2122

2223
/**
2324
* Implementation of the code parser interface
@@ -654,6 +655,33 @@ export class CodeParser implements ICodeParser {
654655
startLine: commentStartLine + 1, // Convert to 1-based
655656
}
656657
}
658+
659+
/**
660+
* Extracts all import statements from a file
661+
* Returns import metadata to be included in all chunks from this file
662+
*/
663+
private extractFileImports(tree: any): ImportInfo[] {
664+
const imports: ImportInfo[] = []
665+
666+
// Query for import statements
667+
const importQuery = `(import_statement) @import`
668+
669+
try {
670+
const matches = tree.rootNode.descendantsOfType("import_statement")
671+
672+
for (const importNode of matches) {
673+
const importInfo = extractImportInfo(importNode)
674+
if (importInfo) {
675+
imports.push(importInfo)
676+
}
677+
}
678+
} catch (error) {
679+
// Silently fail - import extraction is optional
680+
console.debug("Failed to extract imports:", error)
681+
}
682+
683+
return imports
684+
}
657685
}
658686

659687
// Export a singleton instance for convenience

0 commit comments

Comments
 (0)