tree-sitter-analyzer 0.3.0__py3-none-any.whl → 0.6.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of tree-sitter-analyzer might be problematic. Click here for more details.

Files changed (63) hide show
  1. tree_sitter_analyzer/__init__.py +5 -6
  2. tree_sitter_analyzer/__main__.py +2 -2
  3. tree_sitter_analyzer/api.py +4 -2
  4. tree_sitter_analyzer/cli/__init__.py +3 -3
  5. tree_sitter_analyzer/cli/commands/advanced_command.py +1 -1
  6. tree_sitter_analyzer/cli/commands/base_command.py +1 -1
  7. tree_sitter_analyzer/cli/commands/default_command.py +1 -1
  8. tree_sitter_analyzer/cli/commands/partial_read_command.py +2 -2
  9. tree_sitter_analyzer/cli/commands/query_command.py +5 -5
  10. tree_sitter_analyzer/cli/commands/summary_command.py +2 -2
  11. tree_sitter_analyzer/cli/commands/table_command.py +14 -11
  12. tree_sitter_analyzer/cli/info_commands.py +14 -13
  13. tree_sitter_analyzer/cli_main.py +51 -31
  14. tree_sitter_analyzer/core/analysis_engine.py +54 -90
  15. tree_sitter_analyzer/core/cache_service.py +31 -31
  16. tree_sitter_analyzer/core/engine.py +6 -4
  17. tree_sitter_analyzer/core/parser.py +1 -1
  18. tree_sitter_analyzer/core/query.py +502 -494
  19. tree_sitter_analyzer/encoding_utils.py +3 -2
  20. tree_sitter_analyzer/exceptions.py +23 -23
  21. tree_sitter_analyzer/file_handler.py +7 -14
  22. tree_sitter_analyzer/formatters/base_formatter.py +18 -18
  23. tree_sitter_analyzer/formatters/formatter_factory.py +15 -15
  24. tree_sitter_analyzer/formatters/java_formatter.py +291 -287
  25. tree_sitter_analyzer/formatters/python_formatter.py +259 -255
  26. tree_sitter_analyzer/interfaces/cli.py +1 -1
  27. tree_sitter_analyzer/interfaces/cli_adapter.py +62 -41
  28. tree_sitter_analyzer/interfaces/mcp_adapter.py +43 -17
  29. tree_sitter_analyzer/interfaces/mcp_server.py +9 -9
  30. tree_sitter_analyzer/language_detector.py +398 -398
  31. tree_sitter_analyzer/language_loader.py +224 -224
  32. tree_sitter_analyzer/languages/java_plugin.py +1174 -1129
  33. tree_sitter_analyzer/{plugins → languages}/javascript_plugin.py +3 -3
  34. tree_sitter_analyzer/languages/python_plugin.py +26 -8
  35. tree_sitter_analyzer/mcp/resources/code_file_resource.py +0 -3
  36. tree_sitter_analyzer/mcp/resources/project_stats_resource.py +555 -560
  37. tree_sitter_analyzer/mcp/server.py +4 -4
  38. tree_sitter_analyzer/mcp/tools/analyze_scale_tool.py +63 -30
  39. tree_sitter_analyzer/mcp/tools/analyze_scale_tool_cli_compatible.py +9 -4
  40. tree_sitter_analyzer/mcp/tools/table_format_tool.py +2 -2
  41. tree_sitter_analyzer/mcp/utils/__init__.py +10 -8
  42. tree_sitter_analyzer/models.py +470 -470
  43. tree_sitter_analyzer/output_manager.py +12 -20
  44. tree_sitter_analyzer/plugins/__init__.py +9 -62
  45. tree_sitter_analyzer/plugins/base.py +53 -1
  46. tree_sitter_analyzer/plugins/manager.py +29 -12
  47. tree_sitter_analyzer/queries/java.py +78 -78
  48. tree_sitter_analyzer/queries/javascript.py +7 -7
  49. tree_sitter_analyzer/queries/python.py +18 -18
  50. tree_sitter_analyzer/queries/typescript.py +12 -12
  51. tree_sitter_analyzer/query_loader.py +17 -14
  52. tree_sitter_analyzer/table_formatter.py +24 -19
  53. tree_sitter_analyzer/utils.py +7 -7
  54. {tree_sitter_analyzer-0.3.0.dist-info → tree_sitter_analyzer-0.6.0.dist-info}/METADATA +11 -11
  55. tree_sitter_analyzer-0.6.0.dist-info/RECORD +72 -0
  56. {tree_sitter_analyzer-0.3.0.dist-info → tree_sitter_analyzer-0.6.0.dist-info}/entry_points.txt +2 -1
  57. tree_sitter_analyzer/java_analyzer.py +0 -218
  58. tree_sitter_analyzer/plugins/java_plugin.py +0 -608
  59. tree_sitter_analyzer/plugins/plugin_loader.py +0 -85
  60. tree_sitter_analyzer/plugins/python_plugin.py +0 -606
  61. tree_sitter_analyzer/plugins/registry.py +0 -374
  62. tree_sitter_analyzer-0.3.0.dist-info/RECORD +0 -77
  63. {tree_sitter_analyzer-0.3.0.dist-info → tree_sitter_analyzer-0.6.0.dist-info}/WHEEL +0 -0
