tree-sitter-analyzer 1.9.17.1__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.
Files changed (149) hide show
  1. tree_sitter_analyzer/__init__.py +132 -0
  2. tree_sitter_analyzer/__main__.py +11 -0
  3. tree_sitter_analyzer/api.py +853 -0
  4. tree_sitter_analyzer/cli/__init__.py +39 -0
  5. tree_sitter_analyzer/cli/__main__.py +12 -0
  6. tree_sitter_analyzer/cli/argument_validator.py +89 -0
  7. tree_sitter_analyzer/cli/commands/__init__.py +26 -0
  8. tree_sitter_analyzer/cli/commands/advanced_command.py +226 -0
  9. tree_sitter_analyzer/cli/commands/base_command.py +181 -0
  10. tree_sitter_analyzer/cli/commands/default_command.py +18 -0
  11. tree_sitter_analyzer/cli/commands/find_and_grep_cli.py +188 -0
  12. tree_sitter_analyzer/cli/commands/list_files_cli.py +133 -0
  13. tree_sitter_analyzer/cli/commands/partial_read_command.py +139 -0
  14. tree_sitter_analyzer/cli/commands/query_command.py +109 -0
  15. tree_sitter_analyzer/cli/commands/search_content_cli.py +161 -0
  16. tree_sitter_analyzer/cli/commands/structure_command.py +156 -0
  17. tree_sitter_analyzer/cli/commands/summary_command.py +116 -0
  18. tree_sitter_analyzer/cli/commands/table_command.py +414 -0
  19. tree_sitter_analyzer/cli/info_commands.py +124 -0
  20. tree_sitter_analyzer/cli_main.py +472 -0
  21. tree_sitter_analyzer/constants.py +85 -0
  22. tree_sitter_analyzer/core/__init__.py +15 -0
  23. tree_sitter_analyzer/core/analysis_engine.py +580 -0
  24. tree_sitter_analyzer/core/cache_service.py +333 -0
  25. tree_sitter_analyzer/core/engine.py +585 -0
  26. tree_sitter_analyzer/core/parser.py +293 -0
  27. tree_sitter_analyzer/core/query.py +605 -0
  28. tree_sitter_analyzer/core/query_filter.py +200 -0
  29. tree_sitter_analyzer/core/query_service.py +340 -0
  30. tree_sitter_analyzer/encoding_utils.py +530 -0
  31. tree_sitter_analyzer/exceptions.py +747 -0
  32. tree_sitter_analyzer/file_handler.py +246 -0
  33. tree_sitter_analyzer/formatters/__init__.py +1 -0
  34. tree_sitter_analyzer/formatters/base_formatter.py +201 -0
  35. tree_sitter_analyzer/formatters/csharp_formatter.py +367 -0
  36. tree_sitter_analyzer/formatters/formatter_config.py +197 -0
  37. tree_sitter_analyzer/formatters/formatter_factory.py +84 -0
  38. tree_sitter_analyzer/formatters/formatter_registry.py +377 -0
  39. tree_sitter_analyzer/formatters/formatter_selector.py +96 -0
  40. tree_sitter_analyzer/formatters/go_formatter.py +368 -0
  41. tree_sitter_analyzer/formatters/html_formatter.py +498 -0
  42. tree_sitter_analyzer/formatters/java_formatter.py +423 -0
  43. tree_sitter_analyzer/formatters/javascript_formatter.py +611 -0
  44. tree_sitter_analyzer/formatters/kotlin_formatter.py +268 -0
  45. tree_sitter_analyzer/formatters/language_formatter_factory.py +123 -0
  46. tree_sitter_analyzer/formatters/legacy_formatter_adapters.py +228 -0
  47. tree_sitter_analyzer/formatters/markdown_formatter.py +725 -0
  48. tree_sitter_analyzer/formatters/php_formatter.py +301 -0
  49. tree_sitter_analyzer/formatters/python_formatter.py +830 -0
  50. tree_sitter_analyzer/formatters/ruby_formatter.py +278 -0
  51. tree_sitter_analyzer/formatters/rust_formatter.py +233 -0
  52. tree_sitter_analyzer/formatters/sql_formatter_wrapper.py +689 -0
  53. tree_sitter_analyzer/formatters/sql_formatters.py +536 -0
  54. tree_sitter_analyzer/formatters/typescript_formatter.py +543 -0
  55. tree_sitter_analyzer/formatters/yaml_formatter.py +462 -0
  56. tree_sitter_analyzer/interfaces/__init__.py +9 -0
  57. tree_sitter_analyzer/interfaces/cli.py +535 -0
  58. tree_sitter_analyzer/interfaces/cli_adapter.py +359 -0
  59. tree_sitter_analyzer/interfaces/mcp_adapter.py +224 -0
  60. tree_sitter_analyzer/interfaces/mcp_server.py +428 -0
  61. tree_sitter_analyzer/language_detector.py +553 -0
  62. tree_sitter_analyzer/language_loader.py +271 -0
  63. tree_sitter_analyzer/languages/__init__.py +10 -0
  64. tree_sitter_analyzer/languages/csharp_plugin.py +1076 -0
  65. tree_sitter_analyzer/languages/css_plugin.py +449 -0
  66. tree_sitter_analyzer/languages/go_plugin.py +836 -0
  67. tree_sitter_analyzer/languages/html_plugin.py +496 -0
  68. tree_sitter_analyzer/languages/java_plugin.py +1299 -0
  69. tree_sitter_analyzer/languages/javascript_plugin.py +1622 -0
  70. tree_sitter_analyzer/languages/kotlin_plugin.py +656 -0
  71. tree_sitter_analyzer/languages/markdown_plugin.py +1928 -0
  72. tree_sitter_analyzer/languages/php_plugin.py +862 -0
  73. tree_sitter_analyzer/languages/python_plugin.py +1636 -0
  74. tree_sitter_analyzer/languages/ruby_plugin.py +757 -0
  75. tree_sitter_analyzer/languages/rust_plugin.py +673 -0
  76. tree_sitter_analyzer/languages/sql_plugin.py +2444 -0
  77. tree_sitter_analyzer/languages/typescript_plugin.py +1892 -0
  78. tree_sitter_analyzer/languages/yaml_plugin.py +695 -0
  79. tree_sitter_analyzer/legacy_table_formatter.py +860 -0
  80. tree_sitter_analyzer/mcp/__init__.py +34 -0
  81. tree_sitter_analyzer/mcp/resources/__init__.py +43 -0
  82. tree_sitter_analyzer/mcp/resources/code_file_resource.py +208 -0
  83. tree_sitter_analyzer/mcp/resources/project_stats_resource.py +586 -0
  84. tree_sitter_analyzer/mcp/server.py +869 -0
  85. tree_sitter_analyzer/mcp/tools/__init__.py +28 -0
  86. tree_sitter_analyzer/mcp/tools/analyze_scale_tool.py +779 -0
  87. tree_sitter_analyzer/mcp/tools/analyze_scale_tool_cli_compatible.py +291 -0
  88. tree_sitter_analyzer/mcp/tools/base_tool.py +139 -0
  89. tree_sitter_analyzer/mcp/tools/fd_rg_utils.py +816 -0
  90. tree_sitter_analyzer/mcp/tools/find_and_grep_tool.py +686 -0
  91. tree_sitter_analyzer/mcp/tools/list_files_tool.py +413 -0
  92. tree_sitter_analyzer/mcp/tools/output_format_validator.py +148 -0
  93. tree_sitter_analyzer/mcp/tools/query_tool.py +443 -0
  94. tree_sitter_analyzer/mcp/tools/read_partial_tool.py +464 -0
  95. tree_sitter_analyzer/mcp/tools/search_content_tool.py +836 -0
  96. tree_sitter_analyzer/mcp/tools/table_format_tool.py +572 -0
  97. tree_sitter_analyzer/mcp/tools/universal_analyze_tool.py +653 -0
  98. tree_sitter_analyzer/mcp/utils/__init__.py +113 -0
  99. tree_sitter_analyzer/mcp/utils/error_handler.py +569 -0
  100. tree_sitter_analyzer/mcp/utils/file_output_factory.py +217 -0
  101. tree_sitter_analyzer/mcp/utils/file_output_manager.py +322 -0
  102. tree_sitter_analyzer/mcp/utils/gitignore_detector.py +358 -0
  103. tree_sitter_analyzer/mcp/utils/path_resolver.py +414 -0
  104. tree_sitter_analyzer/mcp/utils/search_cache.py +343 -0
  105. tree_sitter_analyzer/models.py +840 -0
  106. tree_sitter_analyzer/mypy_current_errors.txt +2 -0
  107. tree_sitter_analyzer/output_manager.py +255 -0
  108. tree_sitter_analyzer/platform_compat/__init__.py +3 -0
  109. tree_sitter_analyzer/platform_compat/adapter.py +324 -0
  110. tree_sitter_analyzer/platform_compat/compare.py +224 -0
  111. tree_sitter_analyzer/platform_compat/detector.py +67 -0
  112. tree_sitter_analyzer/platform_compat/fixtures.py +228 -0
  113. tree_sitter_analyzer/platform_compat/profiles.py +217 -0
  114. tree_sitter_analyzer/platform_compat/record.py +55 -0
  115. tree_sitter_analyzer/platform_compat/recorder.py +155 -0
  116. tree_sitter_analyzer/platform_compat/report.py +92 -0
  117. tree_sitter_analyzer/plugins/__init__.py +280 -0
  118. tree_sitter_analyzer/plugins/base.py +647 -0
  119. tree_sitter_analyzer/plugins/manager.py +384 -0
  120. tree_sitter_analyzer/project_detector.py +328 -0
  121. tree_sitter_analyzer/queries/__init__.py +27 -0
  122. tree_sitter_analyzer/queries/csharp.py +216 -0
  123. tree_sitter_analyzer/queries/css.py +615 -0
  124. tree_sitter_analyzer/queries/go.py +275 -0
  125. tree_sitter_analyzer/queries/html.py +543 -0
  126. tree_sitter_analyzer/queries/java.py +402 -0
  127. tree_sitter_analyzer/queries/javascript.py +724 -0
  128. tree_sitter_analyzer/queries/kotlin.py +192 -0
  129. tree_sitter_analyzer/queries/markdown.py +258 -0
  130. tree_sitter_analyzer/queries/php.py +95 -0
  131. tree_sitter_analyzer/queries/python.py +859 -0
  132. tree_sitter_analyzer/queries/ruby.py +92 -0
  133. tree_sitter_analyzer/queries/rust.py +223 -0
  134. tree_sitter_analyzer/queries/sql.py +555 -0
  135. tree_sitter_analyzer/queries/typescript.py +871 -0
  136. tree_sitter_analyzer/queries/yaml.py +236 -0
  137. tree_sitter_analyzer/query_loader.py +272 -0
  138. tree_sitter_analyzer/security/__init__.py +22 -0
  139. tree_sitter_analyzer/security/boundary_manager.py +277 -0
  140. tree_sitter_analyzer/security/regex_checker.py +297 -0
  141. tree_sitter_analyzer/security/validator.py +599 -0
  142. tree_sitter_analyzer/table_formatter.py +782 -0
  143. tree_sitter_analyzer/utils/__init__.py +53 -0
  144. tree_sitter_analyzer/utils/logging.py +433 -0
  145. tree_sitter_analyzer/utils/tree_sitter_compat.py +289 -0
  146. tree_sitter_analyzer-1.9.17.1.dist-info/METADATA +485 -0
  147. tree_sitter_analyzer-1.9.17.1.dist-info/RECORD +149 -0
  148. tree_sitter_analyzer-1.9.17.1.dist-info/WHEEL +4 -0
  149. tree_sitter_analyzer-1.9.17.1.dist-info/entry_points.txt +25 -0
