tree-sitter-analyzer 0.2.0__py3-none-any.whl → 0.4.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 +134 -121
  2. tree_sitter_analyzer/__main__.py +11 -12
  3. tree_sitter_analyzer/api.py +533 -539
  4. tree_sitter_analyzer/cli/__init__.py +39 -39
  5. tree_sitter_analyzer/cli/__main__.py +12 -13
  6. tree_sitter_analyzer/cli/commands/__init__.py +26 -27
  7. tree_sitter_analyzer/cli/commands/advanced_command.py +88 -88
  8. tree_sitter_analyzer/cli/commands/base_command.py +160 -155
  9. tree_sitter_analyzer/cli/commands/default_command.py +18 -19
  10. tree_sitter_analyzer/cli/commands/partial_read_command.py +141 -133
  11. tree_sitter_analyzer/cli/commands/query_command.py +81 -82
  12. tree_sitter_analyzer/cli/commands/structure_command.py +138 -121
  13. tree_sitter_analyzer/cli/commands/summary_command.py +101 -93
  14. tree_sitter_analyzer/cli/commands/table_command.py +235 -233
  15. tree_sitter_analyzer/cli/info_commands.py +120 -121
  16. tree_sitter_analyzer/cli_main.py +278 -276
  17. tree_sitter_analyzer/core/__init__.py +15 -20
  18. tree_sitter_analyzer/core/analysis_engine.py +555 -574
  19. tree_sitter_analyzer/core/cache_service.py +320 -330
  20. tree_sitter_analyzer/core/engine.py +559 -560
  21. tree_sitter_analyzer/core/parser.py +293 -288
  22. tree_sitter_analyzer/core/query.py +502 -502
  23. tree_sitter_analyzer/encoding_utils.py +456 -460
  24. tree_sitter_analyzer/exceptions.py +337 -340
  25. tree_sitter_analyzer/file_handler.py +210 -222
  26. tree_sitter_analyzer/formatters/__init__.py +1 -1
  27. tree_sitter_analyzer/formatters/base_formatter.py +167 -168
  28. tree_sitter_analyzer/formatters/formatter_factory.py +78 -74
  29. tree_sitter_analyzer/formatters/java_formatter.py +291 -270
  30. tree_sitter_analyzer/formatters/python_formatter.py +259 -235
  31. tree_sitter_analyzer/interfaces/__init__.py +9 -10
  32. tree_sitter_analyzer/interfaces/cli.py +528 -557
  33. tree_sitter_analyzer/interfaces/cli_adapter.py +343 -319
  34. tree_sitter_analyzer/interfaces/mcp_adapter.py +206 -170
  35. tree_sitter_analyzer/interfaces/mcp_server.py +405 -416
  36. tree_sitter_analyzer/java_analyzer.py +187 -219
  37. tree_sitter_analyzer/language_detector.py +398 -400
  38. tree_sitter_analyzer/language_loader.py +224 -228
  39. tree_sitter_analyzer/languages/__init__.py +10 -11
  40. tree_sitter_analyzer/languages/java_plugin.py +1174 -1113
  41. tree_sitter_analyzer/{plugins → languages}/javascript_plugin.py +446 -439
  42. tree_sitter_analyzer/languages/python_plugin.py +747 -712
  43. tree_sitter_analyzer/mcp/__init__.py +31 -32
  44. tree_sitter_analyzer/mcp/resources/__init__.py +44 -47
  45. tree_sitter_analyzer/mcp/resources/code_file_resource.py +209 -213
  46. tree_sitter_analyzer/mcp/resources/project_stats_resource.py +555 -550
  47. tree_sitter_analyzer/mcp/server.py +333 -345
  48. tree_sitter_analyzer/mcp/tools/__init__.py +30 -31
  49. tree_sitter_analyzer/mcp/tools/analyze_scale_tool.py +654 -557
  50. tree_sitter_analyzer/mcp/tools/analyze_scale_tool_cli_compatible.py +247 -245
  51. tree_sitter_analyzer/mcp/tools/base_tool.py +54 -55
  52. tree_sitter_analyzer/mcp/tools/read_partial_tool.py +300 -302
  53. tree_sitter_analyzer/mcp/tools/table_format_tool.py +362 -359
  54. tree_sitter_analyzer/mcp/tools/universal_analyze_tool.py +543 -476
  55. tree_sitter_analyzer/mcp/utils/__init__.py +107 -106
  56. tree_sitter_analyzer/mcp/utils/error_handler.py +549 -549
  57. tree_sitter_analyzer/models.py +470 -481
  58. tree_sitter_analyzer/output_manager.py +255 -264
  59. tree_sitter_analyzer/plugins/__init__.py +280 -334
  60. tree_sitter_analyzer/plugins/base.py +496 -446
  61. tree_sitter_analyzer/plugins/manager.py +379 -355
  62. tree_sitter_analyzer/queries/__init__.py +26 -27
  63. tree_sitter_analyzer/queries/java.py +391 -394
  64. tree_sitter_analyzer/queries/javascript.py +148 -149
  65. tree_sitter_analyzer/queries/python.py +285 -286
  66. tree_sitter_analyzer/queries/typescript.py +229 -230
  67. tree_sitter_analyzer/query_loader.py +257 -260
  68. tree_sitter_analyzer/table_formatter.py +471 -448
  69. tree_sitter_analyzer/utils.py +277 -277
  70. {tree_sitter_analyzer-0.2.0.dist-info → tree_sitter_analyzer-0.4.0.dist-info}/METADATA +23 -8
  71. tree_sitter_analyzer-0.4.0.dist-info/RECORD +73 -0
  72. {tree_sitter_analyzer-0.2.0.dist-info → tree_sitter_analyzer-0.4.0.dist-info}/entry_points.txt +2 -1
  73. tree_sitter_analyzer/plugins/java_plugin.py +0 -625
  74. tree_sitter_analyzer/plugins/plugin_loader.py +0 -83
  75. tree_sitter_analyzer/plugins/python_plugin.py +0 -598
  76. tree_sitter_analyzer/plugins/registry.py +0 -366
  77. tree_sitter_analyzer-0.2.0.dist-info/RECORD +0 -77
  78. {tree_sitter_analyzer-0.2.0.dist-info → tree_sitter_analyzer-0.4.0.dist-info}/WHEEL +0 -0
