tree-sitter-analyzer 0.2.0__py3-none-any.whl → 0.3.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.
- tree_sitter_analyzer/__init__.py +133 -121
- tree_sitter_analyzer/__main__.py +11 -12
- tree_sitter_analyzer/api.py +531 -539
- tree_sitter_analyzer/cli/__init__.py +39 -39
- tree_sitter_analyzer/cli/__main__.py +12 -13
- tree_sitter_analyzer/cli/commands/__init__.py +26 -27
- tree_sitter_analyzer/cli/commands/advanced_command.py +88 -88
- tree_sitter_analyzer/cli/commands/base_command.py +160 -155
- tree_sitter_analyzer/cli/commands/default_command.py +18 -19
- tree_sitter_analyzer/cli/commands/partial_read_command.py +141 -133
- tree_sitter_analyzer/cli/commands/query_command.py +81 -82
- tree_sitter_analyzer/cli/commands/structure_command.py +138 -121
- tree_sitter_analyzer/cli/commands/summary_command.py +101 -93
- tree_sitter_analyzer/cli/commands/table_command.py +232 -233
- tree_sitter_analyzer/cli/info_commands.py +120 -121
- tree_sitter_analyzer/cli_main.py +277 -276
- tree_sitter_analyzer/core/__init__.py +15 -20
- tree_sitter_analyzer/core/analysis_engine.py +591 -574
- tree_sitter_analyzer/core/cache_service.py +320 -330
- tree_sitter_analyzer/core/engine.py +557 -560
- tree_sitter_analyzer/core/parser.py +293 -288
- tree_sitter_analyzer/core/query.py +494 -502
- tree_sitter_analyzer/encoding_utils.py +458 -460
- tree_sitter_analyzer/exceptions.py +337 -340
- tree_sitter_analyzer/file_handler.py +217 -222
- tree_sitter_analyzer/formatters/__init__.py +1 -1
- tree_sitter_analyzer/formatters/base_formatter.py +167 -168
- tree_sitter_analyzer/formatters/formatter_factory.py +78 -74
- tree_sitter_analyzer/formatters/java_formatter.py +287 -270
- tree_sitter_analyzer/formatters/python_formatter.py +255 -235
- tree_sitter_analyzer/interfaces/__init__.py +9 -10
- tree_sitter_analyzer/interfaces/cli.py +528 -557
- tree_sitter_analyzer/interfaces/cli_adapter.py +322 -319
- tree_sitter_analyzer/interfaces/mcp_adapter.py +180 -170
- tree_sitter_analyzer/interfaces/mcp_server.py +405 -416
- tree_sitter_analyzer/java_analyzer.py +218 -219
- tree_sitter_analyzer/language_detector.py +398 -400
- tree_sitter_analyzer/language_loader.py +224 -228
- tree_sitter_analyzer/languages/__init__.py +10 -11
- tree_sitter_analyzer/languages/java_plugin.py +1129 -1113
- tree_sitter_analyzer/languages/python_plugin.py +737 -712
- tree_sitter_analyzer/mcp/__init__.py +31 -32
- tree_sitter_analyzer/mcp/resources/__init__.py +44 -47
- tree_sitter_analyzer/mcp/resources/code_file_resource.py +212 -213
- tree_sitter_analyzer/mcp/resources/project_stats_resource.py +560 -550
- tree_sitter_analyzer/mcp/server.py +333 -345
- tree_sitter_analyzer/mcp/tools/__init__.py +30 -31
- tree_sitter_analyzer/mcp/tools/analyze_scale_tool.py +621 -557
- tree_sitter_analyzer/mcp/tools/analyze_scale_tool_cli_compatible.py +242 -245
- tree_sitter_analyzer/mcp/tools/base_tool.py +54 -55
- tree_sitter_analyzer/mcp/tools/read_partial_tool.py +300 -302
- tree_sitter_analyzer/mcp/tools/table_format_tool.py +362 -359
- tree_sitter_analyzer/mcp/tools/universal_analyze_tool.py +543 -476
- tree_sitter_analyzer/mcp/utils/__init__.py +105 -106
- tree_sitter_analyzer/mcp/utils/error_handler.py +549 -549
- tree_sitter_analyzer/models.py +470 -481
- tree_sitter_analyzer/output_manager.py +261 -264
- tree_sitter_analyzer/plugins/__init__.py +333 -334
- tree_sitter_analyzer/plugins/base.py +477 -446
- tree_sitter_analyzer/plugins/java_plugin.py +608 -625
- tree_sitter_analyzer/plugins/javascript_plugin.py +446 -439
- tree_sitter_analyzer/plugins/manager.py +362 -355
- tree_sitter_analyzer/plugins/plugin_loader.py +85 -83
- tree_sitter_analyzer/plugins/python_plugin.py +606 -598
- tree_sitter_analyzer/plugins/registry.py +374 -366
- tree_sitter_analyzer/queries/__init__.py +26 -27
- tree_sitter_analyzer/queries/java.py +391 -394
- tree_sitter_analyzer/queries/javascript.py +148 -149
- tree_sitter_analyzer/queries/python.py +285 -286
- tree_sitter_analyzer/queries/typescript.py +229 -230
- tree_sitter_analyzer/query_loader.py +254 -260
- tree_sitter_analyzer/table_formatter.py +468 -448
- tree_sitter_analyzer/utils.py +277 -277
- {tree_sitter_analyzer-0.2.0.dist-info → tree_sitter_analyzer-0.3.0.dist-info}/METADATA +21 -6
- tree_sitter_analyzer-0.3.0.dist-info/RECORD +77 -0
- tree_sitter_analyzer-0.2.0.dist-info/RECORD +0 -77
- {tree_sitter_analyzer-0.2.0.dist-info → tree_sitter_analyzer-0.3.0.dist-info}/WHEEL +0 -0
- {tree_sitter_analyzer-0.2.0.dist-info → tree_sitter_analyzer-0.3.0.dist-info}/entry_points.txt +0 -0
|
@@ -1,170 +1,180 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""
|
|
3
|
-
MCP Adapter for Tree-Sitter Analyzer
|
|
4
|
-
|
|
5
|
-
This module provides an adapter interface for integrating with the MCP protocol.
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
from typing import
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
result
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
def
|
|
153
|
-
"""
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
self.
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
MCP Adapter for Tree-Sitter Analyzer
|
|
4
|
+
|
|
5
|
+
This module provides an adapter interface for integrating with the MCP protocol.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
from ..models import AnalysisResult
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def get_analysis_engine():
|
|
14
|
+
"""Get analysis engine instance for testing compatibility."""
|
|
15
|
+
from ..core.analysis_engine import AnalysisEngine
|
|
16
|
+
|
|
17
|
+
return AnalysisEngine()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def handle_mcp_resource_request(uri):
|
|
21
|
+
"""Handle MCP resource request for testing compatibility."""
|
|
22
|
+
return {
|
|
23
|
+
"contents": [
|
|
24
|
+
{"mimeType": "application/json", "text": {"mock": "resource"}, "uri": uri}
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def read_file_safe(file_path: str) -> str:
|
|
30
|
+
"""Read file safely for MCP resource requests."""
|
|
31
|
+
try:
|
|
32
|
+
with open(file_path, encoding="utf-8") as f:
|
|
33
|
+
return f.read()
|
|
34
|
+
except Exception as e:
|
|
35
|
+
raise FileNotFoundError(f"Could not read file {file_path}: {e}") from e
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class MCPAdapter:
|
|
39
|
+
"""MCP Adapter for testing compatibility."""
|
|
40
|
+
|
|
41
|
+
def __init__(self):
|
|
42
|
+
"""Initialize MCP Adapter."""
|
|
43
|
+
from ..core.analysis_engine import UnifiedAnalysisEngine
|
|
44
|
+
|
|
45
|
+
self.engine = UnifiedAnalysisEngine()
|
|
46
|
+
|
|
47
|
+
async def analyze_file_async(self, file_path: str, **kwargs) -> "AnalysisResult":
|
|
48
|
+
"""Analyze file asynchronously."""
|
|
49
|
+
from ..core.analysis_engine import AnalysisRequest
|
|
50
|
+
|
|
51
|
+
request = AnalysisRequest(
|
|
52
|
+
file_path=file_path,
|
|
53
|
+
language=kwargs.get("language"),
|
|
54
|
+
include_complexity=kwargs.get("include_complexity", False),
|
|
55
|
+
include_details=kwargs.get("include_details", True),
|
|
56
|
+
format_type=kwargs.get("format_type", "standard"),
|
|
57
|
+
)
|
|
58
|
+
return await self.engine.analyze(request)
|
|
59
|
+
|
|
60
|
+
async def get_file_structure_async(
|
|
61
|
+
self, file_path: str, **kwargs
|
|
62
|
+
) -> dict[str, Any]:
|
|
63
|
+
"""Get file structure asynchronously."""
|
|
64
|
+
result = await self.analyze_file_async(file_path, **kwargs)
|
|
65
|
+
return {
|
|
66
|
+
"file_path": result.file_path,
|
|
67
|
+
"language": result.language,
|
|
68
|
+
"structure": {
|
|
69
|
+
"classes": [cls.to_dict() for cls in result.classes],
|
|
70
|
+
"methods": [method.to_dict() for method in result.methods],
|
|
71
|
+
"fields": [field.to_dict() for field in result.fields],
|
|
72
|
+
"imports": [imp.to_dict() for imp in result.imports],
|
|
73
|
+
"annotations": [ann.to_dict() for ann in result.annotations],
|
|
74
|
+
},
|
|
75
|
+
"metadata": {
|
|
76
|
+
"analysis_time": result.analysis_time,
|
|
77
|
+
"success": result.success,
|
|
78
|
+
"error_message": result.error_message,
|
|
79
|
+
"package": result.package,
|
|
80
|
+
"class_count": len(result.classes),
|
|
81
|
+
"method_count": len(result.methods),
|
|
82
|
+
"field_count": len(result.fields),
|
|
83
|
+
"import_count": len(result.imports),
|
|
84
|
+
"annotation_count": len(result.annotations),
|
|
85
|
+
},
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async def analyze_batch_async(
|
|
89
|
+
self, file_paths: list[str], **kwargs
|
|
90
|
+
) -> list["AnalysisResult"]:
|
|
91
|
+
"""Analyze multiple files asynchronously."""
|
|
92
|
+
results = []
|
|
93
|
+
for file_path in file_paths:
|
|
94
|
+
try:
|
|
95
|
+
result = await self.analyze_file_async(file_path, **kwargs)
|
|
96
|
+
results.append(result)
|
|
97
|
+
except Exception as e:
|
|
98
|
+
# Create error result
|
|
99
|
+
from ..models import AnalysisResult
|
|
100
|
+
|
|
101
|
+
error_result = AnalysisResult(
|
|
102
|
+
file_path=file_path,
|
|
103
|
+
language="unknown",
|
|
104
|
+
line_count=0,
|
|
105
|
+
elements=[],
|
|
106
|
+
node_count=0,
|
|
107
|
+
query_results={},
|
|
108
|
+
source_code="",
|
|
109
|
+
package=None,
|
|
110
|
+
imports=[],
|
|
111
|
+
classes=[],
|
|
112
|
+
methods=[],
|
|
113
|
+
fields=[],
|
|
114
|
+
annotations=[],
|
|
115
|
+
analysis_time=0.0,
|
|
116
|
+
success=False,
|
|
117
|
+
error_message=str(e),
|
|
118
|
+
)
|
|
119
|
+
results.append(error_result)
|
|
120
|
+
return results
|
|
121
|
+
|
|
122
|
+
async def handle_mcp_tool_request(
|
|
123
|
+
self, tool_name: str, arguments: dict[str, Any]
|
|
124
|
+
) -> dict[str, Any]:
|
|
125
|
+
"""Handle MCP tool request."""
|
|
126
|
+
if tool_name == "analyze_file":
|
|
127
|
+
file_path = arguments.get("file_path")
|
|
128
|
+
if not file_path:
|
|
129
|
+
return {"error": "file_path is required"}
|
|
130
|
+
|
|
131
|
+
try:
|
|
132
|
+
result = await self.analyze_file_async(file_path)
|
|
133
|
+
return {"success": True, "result": result.to_dict()}
|
|
134
|
+
except Exception as e:
|
|
135
|
+
return {"error": str(e)}
|
|
136
|
+
|
|
137
|
+
return {"error": f"Unknown tool: {tool_name}"}
|
|
138
|
+
|
|
139
|
+
async def handle_mcp_resource_request(self, uri: str) -> dict[str, Any]:
|
|
140
|
+
"""Handle MCP resource request."""
|
|
141
|
+
if uri.startswith("code://"):
|
|
142
|
+
# Extract file path from URI
|
|
143
|
+
file_path = uri.replace("code://", "")
|
|
144
|
+
try:
|
|
145
|
+
content = read_file_safe(file_path)
|
|
146
|
+
return {"uri": uri, "content": content, "mimeType": "text/plain"}
|
|
147
|
+
except Exception as e:
|
|
148
|
+
return {"error": str(e)}
|
|
149
|
+
|
|
150
|
+
return {"error": f"Unsupported URI: {uri}"}
|
|
151
|
+
|
|
152
|
+
def cleanup(self) -> None:
|
|
153
|
+
"""Cleanup resources."""
|
|
154
|
+
pass
|
|
155
|
+
|
|
156
|
+
async def aclose(self) -> None:
|
|
157
|
+
"""Async cleanup."""
|
|
158
|
+
pass
|
|
159
|
+
|
|
160
|
+
def analyze_with_mcp_request(self, arguments):
|
|
161
|
+
"""Analyze with MCP request."""
|
|
162
|
+
if "file_path" not in arguments:
|
|
163
|
+
raise KeyError("file_path is required in MCP request")
|
|
164
|
+
return self.analyze_file_async(arguments["file_path"])
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
class MCPServerAdapter:
|
|
168
|
+
"""MCP Server Adapter for testing compatibility."""
|
|
169
|
+
|
|
170
|
+
def __init__(self):
|
|
171
|
+
"""Initialize MCP Server Adapter."""
|
|
172
|
+
self.mcp_adapter = MCPAdapter()
|
|
173
|
+
|
|
174
|
+
async def handle_request(
|
|
175
|
+
self, method: str, params: dict[str, Any]
|
|
176
|
+
) -> dict[str, Any]:
|
|
177
|
+
"""Handle MCP request."""
|
|
178
|
+
if not params:
|
|
179
|
+
return {"error": "params are required"}
|
|
180
|
+
return await self.mcp_adapter.handle_mcp_tool_request(method, params)
|