1- // src/lib/core.ts
21import * as fs from "fs" ;
32import * as micromatch from "micromatch" ;
43import * as path from "path" ;
54import { parserRegistry } from "../parsers" ;
65import { resolverRegistry } from "../resolvers" ;
7- import { PythonResolver } from "../resolvers/python-resolver" ;
86import { FileContext } from "../types" ;
97import { findProjectRoot , isTextFile } from "../utils" ;
108import { getIgnorePatterns } from "./config" ;
@@ -22,15 +20,13 @@ export class ContextCollector {
2220
2321 this . output . log ( `Using ${ ignorePatterns . length } ignore patterns` ) ;
2422
25- // Recursively discover files while respecting ignore patterns
2623 const filteredFiles = await this . discoverFiles (
2724 workspaceRoot ,
2825 workspaceRoot ,
2926 ignorePatterns ,
3027 ) ;
3128 this . output . log ( `Discovered ${ filteredFiles . length } files after filtering` ) ;
3229
33- // Process files and create contexts
3430 const contexts : FileContext [ ] = [ ] ;
3531 for ( let i = 0 ; i < filteredFiles . length ; i ++ ) {
3632 if ( progressCallback && ! progressCallback ( i + 1 , filteredFiles . length ) ) {
@@ -68,7 +64,6 @@ export class ContextCollector {
6864 const relativePath = path . relative ( workspaceRoot , fullPath ) ;
6965
7066 if ( entry . isDirectory ( ) ) {
71- // For directories, check ignore patterns against both full path and directory name
7267 const directoryName = entry . name ;
7368 const isIgnored =
7469 micromatch . isMatch ( relativePath , ignorePatterns , { dot : true } ) ||
@@ -78,7 +73,6 @@ export class ContextCollector {
7873 micromatch . isMatch ( directoryName , ignorePatterns , { dot : true } ) ;
7974
8075 if ( ! isIgnored ) {
81- // Only recurse into directories that aren't ignored
8276 const subFiles = await this . discoverFiles (
8377 fullPath ,
8478 workspaceRoot ,
@@ -87,7 +81,6 @@ export class ContextCollector {
8781 files . push ( ...subFiles ) ;
8882 }
8983 } else if ( entry . isFile ( ) ) {
90- // For files, check ignore patterns against both full relative path and just filename
9184 const filename = path . basename ( fullPath ) ;
9285 const isIgnored =
9386 micromatch . isMatch ( relativePath , ignorePatterns , { dot : true } ) ||
@@ -120,20 +113,13 @@ export class ContextCollector {
120113 contexts : FileContext [ ] ,
121114 processed : Set < string > ,
122115 workspaceRoot : string ,
123- pythonFiles : Set < string > ,
124116 ) : Promise < void > {
125117 const normalizedPath = path . resolve ( filePath ) ;
126118
127119 if ( processed . has ( normalizedPath ) || ! fs . existsSync ( normalizedPath ) ) {
128120 return ;
129121 }
130122
131- // Collect Python files for batch processing
132- if ( filePath . endsWith ( ".py" ) ) {
133- pythonFiles . add ( normalizedPath ) ;
134- return ;
135- }
136-
137123 processed . add ( normalizedPath ) ;
138124
139125 try {
@@ -150,7 +136,6 @@ export class ContextCollector {
150136 this . output . log ( `${ relativePath } : ${ imports . length } imports` ) ;
151137 }
152138
153- // Use project-specific root for import resolution instead of workspace root
154139 const projectRoot = this . getProjectRootForFile ( normalizedPath ) ;
155140
156141 for ( const importInfo of imports ) {
@@ -166,7 +151,6 @@ export class ContextCollector {
166151 contexts ,
167152 processed ,
168153 workspaceRoot ,
169- pythonFiles ,
170154 ) ;
171155 }
172156 }
@@ -175,74 +159,4 @@ export class ContextCollector {
175159 this . output . error ( `Failed to process: ${ normalizedPath } ` , error ) ;
176160 }
177161 }
178-
179- async processPythonFiles (
180- pythonFiles : Set < string > ,
181- contexts : FileContext [ ] ,
182- processed : Set < string > ,
183- workspaceRoot : string ,
184- ) : Promise < void > {
185- if ( pythonFiles . size === 0 ) {
186- return ;
187- }
188-
189- this . output . log (
190- `Processing ${ pythonFiles . size } Python files with helper...` ,
191- ) ;
192-
193- const resolver = resolverRegistry . getResolver ( "dummy.py" ) as PythonResolver ;
194- const ignorePatterns = getIgnorePatterns ( ) ;
195-
196- try {
197- const allPythonFiles = await resolver . resolveAllImports (
198- Array . from ( pythonFiles ) ,
199- ignorePatterns ,
200- ) ;
201- this . output . log (
202- `Python helper found ${ allPythonFiles . length } total Python files` ,
203- ) ;
204-
205- for ( const pythonFile of allPythonFiles ) {
206- const normalizedPath = path . resolve ( pythonFile ) ;
207-
208- if ( ! processed . has ( normalizedPath ) && fs . existsSync ( normalizedPath ) ) {
209- processed . add ( normalizedPath ) ;
210-
211- try {
212- const content = fs . readFileSync ( normalizedPath , "utf8" ) ;
213- const relativePath = path . relative ( workspaceRoot , normalizedPath ) ;
214- contexts . push ( { path : normalizedPath , content, relativePath } ) ;
215- } catch ( error ) {
216- this . output . error (
217- `Failed to read Python file: ${ normalizedPath } ` ,
218- error ,
219- ) ;
220- }
221- }
222- }
223- } catch ( error ) {
224- this . output . error (
225- `Python helper failed, processing files individually` ,
226- error ,
227- ) ;
228-
229- // Fallback: add Python files without import resolution
230- for ( const pythonFile of pythonFiles ) {
231- if ( ! processed . has ( pythonFile ) ) {
232- processed . add ( pythonFile ) ;
233-
234- try {
235- const content = fs . readFileSync ( pythonFile , "utf8" ) ;
236- const relativePath = path . relative ( workspaceRoot , pythonFile ) ;
237- contexts . push ( { path : pythonFile , content, relativePath } ) ;
238- } catch ( error ) {
239- this . output . error (
240- `Failed to read Python file: ${ pythonFile } ` ,
241- error ,
242- ) ;
243- }
244- }
245- }
246- }
247- }
248162}
0 commit comments