@@ -1,168 +1,167 @@
1
- #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
- """
4
- Base formatter for language-specific table formatting.
5
- """
6
-
7
- import csv
8
- import io
9
- import os
10
- from abc import ABC, abstractmethod
11
- from typing import Any, Dict, List
12
-
13
-
14
- class BaseTableFormatter(ABC):
15
- """Base class for language-specific table formatters"""
16
-
17
- def __init__(self, format_type: str = "full"):
18
- self.format_type = format_type
19
-
20
- def _get_platform_newline(self) -> str:
21
- """プラットフォーム固有の改行コードを取得"""
22
- return os.linesep
23
-
24
- def _convert_to_platform_newlines(self, text: str) -> str:
25
- """通常の\nをプラットフォーム固有の改行コードに変換"""
26
- if os.linesep != "\n":
27
- return text.replace("\n", os.linesep)
28
- return text
29
-
30
- def format_structure(self, structure_data: Dict[str, Any]) -> str:
31
- """構造データをテーブル形式でフォーマット"""
32
- if self.format_type == "full":
33
- result = self._format_full_table(structure_data)
34
- elif self.format_type == "compact":
35
- result = self._format_compact_table(structure_data)
36
- elif self.format_type == "csv":
37
- result = self._format_csv(structure_data)
38
- else:
39
- raise ValueError(f"Unsupported format type: {self.format_type}")
40
-
41
- # 最終的にプラットフォーム固有の改行コードに変換
42
- if self.format_type == "csv":
43
- return result
44
-
45
- return self._convert_to_platform_newlines(result)
46
-
47
- @abstractmethod
48
- def _format_full_table(self, data: Dict[str, Any]) -> str:
49
- """完全版テーブル形式(言語固有実装)"""
50
- pass
51
-
52
- @abstractmethod
53
- def _format_compact_table(self, data: Dict[str, Any]) -> str:
54
- """コンパクト版テーブル形式(言語固有実装)"""
55
- pass
56
-
57
- def _format_csv(self, data: Dict[str, Any]) -> str:
58
- """CSV形式(共通実装)"""
59
- output = io.StringIO()
60
- writer = csv.writer(output, lineterminator="\n")
61
-
62
- # ヘッダー
63
- writer.writerow(
64
- ["Type", "Name", "Signature", "Visibility", "Lines", "Complexity", "Doc"]
65
- )
66
-
67
- # フィールド
68
- for field in data.get("fields", []):
69
- writer.writerow(
70
- [
71
- "Field",
72
- str(field.get("name", "")),
73
- f"{str(field.get('name', ''))}:{str(field.get('type', ''))}",
74
- str(field.get("visibility", "")),
75
- f"{field.get('line_range', {}).get('start', 0)}-{field.get('line_range', {}).get('end', 0)}",
76
- "",
77
- self._clean_csv_text(
78
- self._extract_doc_summary(str(field.get("javadoc", "")))
79
- ),
80
- ]
81
- )
82
-
83
- # メソッド
84
- for method in data.get("methods", []):
85
- writer.writerow(
86
- [
87
- "Constructor" if method.get("is_constructor", False) else "Method",
88
- str(method.get("name", "")),
89
- self._clean_csv_text(self._create_full_signature(method)),
90
- str(method.get("visibility", "")),
91
- f"{method.get('line_range', {}).get('start', 0)}-{method.get('line_range', {}).get('end', 0)}",
92
- method.get("complexity_score", 0),
93
- self._clean_csv_text(
94
- self._extract_doc_summary(str(method.get("javadoc", "")))
95
- ),
96
- ]
97
- )
98
-
99
- csv_content = output.getvalue()
100
- csv_content = csv_content.replace("\r\n", "\n").replace("\r", "\n")
101
- csv_content = csv_content.rstrip("\n")
102
- output.close()
103
-
104
- return csv_content
105
-
106
- # 共通ヘルパーメソッド
107
- def _create_full_signature(self, method: Dict[str, Any]) -> str:
108
- """完全なメソッドシグネチャを作成"""
109
- params = method.get("parameters", [])
110
- param_strs = []
111
- for param in params:
112
- if isinstance(param, dict):
113
- param_type = str(param.get("type", "Object"))
114
- param_name = str(param.get("name", "param"))
115
- param_strs.append(f"{param_name}:{param_type}")
116
- else:
117
- param_strs.append(str(param))
118
-
119
- params_str = ", ".join(param_strs)
120
- return_type = str(method.get("return_type", "void"))
121
-
122
- modifiers = []
123
- if method.get("is_static", False):
124
- modifiers.append("[static]")
125
-
126
- modifier_str = " ".join(modifiers)
127
- signature = f"({params_str}):{return_type}"
128
-
129
- if modifier_str:
130
- signature += f" {modifier_str}"
131
-
132
- return signature
133
-
134
- def _convert_visibility(self, visibility: str) -> str:
135
- """可視性を記号に変換"""
136
- mapping = {"public": "+", "private": "-", "protected": "#", "package": "~"}
137
- return mapping.get(visibility, visibility)
138
-
139
- def _extract_doc_summary(self, javadoc: str) -> str:
140
- """ドキュメントから要約を抽出"""
141
- if not javadoc:
142
- return "-"
143
-
144
- # コメント記号を除去
145
- clean_doc = (
146
- javadoc.replace("/**", "").replace("*/", "").replace("*", "").strip()
147
- )
148
-
149
- # 最初の行を取得
150
- lines = clean_doc.split("\n")
151
- first_line = lines[0].strip()
152
-
153
- # 長すぎる場合は切り詰め
154
- if len(first_line) > 50:
155
- first_line = first_line[:47] + "..."
156
-
157
- return first_line.replace("|", "\\|").replace("\n", " ")
158
-
159
- def _clean_csv_text(self, text: str) -> str:
160
- """CSV形式用のテキストクリーニング"""
161
- if not text:
162
- return ""
163
-
164
- cleaned = text.replace("\r\n", " ").replace("\r", " ").replace("\n", " ")
165
- cleaned = " ".join(cleaned.split())
166
- cleaned = cleaned.replace('"', '""')
167
-
168
- return cleaned
1
+ #!/usr/bin/env python3
2
+ """
3
+ Base formatter for language-specific table formatting.
4
+ """
5
+
6
+ import csv
7
+ import io
8
+ import os
9
+ from abc import ABC, abstractmethod
10
+ from typing import Any
11
+
12
+
13
+ class BaseTableFormatter(ABC):
14
+ """Base class for language-specific table formatters"""
15
+
16
+ def __init__(self, format_type: str = "full"):
17
+ self.format_type = format_type
18
+
19
+ def _get_platform_newline(self) -> str:
20
+ """プラットフォーム固有の改行コードを取得"""
21
+ return os.linesep
22
+
23
+ def _convert_to_platform_newlines(self, text: str) -> str:
24
+ """通常の\nをプラットフォーム固有の改行コードに変換"""
25
+ if os.linesep != "\n":
26
+ return text.replace("\n", os.linesep)
27
+ return text
28
+
29
+ def format_structure(self, structure_data: dict[str, Any]) -> str:
30
+ """構造データをテーブル形式でフォーマット"""
31
+ if self.format_type == "full":
32
+ result = self._format_full_table(structure_data)
33
+ elif self.format_type == "compact":
34
+ result = self._format_compact_table(structure_data)
35
+ elif self.format_type == "csv":
36
+ result = self._format_csv(structure_data)
37
+ else:
38
+ raise ValueError(f"Unsupported format type: {self.format_type}")
39
+
40
+ # 最終的にプラットフォーム固有の改行コードに変換
41
+ if self.format_type == "csv":
42
+ return result
43
+
44
+ return self._convert_to_platform_newlines(result)
45
+
46
+ @abstractmethod
47
+ def _format_full_table(self, data: dict[str, Any]) -> str:
48
+ """完全版テーブル形式(言語固有実装)"""
49
+ pass
50
+
51
+ @abstractmethod
52
+ def _format_compact_table(self, data: dict[str, Any]) -> str:
53
+ """コンパクト版テーブル形式(言語固有実装)"""
54
+ pass
55
+
56
+ def _format_csv(self, data: dict[str, Any]) -> str:
57
+ """CSV形式(共通実装)"""
58
+ output = io.StringIO()
59
+ writer = csv.writer(output, lineterminator="\n")
60
+
61
+ # ヘッダー
62
+ writer.writerow(
63
+ ["Type", "Name", "Signature", "Visibility", "Lines", "Complexity", "Doc"]
64
+ )
65
+
66
+ # フィールド
67
+ for field in data.get("fields", []):
68
+ writer.writerow(
69
+ [
70
+ "Field",
71
+ str(field.get("name", "")),
72
+ f"{str(field.get('name', ''))}:{str(field.get('type', ''))}",
73
+ str(field.get("visibility", "")),
74
+ f"{field.get('line_range', {}).get('start', 0)}-{field.get('line_range', {}).get('end', 0)}",
75
+ "",
76
+ self._clean_csv_text(
77
+ self._extract_doc_summary(str(field.get("javadoc", "")))
78
+ ),
79
+ ]
80
+ )
81
+
82
+ # メソッド
83
+ for method in data.get("methods", []):
84
+ writer.writerow(
85
+ [
86
+ "Constructor" if method.get("is_constructor", False) else "Method",
87
+ str(method.get("name", "")),
88
+ self._clean_csv_text(self._create_full_signature(method)),
89
+ str(method.get("visibility", "")),
90
+ f"{method.get('line_range', {}).get('start', 0)}-{method.get('line_range', {}).get('end', 0)}",
91
+ method.get("complexity_score", 0),
92
+ self._clean_csv_text(
93
+ self._extract_doc_summary(str(method.get("javadoc", "")))
94
+ ),
95
+ ]
96
+ )
97
+
98
+ csv_content = output.getvalue()
99
+ csv_content = csv_content.replace("\r\n", "\n").replace("\r", "\n")
100
+ csv_content = csv_content.rstrip("\n")
101
+ output.close()
102
+
103
+ return csv_content
104
+
105
+ # 共通ヘルパーメソッド
106
+ def _create_full_signature(self, method: dict[str, Any]) -> str:
107
+ """完全なメソッドシグネチャを作成"""
108
+ params = method.get("parameters", [])
109
+ param_strs = []
110
+ for param in params:
111
+ if isinstance(param, dict):
112
+ param_type = str(param.get("type", "Object"))
113
+ param_name = str(param.get("name", "param"))
114
+ param_strs.append(f"{param_name}:{param_type}")
115
+ else:
116
+ param_strs.append(str(param))
117
+
118
+ params_str = ", ".join(param_strs)
119
+ return_type = str(method.get("return_type", "void"))
120
+
121
+ modifiers = []
122
+ if method.get("is_static", False):
123
+ modifiers.append("[static]")
124
+
125
+ modifier_str = " ".join(modifiers)
126
+ signature = f"({params_str}):{return_type}"
127
+
128
+ if modifier_str:
129
+ signature += f" {modifier_str}"
130
+
131
+ return signature
132
+
133
+ def _convert_visibility(self, visibility: str) -> str:
134
+ """可視性を記号に変換"""
135
+ mapping = {"public": "+", "private": "-", "protected": "#", "package": "~"}
136
+ return mapping.get(visibility, visibility)
137
+
138
+ def _extract_doc_summary(self, javadoc: str) -> str:
139
+ """ドキュメントから要約を抽出"""
140
+ if not javadoc:
141
+ return "-"
142
+
143
+ # コメント記号を除去
144
+ clean_doc = (
145
+ javadoc.replace("/**", "").replace("*/", "").replace("*", "").strip()
146
+ )
147
+
148
+ # 最初の行を取得
149
+ lines = clean_doc.split("\n")
150
+ first_line = lines[0].strip()
151
+
152
+ # 長すぎる場合は切り詰め
153
+ if len(first_line) > 50:
154
+ first_line = first_line[:47] + "..."
155
+
156
+ return first_line.replace("|", "\\|").replace("\n", " ")
157
+
158
+ def _clean_csv_text(self, text: str) -> str:
159
+ """CSV形式用のテキストクリーニング"""
160
+ if not text:
161
+ return ""
162
+
163
+ cleaned = text.replace("\r\n", " ").replace("\r", " ").replace("\n", " ")
164
+ cleaned = " ".join(cleaned.split())
165
+ cleaned = cleaned.replace('"', '""')
166
+
167
+ return cleaned
@@ -1,74 +1,78 @@
1
- #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
- """
4
- Factory for creating language-specific table formatters.
5
- """
6
-
7
- from typing import Dict, Type
8
- from .base_formatter import BaseTableFormatter
9
- from .java_formatter import JavaTableFormatter
10
- from .python_formatter import PythonTableFormatter
11
-
12
-
13
- class TableFormatterFactory:
14
- """言語固有のテーブルフォーマッターを作成するファクトリー"""
15
-
16
- _formatters: Dict[str, Type[BaseTableFormatter]] = {
17
- "java": JavaTableFormatter,
18
- "python": PythonTableFormatter,
19
- }
20
-
21
- @classmethod
22
- def create_formatter(cls, language: str, format_type: str = "full") -> BaseTableFormatter:
23
- """
24
- 指定された言語用のテーブルフォーマッターを作成
25
-
26
- Args:
27
- language: プログラミング言語名
28
- format_type: フォーマットタイプ(full, compact, csv)
29
-
30
- Returns:
31
- 言語固有のテーブルフォーマッター
32
- """
33
- formatter_class = cls._formatters.get(language.lower())
34
-
35
- if formatter_class is None:
36
- # デフォルトとしてJavaフォーマッターを使用
37
- formatter_class = JavaTableFormatter
38
-
39
- return formatter_class(format_type)
40
-
41
- @classmethod
42
- def register_formatter(cls, language: str, formatter_class: Type[BaseTableFormatter]) -> None:
43
- """
44
- 新しい言語フォーマッターを登録
45
-
46
- Args:
47
- language: プログラミング言語名
48
- formatter_class: フォーマッタークラス
49
- """
50
- cls._formatters[language.lower()] = formatter_class
51
-
52
- @classmethod
53
- def get_supported_languages(cls) -> list[str]:
54
- """
55
- サポートされている言語一覧を取得
56
-
57
- Returns:
58
- サポートされている言語のリスト
59
- """
60
- return list(cls._formatters.keys())
61
-
62
-
63
- def create_table_formatter(format_type: str, language: str = "java") -> BaseTableFormatter:
64
- """
65
- テーブルフォーマッターを作成(互換性のための関数)
66
-
67
- Args:
68
- format_type: フォーマットタイプ
69
- language: プログラミング言語名
70
-
71
- Returns:
72
- テーブルフォーマッター
73
- """
74
- return TableFormatterFactory.create_formatter(language, format_type)
1
+ #!/usr/bin/env python3
2
+ """
3
+ Factory for creating language-specific table formatters.
4
+ """
5
+
6
+ from .base_formatter import BaseTableFormatter
7
+ from .java_formatter import JavaTableFormatter
8
+ from .python_formatter import PythonTableFormatter
9
+
10
+
11
+ class TableFormatterFactory:
12
+ """言語固有のテーブルフォーマッターを作成するファクトリー"""
13
+
14
+ _formatters: dict[str, type[BaseTableFormatter]] = {
15
+ "java": JavaTableFormatter,
16
+ "python": PythonTableFormatter,
17
+ }
18
+
19
+ @classmethod
20
+ def create_formatter(
21
+ cls, language: str, format_type: str = "full"
22
+ ) -> BaseTableFormatter:
23
+ """
24
+ 指定された言語用のテーブルフォーマッターを作成
25
+
26
+ Args:
27
+ language: プログラミング言語名
28
+ format_type: フォーマットタイプ(full, compact, csv)
29
+
30
+ Returns:
31
+ 言語固有のテーブルフォーマッター
32
+ """
33
+ formatter_class = cls._formatters.get(language.lower())
34
+
35
+ if formatter_class is None:
36
+ # デフォルトとしてJavaフォーマッターを使用
37
+ formatter_class = JavaTableFormatter
38
+
39
+ return formatter_class(format_type)
40
+
41
+ @classmethod
42
+ def register_formatter(
43
+ cls, language: str, formatter_class: type[BaseTableFormatter]
44
+ ) -> None:
45
+ """
46
+ 新しい言語フォーマッターを登録
47
+
48
+ Args:
49
+ language: プログラミング言語名
50
+ formatter_class: フォーマッタークラス
51
+ """
52
+ cls._formatters[language.lower()] = formatter_class
53
+
54
+ @classmethod
55
+ def get_supported_languages(cls) -> list[str]:
56
+ """
57
+ サポートされている言語一覧を取得
58
+
59
+ Returns:
60
+ サポートされている言語のリスト
61
+ """
62
+ return list(cls._formatters.keys())
63
+
64
+
65
+ def create_table_formatter(
66
+ format_type: str, language: str = "java"
67
+ ) -> BaseTableFormatter:
68
+ """
69
+ テーブルフォーマッターを作成(互換性のための関数)
70
+
71
+ Args:
72
+ format_type: フォーマットタイプ
73
+ language: プログラミング言語名
74
+
75
+ Returns:
76
+ テーブルフォーマッター
77
+ """
78
+ return TableFormatterFactory.create_formatter(language, format_type)