@@ -93,7 +93,7 @@ class TreeSitterAnalyzerMCPServer:
93
93
  server: Server = Server(self.name)
94
94
 
95
95
  # Register tools
96
- @server.list_tools()
96
+ @server.list_tools() # type: ignore
97
97
  async def handle_list_tools() -> list[Tool]:
98
98
  """List available tools."""
99
99
  tools = [
@@ -144,7 +144,7 @@ class TreeSitterAnalyzerMCPServer:
144
144
 
145
145
  return tools
146
146
 
147
- @server.call_tool()
147
+ @server.call_tool() # type: ignore
148
148
  async def handle_call_tool(
149
149
  name: str, arguments: dict[str, Any]
150
150
  ) -> list[TextContent]:
@@ -201,7 +201,7 @@ class TreeSitterAnalyzerMCPServer:
201
201
  ]
202
202
 
203
203
  # Register resources
204
- @server.list_resources()
204
+ @server.list_resources() # type: ignore
205
205
  async def handle_list_resources() -> list[Resource]:
206
206
  """List available resources."""
207
207
  return [
@@ -225,7 +225,7 @@ class TreeSitterAnalyzerMCPServer:
225
225
  ),
226
226
  ]
227
227
 
228
- @server.read_resource()
228
+ @server.read_resource() # type: ignore
229
229
  async def handle_read_resource(uri: str) -> str:
230
230
  """Read resource content."""
231
231
  try:
@@ -214,7 +214,7 @@ class AnalyzeScaleTool:
214
214
  Returns:
215
215
  Dictionary containing LLM guidance
216
216
  """
217
- guidance = {
217
+ guidance: dict[str, Any] = {
218
218
  "analysis_strategy": "",
219
219
  "recommended_tools": [],
220
220
  "key_areas": [],
@@ -417,35 +417,47 @@ class AnalyzeScaleTool:
417
417
  "classes": len(
418
418
  [
419
419
  e
420
- for e in analysis_result.elements
420
+ for e in (
421
+ analysis_result.elements if analysis_result else []
422
+ )
421
423
  if e.__class__.__name__ == "Class"
422
424
  ]
423
425
  ),
424
426
  "methods": len(
425
427
  [
426
428
  e
427
- for e in analysis_result.elements
429
+ for e in (
430
+ analysis_result.elements if analysis_result else []
431
+ )
428
432
  if e.__class__.__name__ == "Function"
429
433
  ]
430
434
  ),
431
435
  "fields": len(
432
436
  [
433
437
  e
434
- for e in analysis_result.elements
438
+ for e in (
439
+ analysis_result.elements if analysis_result else []
440
+ )
435
441
  if e.__class__.__name__ == "Variable"
436
442
  ]
437
443
  ),
438
444
  "imports": len(
439
445
  [
440
446
  e
441
- for e in analysis_result.elements
447
+ for e in (
448
+ analysis_result.elements if analysis_result else []
449
+ )
442
450
  if e.__class__.__name__ == "Import"
443
451
  ]
444
452
  ),
445
- "annotations": len(getattr(analysis_result, "annotations", [])),
453
+ "annotations": len(
454
+ getattr(analysis_result, "annotations", [])
455
+ if analysis_result
456
+ else []
457
+ ),
446
458
  "package": (
447
459
  analysis_result.package.name
448
- if analysis_result.package
460
+ if analysis_result and analysis_result.package
449
461
  else None
450
462
  ),
451
463
  },
@@ -458,20 +470,27 @@ class AnalyzeScaleTool:
458
470
  # Add detailed information if requested (backward compatibility)
459
471
  if include_details:
460
472
  result["detailed_analysis"] = {
461
- "statistics": analysis_result.get_statistics(),
473
+ "statistics": (
474
+ analysis_result.get_statistics() if analysis_result else {}
475
+ ),
462
476
  "classes": [
463
477
  {
464
478
  "name": cls.name,
465
- "type": cls.class_type,
466
- "visibility": cls.visibility,
467
- "extends": cls.extends_class,
468
- "implements": cls.implements_interfaces,
469
- "annotations": [ann.name for ann in cls.annotations],
479
+ "type": getattr(cls, "class_type", "unknown"),
480
+ "visibility": getattr(cls, "visibility", "unknown"),
481
+ "extends": getattr(cls, "extends_class", None),
482
+ "implements": getattr(cls, "implements_interfaces", []),
483
+ "annotations": [
484
+ getattr(ann, "name", str(ann))
485
+ for ann in getattr(cls, "annotations", [])
486
+ ],
470
487
  "lines": f"{cls.start_line}-{cls.end_line}",
471
488
  }
472
489
  for cls in [
473
490
  e
474
- for e in analysis_result.elements
491
+ for e in (
492
+ analysis_result.elements if analysis_result else []
493
+ )
475
494
  if e.__class__.__name__ == "Class"
476
495
  ]
477
496
  ],
@@ -479,35 +498,49 @@ class AnalyzeScaleTool:
479
498
  {
480
499
  "name": method.name,
481
500
  "file_path": getattr(method, "file_path", file_path),
482
- "visibility": method.visibility,
483
- "return_type": method.return_type,
484
- "parameters": len(method.parameters),
485
- "annotations": [ann.name for ann in method.annotations],
486
- "is_constructor": method.is_constructor,
487
- "is_static": method.is_static,
488
- "complexity": method.complexity_score,
501
+ "visibility": getattr(method, "visibility", "unknown"),
502
+ "return_type": getattr(
503
+ method, "return_type", "unknown"
504
+ ),
505
+ "parameters": len(getattr(method, "parameters", [])),
506
+ "annotations": [
507
+ getattr(ann, "name", str(ann))
508
+ for ann in getattr(method, "annotations", [])
509
+ ],
510
+ "is_constructor": getattr(
511
+ method, "is_constructor", False
512
+ ),
513
+ "is_static": getattr(method, "is_static", False),
514
+ "complexity": getattr(method, "complexity_score", 0),
489
515
  "lines": f"{method.start_line}-{method.end_line}",
490
516
  }
491
517
  for method in [
492
518
  e
493
- for e in analysis_result.elements
519
+ for e in (
520
+ analysis_result.elements if analysis_result else []
521
+ )
494
522
  if e.__class__.__name__ == "Function"
495
523
  ]
496
524
  ],
497
525
  "fields": [
498
526
  {
499
527
  "name": field.name,
500
- "type": field.field_type,
528
+ "type": getattr(field, "field_type", "unknown"),
501
529
  "file_path": getattr(field, "file_path", file_path),
502
- "visibility": field.visibility,
503
- "is_static": field.is_static,
504
- "is_final": field.is_final,
505
- "annotations": [ann.name for ann in field.annotations],
530
+ "visibility": getattr(field, "visibility", "unknown"),
531
+ "is_static": getattr(field, "is_static", False),
532
+ "is_final": getattr(field, "is_final", False),
533
+ "annotations": [
534
+ getattr(ann, "name", str(ann))
535
+ for ann in getattr(field, "annotations", [])
536
+ ],
506
537
  "lines": f"{field.start_line}-{field.end_line}",
507
538
  }
508
539
  for field in [
509
540
  e
510
- for e in analysis_result.elements
541
+ for e in (
542
+ analysis_result.elements if analysis_result else []
543
+ )
511
544
  if e.__class__.__name__ == "Variable"
512
545
  ]
513
546
  ],
@@ -517,14 +550,14 @@ class AnalyzeScaleTool:
517
550
  classes_count = len(
518
551
  [
519
552
  e
520
- for e in analysis_result.elements
553
+ for e in (analysis_result.elements if analysis_result else [])
521
554
  if e.__class__.__name__ == "Class"
522
555
  ]
523
556
  )
524
557
  methods_count = len(
525
558
  [
526
559
  e
527
- for e in analysis_result.elements
560
+ for e in (analysis_result.elements if analysis_result else [])
528
561
  if e.__class__.__name__ == "Function"
529
562
  ]
530
563
  )
@@ -8,7 +8,7 @@ that matches the CLI --advanced --statistics output exactly.
8
8
 
9
9
  import time
10
10
  from pathlib import Path
11
- from typing import Any
11
+ from typing import Any, cast
12
12
 
13
13
  from ...core.analysis_engine import get_analysis_engine
14
14
  from ...language_detector import detect_language_from_file
@@ -104,8 +104,10 @@ class AnalyzeScaleToolCLICompatible:
104
104
  # Use AdvancedAnalyzer for comprehensive analysis
105
105
  analysis_result = await self.analysis_engine.analyze_file(file_path)
106
106
 
107
- if analysis_result is None:
108
- # Return CLI-compatible error format
107
+ # Handle potential None result (for testing purposes with mocked engine)
108
+ # This can only happen in tests where the engine is mocked to return None
109
+ # Use cast to tell MyPy this is possible in testing scenarios
110
+ if cast(Any, analysis_result) is None:
109
111
  return {
110
112
  "file_path": file_path,
111
113
  "success": False,
@@ -129,7 +131,10 @@ class AnalyzeScaleToolCLICompatible:
129
131
  "file_path": file_path,
130
132
  "success": True,
131
133
  "package_name": (
132
- analysis_result.package.name if analysis_result.package else None
134
+ analysis_result.package.name
135
+ if analysis_result.package
136
+ and hasattr(analysis_result.package, "name")
137
+ else None
133
138
  ),
134
139
  "element_counts": {
135
140
  "imports": len(analysis_result.imports),
@@ -157,7 +157,7 @@ class TableFormatTool:
157
157
  # Fallback to original conversion method
158
158
  return self._convert_parameters(parameters)
159
159
 
160
- def _get_field_modifiers(self, field) -> list:
160
+ def _get_field_modifiers(self, field: Any) -> list[str]:
161
161
  """Extract field modifiers as a list"""
162
162
  modifiers = []
163
163
 
@@ -172,7 +172,7 @@ class TableFormatTool:
172
172
  modifiers.append("final")
173
173
  return modifiers
174
174
 
175
- def _convert_analysis_result_to_dict(self, result) -> dict[str, Any]:
175
+ def _convert_analysis_result_to_dict(self, result: Any) -> dict[str, Any]:
176
176
  """Convert AnalysisResult to dictionary format expected by TableFormatter"""
177
177
  # Extract elements by type
178
178
  classes = [e for e in result.elements if e.__class__.__name__ == "Class"]
@@ -9,6 +9,8 @@ Note: Cache and performance monitoring functionality has been moved to
9
9
  the unified core services for better architecture.
10
10
  """
11
11
 
12
+ from typing import Any
13
+
12
14
  # Export main utility classes and functions
13
15
  from .error_handler import (
14
16
  AnalysisError,
@@ -50,36 +52,36 @@ try:
50
52
  class BackwardCompatibleCacheManager:
51
53
  """Backward compatible cache manager wrapper"""
52
54
 
53
- def __init__(self):
55
+ def __init__(self) -> None:
54
56
  self._cache_service = UnifiedCacheService()
55
57
 
56
- def clear_all_caches(self):
58
+ def clear_all_caches(self) -> None:
57
59
  """Backward compatibility: clear all caches"""
58
60
  return self._cache_service.clear()
59
61
 
60
- def get_cache_stats(self):
62
+ def get_cache_stats(self) -> dict[str, Any]:
61
63
  """Backward compatibility: get cache statistics"""
62
64
  return self._cache_service.get_stats()
63
65
 
64
- def __getattr__(self, name):
66
+ def __getattr__(self, name: str) -> Any:
65
67
  """Delegate other methods to the cache service"""
66
68
  return getattr(self._cache_service, name)
67
69
 
68
- def get_cache_manager():
70
+ def get_cache_manager() -> Any:
69
71
  """Backward compatibility: Get unified cache service"""
70
72
  return BackwardCompatibleCacheManager()
71
73
 
72
- def get_performance_monitor():
74
+ def get_performance_monitor() -> Any:
73
75
  """Backward compatibility: Get unified analysis engine for performance monitoring"""
74
76
  return UnifiedAnalysisEngine()
75
77
 
76
78
  except ImportError:
77
79
  # Fallback if core services are not available
78
- def get_cache_manager():
80
+ def get_cache_manager() -> Any:
79
81
  """Fallback cache manager"""
80
82
  return None
81
83
 
82
- def get_performance_monitor():
84
+ def get_performance_monitor() -> Any:
83
85
  """Fallback performance monitor"""
84
86
  return None
85
87