MCPcopy Create free account
hub / github.com/codag-megalith/codag-visualizer / analyze

Method analyze

frontend/src/static-analyzer.ts:36–81  ·  view source on GitHub ↗

* Parse file and extract LLM workflow locations using tree-sitter

(code: string, filePath: string)

Source from the content-addressed store, hash-verified

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
84export const staticAnalyzer = new StaticAnalyzer();

Callers 4

hashContentASTMethod · 0.80
detectWorkflowMethod · 0.80
buildMetadataMethod · 0.80

Calls 7

isLLMIdentifierMethod · 0.95
getLanguageForFileMethod · 0.80
isAvailableMethod · 0.80
parseMethod · 0.80
getMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected