tree-sitter-analyzer 0.1.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 (78) hide show
  1. tree_sitter_analyzer/__init__.py +121 -0
  2. tree_sitter_analyzer/__main__.py +12 -0
  3. tree_sitter_analyzer/api.py +539 -0
  4. tree_sitter_analyzer/cli/__init__.py +39 -0
  5. tree_sitter_analyzer/cli/__main__.py +13 -0
  6. tree_sitter_analyzer/cli/commands/__init__.py +27 -0
  7. tree_sitter_analyzer/cli/commands/advanced_command.py +88 -0
  8. tree_sitter_analyzer/cli/commands/base_command.py +155 -0
  9. tree_sitter_analyzer/cli/commands/default_command.py +19 -0
  10. tree_sitter_analyzer/cli/commands/partial_read_command.py +133 -0
  11. tree_sitter_analyzer/cli/commands/query_command.py +82 -0
  12. tree_sitter_analyzer/cli/commands/structure_command.py +121 -0
  13. tree_sitter_analyzer/cli/commands/summary_command.py +93 -0
  14. tree_sitter_analyzer/cli/commands/table_command.py +233 -0
  15. tree_sitter_analyzer/cli/info_commands.py +121 -0
  16. tree_sitter_analyzer/cli_main.py +276 -0
  17. tree_sitter_analyzer/core/__init__.py +20 -0
  18. tree_sitter_analyzer/core/analysis_engine.py +574 -0
  19. tree_sitter_analyzer/core/cache_service.py +330 -0
  20. tree_sitter_analyzer/core/engine.py +560 -0
  21. tree_sitter_analyzer/core/parser.py +288 -0
  22. tree_sitter_analyzer/core/query.py +502 -0
  23. tree_sitter_analyzer/encoding_utils.py +460 -0
  24. tree_sitter_analyzer/exceptions.py +340 -0
  25. tree_sitter_analyzer/file_handler.py +222 -0
  26. tree_sitter_analyzer/formatters/__init__.py +1 -0
  27. tree_sitter_analyzer/formatters/base_formatter.py +168 -0
  28. tree_sitter_analyzer/formatters/formatter_factory.py +74 -0
  29. tree_sitter_analyzer/formatters/java_formatter.py +270 -0
  30. tree_sitter_analyzer/formatters/python_formatter.py +235 -0
  31. tree_sitter_analyzer/interfaces/__init__.py +10 -0
  32. tree_sitter_analyzer/interfaces/cli.py +557 -0
  33. tree_sitter_analyzer/interfaces/cli_adapter.py +319 -0
  34. tree_sitter_analyzer/interfaces/mcp_adapter.py +170 -0
  35. tree_sitter_analyzer/interfaces/mcp_server.py +416 -0
  36. tree_sitter_analyzer/java_analyzer.py +219 -0
  37. tree_sitter_analyzer/language_detector.py +400 -0
  38. tree_sitter_analyzer/language_loader.py +228 -0
  39. tree_sitter_analyzer/languages/__init__.py +11 -0
  40. tree_sitter_analyzer/languages/java_plugin.py +1113 -0
  41. tree_sitter_analyzer/languages/python_plugin.py +712 -0
  42. tree_sitter_analyzer/mcp/__init__.py +32 -0
  43. tree_sitter_analyzer/mcp/resources/__init__.py +47 -0
  44. tree_sitter_analyzer/mcp/resources/code_file_resource.py +213 -0
  45. tree_sitter_analyzer/mcp/resources/project_stats_resource.py +550 -0
  46. tree_sitter_analyzer/mcp/server.py +319 -0
  47. tree_sitter_analyzer/mcp/tools/__init__.py +36 -0
  48. tree_sitter_analyzer/mcp/tools/analyze_scale_tool.py +558 -0
  49. tree_sitter_analyzer/mcp/tools/analyze_scale_tool_cli_compatible.py +245 -0
  50. tree_sitter_analyzer/mcp/tools/base_tool.py +55 -0
  51. tree_sitter_analyzer/mcp/tools/get_positions_tool.py +448 -0
  52. tree_sitter_analyzer/mcp/tools/read_partial_tool.py +302 -0
  53. tree_sitter_analyzer/mcp/tools/table_format_tool.py +359 -0
  54. tree_sitter_analyzer/mcp/tools/universal_analyze_tool.py +476 -0
  55. tree_sitter_analyzer/mcp/utils/__init__.py +106 -0
  56. tree_sitter_analyzer/mcp/utils/error_handler.py +549 -0
  57. tree_sitter_analyzer/models.py +481 -0
  58. tree_sitter_analyzer/output_manager.py +264 -0
  59. tree_sitter_analyzer/plugins/__init__.py +334 -0
  60. tree_sitter_analyzer/plugins/base.py +446 -0
  61. tree_sitter_analyzer/plugins/java_plugin.py +625 -0
  62. tree_sitter_analyzer/plugins/javascript_plugin.py +439 -0
  63. tree_sitter_analyzer/plugins/manager.py +355 -0
  64. tree_sitter_analyzer/plugins/plugin_loader.py +83 -0
  65. tree_sitter_analyzer/plugins/python_plugin.py +598 -0
  66. tree_sitter_analyzer/plugins/registry.py +366 -0
  67. tree_sitter_analyzer/queries/__init__.py +27 -0
  68. tree_sitter_analyzer/queries/java.py +394 -0
  69. tree_sitter_analyzer/queries/javascript.py +149 -0
  70. tree_sitter_analyzer/queries/python.py +286 -0
  71. tree_sitter_analyzer/queries/typescript.py +230 -0
  72. tree_sitter_analyzer/query_loader.py +260 -0
  73. tree_sitter_analyzer/table_formatter.py +448 -0
  74. tree_sitter_analyzer/utils.py +201 -0
  75. tree_sitter_analyzer-0.1.0.dist-info/METADATA +581 -0
  76. tree_sitter_analyzer-0.1.0.dist-info/RECORD +78 -0
  77. tree_sitter_analyzer-0.1.0.dist-info/WHEEL +4 -0
  78. tree_sitter_analyzer-0.1.0.dist-info/entry_points.txt +8 -0
