* Parse file and extract LLM workflow locations using tree-sitter
(code: string, filePath: string)
| 34 | * Parse file and extract LLM workflow locations using tree-sitter |
| 35 | */ |
| 36 | analyze(code: string, filePath: string): FileAnalysis { |
| 37 | const language = ParserManager.getLanguageForFile(filePath); |
| 38 | if (!language || !ParserManager.isAvailable()) { |
| 39 | console.warn(`Unsupported file type or parser unavailable for: ${filePath}`); |
| 40 | return { |
| 41 | filePath, |
| 42 | locations: [], |
| 43 | imports: [], |
| 44 | exports: [], |
| 45 | llmRelatedVariables: new Set() |
| 46 | }; |
| 47 | } |
| 48 | |
| 49 | try { |
| 50 | const manager = ParserManager.get(); |
| 51 | const tree = manager.parse(code, language, filePath); |
| 52 | const result = extractFileAnalysisFromTree( |
| 53 | tree, |
| 54 | language, |
| 55 | filePath, |
| 56 | code, |
| 57 | (name: string) => this.isLLMIdentifier(name), |
| 58 | ); |
| 59 | tree.delete(); |
| 60 | |
| 61 | return { |
| 62 | filePath, |
| 63 | locations: result.locations as CodeLocation[], |
| 64 | imports: result.imports, |
| 65 | exports: result.exports, |
| 66 | llmRelatedVariables: result.llmRelatedVariables, |
| 67 | }; |
| 68 | } catch (error) { |
| 69 | console.error(`Failed to parse ${filePath}:`, error); |
| 70 | if (error instanceof Error) { |
| 71 | console.error(`Error details: ${error.message}`); |
| 72 | } |
| 73 | return { |
| 74 | filePath, |
| 75 | locations: [], |
| 76 | imports: [], |
| 77 | exports: [], |
| 78 | llmRelatedVariables: new Set() |
| 79 | }; |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | export const staticAnalyzer = new StaticAnalyzer(); |
no test coverage detected