Coverage for src\llm_code_lens\utils.py: 0%

28 statements  

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

1""" 

2LLM Code Lens - Utility Functions 

3Shared utility functions used across multiple modules. 

4""" 

5 

6from typing import Dict, List, Set, Optional 

7 

8def estimate_todo_priority(text: str) -> str: 

9 """ 

10 Estimate TODO priority based on content. 

11  

12 Args: 

13 text: The text of the TODO comment 

14  

15 Returns: 

16 Priority level: 'high', 'medium', or 'low' 

17 """ 

18 text = text.lower() 

19 if any(word in text for word in ['urgent', 'critical', 'fixme', 'bug', 'memory leak', 'security']): 

20 return 'high' 

21 if any(word in text for word in ['important', 'needed', 'should']): 

22 return 'medium' 

23 return 'low' 

24 

25def is_potential_entry_point(file_path: str, analysis: dict) -> bool: 

26 """ 

27 Identify if a file is a potential entry point. 

28  

29 Args: 

30 file_path: Path to the file 

31 analysis: Analysis data for the file 

32  

33 Returns: 

34 bool: True if the file is likely an entry point 

35 """ 

36 from pathlib import Path 

37 

38 filename = Path(file_path).name 

39 if filename in {'main.py', 'app.py', 'cli.py', 'server.py', 'index.js', 'server.js'}: 

40 return True 

41 

42 # Check for main-like functions 

43 for func in analysis.get('functions', []): 

44 if func.get('name') in {'main', 'run', 'start', 'cli', 'execute'}: 

45 return True 

46 

47 return False 

48 

49def is_core_file(analysis: dict) -> bool: 

50 """ 

51 Identify if a file is likely a core component. 

52  

53 Args: 

54 analysis: Analysis data for the file 

55  

56 Returns: 

57 bool: True if the file is likely a core component 

58 """ 

59 # Check function count 

60 if len(analysis.get('functions', [])) > 5: 

61 return True 

62 

63 # Check class count 

64 if len(analysis.get('classes', [])) > 2: 

65 return True 

66 

67 # Check function complexity 

68 complex_funcs = sum(1 for f in analysis.get('functions', []) 

69 if (f.get('complexity', 0) > 5 or 

70 f.get('loc', 0) > 50 or 

71 len(f.get('args', [])) > 3)) 

72 if complex_funcs >= 1: 

73 return True 

74 

75 # Check file complexity 

76 if analysis.get('metrics', {}).get('complexity', 0) > 20: 

77 return True 

78 

79 return False