@@ -0,0 +1,280 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Plugin System for Multi-Language Code Analysis
4
+
5
+ This package provides a plugin-based architecture for extending
6
+ the tree-sitter analyzer with language-specific parsers and extractors.
7
+ """
8
+
9
+ from abc import ABC, abstractmethod
10
+ from typing import TYPE_CHECKING
11
+
12
+ if TYPE_CHECKING:
13
+ import tree_sitter
14
+
15
+ # from ..models import (
16
+ # CodeElement,
17
+ # ) # Not used currently
18
+ from ..models import Class as ModelClass
19
+ from ..models import Function as ModelFunction
20
+ from ..models import Import as ModelImport
21
+ from ..models import Variable as ModelVariable
22
+ from ..utils import log_debug, log_error, log_warning
23
+
24
+ __all__ = [
25
+ "LanguagePlugin",
26
+ "ElementExtractor",
27
+ "DefaultExtractor",
28
+ "DefaultLanguagePlugin",
29
+ ]
30
+
31
+
32
+ class ElementExtractor(ABC):
33
+ """Abstract base class for language-specific element extractors"""
34
+
35
+ @abstractmethod
36
+ def extract_functions(
37
+ self, tree: "tree_sitter.Tree", source_code: str
38
+ ) -> list[ModelFunction]:
39
+ """Extract function definitions from the syntax tree"""
40
+ log_warning("extract_functions not implemented in subclass")
41
+ return []
42
+
43
+ @abstractmethod
44
+ def extract_classes(
45
+ self, tree: "tree_sitter.Tree", source_code: str
46
+ ) -> list[ModelClass]:
47
+ """Extract class definitions from the syntax tree"""
48
+ log_warning("extract_classes not implemented in subclass")
49
+ return []
50
+
51
+ @abstractmethod
52
+ def extract_variables(
53
+ self, tree: "tree_sitter.Tree", source_code: str
54
+ ) -> list[ModelVariable]:
55
+ """Extract variable declarations from the syntax tree"""
56
+ log_warning("extract_variables not implemented in subclass")
57
+ return []
58
+
59
+ @abstractmethod
60
+ def extract_imports(
61
+ self, tree: "tree_sitter.Tree", source_code: str
62
+ ) -> list[ModelImport]:
63
+ """Extract import statements from the syntax tree"""
64
+ log_warning("extract_imports not implemented in subclass")
65
+ return []
66
+
67
+
68
+ class LanguagePlugin(ABC):
69
+ """Abstract base class for language-specific plugins"""
70
+
71
+ @abstractmethod
72
+ def get_language_name(self) -> str:
73
+ """Return the name of the programming language this plugin supports"""
74
+ return "unknown"
75
+
76
+ @abstractmethod
77
+ def get_file_extensions(self) -> list[str]:
78
+ """Return list of file extensions this plugin supports"""
79
+ return []
80
+
81
+ @abstractmethod
82
+ def create_extractor(self) -> ElementExtractor:
83
+ """Create and return an element extractor for this language"""
84
+ return DefaultExtractor()
85
+
86
+ def is_applicable(self, file_path: str) -> bool:
87
+ """Check if this plugin is applicable for the given file"""
88
+ extensions = self.get_file_extensions()
89
+ return any(file_path.lower().endswith(ext.lower()) for ext in extensions)
90
+
91
+
92
+ class DefaultExtractor(ElementExtractor):
93
+ """Default implementation of ElementExtractor with basic functionality"""
94
+
95
+ def extract_functions(
96
+ self, tree: "tree_sitter.Tree", source_code: str
97
+ ) -> list[ModelFunction]:
98
+ """Basic function extraction implementation"""
99
+ functions: list[ModelFunction] = []
100
+ try:
101
+ if hasattr(tree, "root_node"):
102
+ # Generic function extraction logic
103
+ self._traverse_for_functions(
104
+ tree.root_node, functions, source_code.splitlines()
105
+ )
106
+ except Exception as e:
107
+ log_error(f"Error in function extraction: {e}")
108
+ return functions
109
+
110
+ def extract_classes(
111
+ self, tree: "tree_sitter.Tree", source_code: str
112
+ ) -> list[ModelClass]:
113
+ """Basic class extraction implementation"""
114
+ classes: list[ModelClass] = []
115
+ try:
116
+ if hasattr(tree, "root_node"):
117
+ # Generic class extraction logic
118
+ self._traverse_for_classes(
119
+ tree.root_node, classes, source_code.splitlines()
120
+ )
121
+ except Exception as e:
122
+ log_error(f"Error in class extraction: {e}")
123
+ return classes
124
+
125
+ def extract_variables(
126
+ self, tree: "tree_sitter.Tree", source_code: str
127
+ ) -> list[ModelVariable]:
128
+ """Basic variable extraction implementation"""
129
+ variables: list[ModelVariable] = []
130
+ try:
131
+ if hasattr(tree, "root_node"):
132
+ # Generic variable extraction logic
133
+ self._traverse_for_variables(
134
+ tree.root_node, variables, source_code.splitlines()
135
+ )
136
+ except Exception as e:
137
+ log_error(f"Error in variable extraction: {e}")
138
+ return variables
139
+
140
+ def extract_imports(
141
+ self, tree: "tree_sitter.Tree", source_code: str
142
+ ) -> list[ModelImport]:
143
+ """Basic import extraction implementation"""
144
+ imports: list[ModelImport] = []
145
+ try:
146
+ if hasattr(tree, "root_node"):
147
+ # Generic import extraction logic
148
+ self._traverse_for_imports(
149
+ tree.root_node, imports, source_code.splitlines()
150
+ )
151
+ except Exception as e:
152
+ log_error(f"Error in import extraction: {e}")
153
+ return imports
154
+
155
+ def _traverse_for_functions(
156
+ self, node: "tree_sitter.Node", functions: list[ModelFunction], lines: list[str]
157
+ ) -> None:
158
+ """Traverse tree to find function-like nodes"""
159
+ if hasattr(node, "type") and "function" in node.type.lower():
160
+ try:
161
+ func = ModelFunction(
162
+ name=self._extract_node_name(node) or "unknown",
163
+ start_line=(
164
+ node.start_point[0] + 1 if hasattr(node, "start_point") else 0
165
+ ),
166
+ end_line=node.end_point[0] + 1 if hasattr(node, "end_point") else 0,
167
+ raw_text="",
168
+ language="unknown",
169
+ )
170
+ functions.append(func)
171
+ except Exception as e:
172
+ log_debug(f"Failed to extract function: {e}")
173
+
174
+ if hasattr(node, "children"):
175
+ for child in node.children:
176
+ self._traverse_for_functions(child, functions, lines)
177
+
178
+ def _traverse_for_classes(
179
+ self, node: "tree_sitter.Node", classes: list[ModelClass], lines: list[str]
180
+ ) -> None:
181
+ """Traverse tree to find class-like nodes"""
182
+ if hasattr(node, "type") and "class" in node.type.lower():
183
+ try:
184
+ cls = ModelClass(
185
+ name=self._extract_node_name(node) or "unknown",
186
+ start_line=(
187
+ node.start_point[0] + 1 if hasattr(node, "start_point") else 0
188
+ ),
189
+ end_line=node.end_point[0] + 1 if hasattr(node, "end_point") else 0,
190
+ raw_text="",
191
+ language="unknown",
192
+ )
193
+ classes.append(cls)
194
+ except Exception as e:
195
+ log_debug(f"Failed to extract class: {e}")
196
+
197
+ if hasattr(node, "children"):
198
+ for child in node.children:
199
+ self._traverse_for_classes(child, classes, lines)
200
+
201
+ def _traverse_for_variables(
202
+ self, node: "tree_sitter.Node", variables: list[ModelVariable], lines: list[str]
203
+ ) -> None:
204
+ """Traverse tree to find variable declarations"""
205
+ if hasattr(node, "type") and (
206
+ "variable" in node.type.lower() or "declaration" in node.type.lower()
207
+ ):
208
+ try:
209
+ var = ModelVariable(
210
+ name=self._extract_node_name(node) or "unknown",
211
+ start_line=(
212
+ node.start_point[0] + 1 if hasattr(node, "start_point") else 0
213
+ ),
214
+ end_line=node.end_point[0] + 1 if hasattr(node, "end_point") else 0,
215
+ raw_text="",
216
+ language="unknown",
217
+ )
218
+ variables.append(var)
219
+ except Exception as e:
220
+ log_debug(f"Failed to extract variable: {e}")
221
+
222
+ if hasattr(node, "children"):
223
+ for child in node.children:
224
+ self._traverse_for_variables(child, variables, lines)
225
+
226
+ def _traverse_for_imports(
227
+ self, node: "tree_sitter.Node", imports: list[ModelImport], lines: list[str]
228
+ ) -> None:
229
+ """Traverse tree to find import statements"""
230
+ if hasattr(node, "type") and "import" in node.type.lower():
231
+ try:
232
+ imp = ModelImport(
233
+ name=self._extract_node_name(node) or "unknown",
234
+ start_line=(
235
+ node.start_point[0] + 1 if hasattr(node, "start_point") else 0
236
+ ),
237
+ end_line=node.end_point[0] + 1 if hasattr(node, "end_point") else 0,
238
+ raw_text="",
239
+ language="unknown",
240
+ )
241
+ imports.append(imp)
242
+ except Exception as e:
243
+ log_debug(f"Failed to extract import: {e}")
244
+
245
+ if hasattr(node, "children"):
246
+ for child in node.children:
247
+ self._traverse_for_imports(child, imports, lines)
248
+
249
+ def _extract_node_name(self, node: "tree_sitter.Node") -> str | None:
250
+ """Extract name from a tree-sitter node"""
251
+ try:
252
+ # Look for identifier children
253
+ if hasattr(node, "children"):
254
+ for child in node.children:
255
+ if hasattr(child, "type") and child.type == "identifier":
256
+ # This would need actual text extraction in real implementation
257
+ return f"element_{child.start_point[0]}_{child.start_point[1]}"
258
+ return None
259
+ except Exception:
260
+ return None
261
+
262
+
263
+ # Legacy PluginRegistry removed - now using PluginManager from .manager
264
+
265
+
266
+ class DefaultLanguagePlugin(LanguagePlugin):
267
+ """Default plugin that provides basic functionality for any language"""
268
+
269
+ def get_language_name(self) -> str:
270
+ return "generic"
271
+
272
+ def get_file_extensions(self) -> list[str]:
273
+ return [".txt", ".md"] # Fallback extensions
274
+
275
+ def create_extractor(self) -> ElementExtractor:
276
+ return DefaultExtractor()
277
+
278
+
279
+ # Legacy plugin registry removed - now using PluginManager
280
+ # from .manager import PluginManager