@@ -0,0 +1,235 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Python-specific table formatter.
5
+ """
6
+
7
+ from typing import Any, Dict, List
8
+ from .base_formatter import BaseTableFormatter
9
+
10
+
11
+ class PythonTableFormatter(BaseTableFormatter):
12
+ """Python言語専用のテーブルフォーマッター"""
13
+
14
+ def _format_full_table(self, data: Dict[str, Any]) -> str:
15
+ """Python用完全版テーブル形式"""
16
+ lines = []
17
+
18
+ # ヘッダー - Python用(複数クラス対応)
19
+ classes = data.get("classes", [])
20
+ if len(classes) > 1:
21
+ # 複数クラスがある場合はファイル名を使用
22
+ file_name = data.get("file_path", "Unknown").split("/")[-1].split("\\")[-1]
23
+ lines.append(f"# {file_name}")
24
+ else:
25
+ # 単一クラスの場合はクラス名を使用
26
+ class_name = classes[0].get("name", "Unknown") if classes else "Unknown"
27
+ lines.append(f"# {class_name}")
28
+ lines.append("")
29
+
30
+ # Imports
31
+ imports = data.get("imports", [])
32
+ if imports:
33
+ lines.append("## Imports")
34
+ lines.append("```python")
35
+ for imp in imports:
36
+ lines.append(str(imp.get("statement", "")))
37
+ lines.append("```")
38
+ lines.append("")
39
+
40
+ # Classes - Python用(複数クラス対応)
41
+ if len(classes) > 1:
42
+ lines.append("## Classes")
43
+ lines.append("| Class | Type | Visibility | Lines | Methods | Fields |")
44
+ lines.append("|-------|------|------------|-------|---------|--------|")
45
+
46
+ for class_info in classes:
47
+ name = str(class_info.get("name", "Unknown"))
48
+ class_type = str(class_info.get("type", "class"))
49
+ visibility = str(class_info.get("visibility", "public"))
50
+ line_range = class_info.get("line_range", {})
51
+ lines_str = f"{line_range.get('start', 0)}-{line_range.get('end', 0)}"
52
+
53
+ # このクラスのメソッド数とフィールド数を計算
54
+ class_methods = [m for m in data.get("methods", [])
55
+ if line_range.get('start', 0) <= m.get('line_range', {}).get('start', 0) <= line_range.get('end', 0)]
56
+ class_fields = [f for f in data.get("fields", [])
57
+ if line_range.get('start', 0) <= f.get('line_range', {}).get('start', 0) <= line_range.get('end', 0)]
58
+
59
+ lines.append(f"| {name} | {class_type} | {visibility} | {lines_str} | {len(class_methods)} | {len(class_fields)} |")
60
+ else:
61
+ # 単一クラスの場合
62
+ lines.append("## Class Info")
63
+ lines.append("| Property | Value |")
64
+ lines.append("|----------|-------|")
65
+
66
+ class_info = data.get("classes", [{}])[0] if data.get("classes") else {}
67
+ stats = data.get("statistics") or {}
68
+
69
+ lines.append(f"| Package | (default) |")
70
+ lines.append(f"| Type | {str(class_info.get('type', 'class'))} |")
71
+ lines.append(f"| Visibility | {str(class_info.get('visibility', 'public'))} |")
72
+ lines.append(
73
+ f"| Lines | {class_info.get('line_range', {}).get('start', 0)}-{class_info.get('line_range', {}).get('end', 0)} |"
74
+ )
75
+ lines.append(f"| Total Methods | {stats.get('method_count', 0)} |")
76
+ lines.append(f"| Total Fields | {stats.get('field_count', 0)} |")
77
+
78
+ lines.append("")
79
+
80
+ # Fields
81
+ fields = data.get("fields", [])
82
+ if fields:
83
+ lines.append("## Fields")
84
+ lines.append("| Name | Type | Vis | Modifiers | Line | Doc |")
85
+ lines.append("|------|------|-----|-----------|------|-----|")
86
+
87
+ for field in fields:
88
+ name = str(field.get("name", ""))
89
+ field_type = str(field.get("type", ""))
90
+ visibility = self._convert_visibility(str(field.get("visibility", "")))
91
+ modifiers = ",".join([str(m) for m in field.get("modifiers", [])])
92
+ line = field.get("line_range", {}).get("start", 0)
93
+ doc = str(field.get("javadoc", "")) or "-"
94
+ doc = doc.replace("\n", " ").replace("|", "\\|")[:50]
95
+
96
+ lines.append(
97
+ f"| {name} | {field_type} | {visibility} | {modifiers} | {line} | {doc} |"
98
+ )
99
+ lines.append("")
100
+
101
+ # Methods - Python用(コンストラクタ分離なし)
102
+ methods = data.get("methods", [])
103
+ if methods:
104
+ lines.append("## Methods")
105
+ lines.append("| Method | Signature | Vis | Lines | Cols | Cx | Doc |")
106
+ lines.append("|--------|-----------|-----|-------|------|----|----|")
107
+
108
+ for method in methods:
109
+ lines.append(self._format_method_row(method))
110
+ lines.append("")
111
+
112
+ # 末尾の空行を削除
113
+ while lines and lines[-1] == "":
114
+ lines.pop()
115
+
116
+ return "\n".join(lines)
117
+
118
+ def _format_compact_table(self, data: Dict[str, Any]) -> str:
119
+ """Python用コンパクト版テーブル形式"""
120
+ lines = []
121
+
122
+ # ヘッダー
123
+ classes = data.get("classes", [])
124
+ if len(classes) > 1:
125
+ file_name = data.get("file_path", "Unknown").split("/")[-1].split("\\")[-1]
126
+ lines.append(f"# {file_name}")
127
+ else:
128
+ class_name = classes[0].get("name", "Unknown") if classes else "Unknown"
129
+ lines.append(f"# {class_name}")
130
+ lines.append("")
131
+
132
+ # 基本情報
133
+ stats = data.get("statistics") or {}
134
+ lines.append("## Info")
135
+ lines.append("| Property | Value |")
136
+ lines.append("|----------|-------|")
137
+ lines.append(f"| Classes | {len(classes)} |")
138
+ lines.append(f"| Methods | {stats.get('method_count', 0)} |")
139
+ lines.append(f"| Fields | {stats.get('field_count', 0)} |")
140
+ lines.append("")
141
+
142
+ # メソッド(簡略版)
143
+ methods = data.get("methods", [])
144
+ if methods:
145
+ lines.append("## Methods")
146
+ lines.append("| Method | Sig | V | L | Cx | Doc |")
147
+ lines.append("|--------|-----|---|---|----|----|")
148
+
149
+ for method in methods:
150
+ name = str(method.get("name", ""))
151
+ signature = self._create_compact_signature(method)
152
+ visibility = self._convert_visibility(str(method.get("visibility", "")))
153
+ line_range = method.get("line_range", {})
154
+ lines_str = f"{line_range.get('start', 0)}-{line_range.get('end', 0)}"
155
+ complexity = method.get("complexity_score", 0)
156
+ doc = self._clean_csv_text(
157
+ self._extract_doc_summary(str(method.get("javadoc", "")))
158
+ )
159
+
160
+ lines.append(
161
+ f"| {name} | {signature} | {visibility} | {lines_str} | {complexity} | {doc} |"
162
+ )
163
+ lines.append("")
164
+
165
+ # 末尾の空行を削除
166
+ while lines and lines[-1] == "":
167
+ lines.pop()
168
+
169
+ return "\n".join(lines)
170
+
171
+ def _format_method_row(self, method: Dict[str, Any]) -> str:
172
+ """Python用メソッド行のフォーマット"""
173
+ name = str(method.get("name", ""))
174
+ signature = self._create_full_signature(method)
175
+ visibility = self._convert_visibility(str(method.get("visibility", "")))
176
+ line_range = method.get("line_range", {})
177
+ lines_str = f"{line_range.get('start', 0)}-{line_range.get('end', 0)}"
178
+ cols_str = "5-6" # デフォルト値
179
+ complexity = method.get("complexity_score", 0)
180
+ doc = self._clean_csv_text(
181
+ self._extract_doc_summary(str(method.get("javadoc", "")))
182
+ )
183
+
184
+ return f"| {name} | {signature} | {visibility} | {lines_str} | {cols_str} | {complexity} | {doc} |"
185
+
186
+ def _create_compact_signature(self, method: Dict[str, Any]) -> str:
187
+ """Python用コンパクトなメソッドシグネチャを作成"""
188
+ params = method.get("parameters", [])
189
+ param_types = []
190
+
191
+ for p in params:
192
+ if isinstance(p, dict):
193
+ param_types.append(self._shorten_type(p.get("type", "Any")))
194
+ else:
195
+ param_types.append("Any")
196
+
197
+ params_str = ",".join(param_types)
198
+ return_type = self._shorten_type(method.get("return_type", "Any"))
199
+
200
+ return f"({params_str}):{return_type}"
201
+
202
+ def _shorten_type(self, type_name: Any) -> str:
203
+ """Python用型名を短縮"""
204
+ if type_name is None:
205
+ return "Any"
206
+
207
+ if not isinstance(type_name, str):
208
+ type_name = str(type_name)
209
+
210
+ type_mapping = {
211
+ "str": "s",
212
+ "int": "i",
213
+ "float": "f",
214
+ "bool": "b",
215
+ "None": "N",
216
+ "Any": "A",
217
+ "List": "L",
218
+ "Dict": "D",
219
+ "Optional": "O",
220
+ "Union": "U",
221
+ }
222
+
223
+ # List[str] -> L[s]
224
+ if "List[" in type_name:
225
+ return type_name.replace("List[", "L[").replace("str", "s").replace("int", "i")
226
+
227
+ # Dict[str, int] -> D[s,i]
228
+ if "Dict[" in type_name:
229
+ return type_name.replace("Dict[", "D[").replace("str", "s").replace("int", "i")
230
+
231
+ # Optional[str] -> O[s]
232
+ if "Optional[" in type_name:
233
+ return type_name.replace("Optional[", "O[").replace("str", "s")
234
+
235
+ return type_mapping.get(type_name, type_name[:3] if len(type_name) > 3 else type_name)
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Interfaces Package
5
+
6
+ This package contains the external interfaces for the tree-sitter analyzer.
7
+ Each interface provides a different way to interact with the core analysis engine.
8
+ """
9
+
10
+ # This file makes the interfaces directory a Python package