Coverage for src\llm_code_lens\processors\insights.py: 0%

43 statements  

« prev     ^ index     » next       coverage.py v7.7.0, created at 2025-05-25 12:07 +0300

1""" 

2LLM Code Lens - Insights Generator 

3Generates insights from code analysis results. 

4""" 

5 

6from typing import Dict, List 

7from pathlib import Path 

8from ..utils import estimate_todo_priority 

9 

10def generate_insights(analysis: Dict[str, dict]) -> List[str]: 

11 """ 

12 Generate insights from code analysis results. 

13  

14 Args: 

15 analysis: Dictionary of file paths to analysis results 

16  

17 Returns: 

18 List of insight strings 

19 """ 

20 insights = [] 

21 

22 # Basic project stats 

23 total_files = len(analysis) if isinstance(analysis, dict) else 0 

24 if total_files == 1: 

25 insights.append("Found 1 analyzable file") 

26 elif total_files > 0: 

27 insights.append(f"Found {total_files} analyzable files") 

28 

29 # Track various metrics 

30 todo_count = 0 

31 todo_priorities = {'high': 0, 'medium': 0, 'low': 0} 

32 undocumented_count = 0 

33 complex_functions = [] 

34 memory_leaks = 0 

35 

36 for file_path, file_analysis in analysis.items(): 

37 if not isinstance(file_analysis, dict): 

38 continue 

39 

40 # Process TODOs 

41 for todo in file_analysis.get('todos', []): 

42 todo_count += 1 

43 text = todo.get('text', '').lower() 

44 priority = estimate_todo_priority(text) 

45 todo_priorities[priority] += 1 

46 

47 # Check for memory leak TODOs 

48 if 'memory leak' in text: 

49 memory_leaks += 1 

50 

51 # Process functions 

52 for func in file_analysis.get('functions', []): 

53 if not func.get('docstring'): 

54 undocumented_count += 1 

55 if func.get('complexity', 0) > 5 or func.get('loc', 0) > 50: 

56 complex_functions.append(f"{func.get('name', 'unnamed')} in {file_path}") 

57 

58 # Add insights based on findings 

59 if todo_count > 0: 

60 insights.append(f"Found {todo_count} TODOs across {total_files} files") 

61 if todo_priorities['high'] > 0: 

62 insights.append(f"Found {todo_priorities['high']} high-priority TODOs") 

63 

64 if memory_leaks > 0: 

65 insights.append(f"Found {memory_leaks} potential memory leak issues") 

66 

67 if complex_functions: 

68 if len(complex_functions) <= 3: 

69 insights.append(f"Complex functions detected: {', '.join(complex_functions)}") 

70 else: 

71 insights.append(f"Found {len(complex_functions)} complex functions that might need attention") 

72 

73 if undocumented_count > 0: 

74 insights.append(f"Found {undocumented_count} undocumented functions") 

75 

76 return insights