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,34 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ MCP (Model Context Protocol) integration for Tree-sitter Analyzer
4
+
5
+ This module provides MCP server functionality that exposes the tree-sitter
6
+ analyzer capabilities through the Model Context Protocol.
7
+ """
8
+
9
+ from typing import Any
10
+
11
+ # Import main package version for consistency
12
+ try:
13
+ from .. import __version__ as main_version
14
+
15
+ __version__ = main_version
16
+ except ImportError:
17
+ # Fallback version if main package not available
18
+ __version__ = "1.1.1"
19
+
20
+ __author__ = "Tree-sitter Analyzer Team"
21
+
22
+ # MCP module metadata
23
+ MCP_INFO: dict[str, Any] = {
24
+ "name": "tree-sitter-analyzer-mcp",
25
+ "version": __version__,
26
+ "description": "Tree-sitter based code analyzer with MCP support - Solve LLM token limit problems for large code files",
27
+ "protocol_version": "2024-11-05",
28
+ "capabilities": {"tools": {}, "resources": {}, "prompts": {}, "logging": {}},
29
+ }
30
+
31
+ __all__ = [
32
+ "MCP_INFO",
33
+ "__version__",
34
+ ]
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ MCP Resources Module
4
+
5
+ This module provides MCP (Model Context Protocol) resource implementations
6
+ for the tree-sitter-analyzer project. Resources provide dynamic content
7
+ access through URI-based identification.
8
+
9
+ Resources:
10
+ - CodeFileResource: Access to code file content
11
+ - ProjectStatsResource: Access to project statistics and analysis data
12
+
13
+ The resources integrate with existing analyzer components to provide
14
+ seamless access to code analysis functionality through the MCP protocol.
15
+ """
16
+
17
+ # Export main resource classes
18
+ from .code_file_resource import CodeFileResource
19
+ from .project_stats_resource import ProjectStatsResource
20
+
21
+ # Resource metadata
22
+ __author__ = "Tree-Sitter Analyzer Team"
23
+
24
+ # MCP Resource capabilities
25
+ MCP_RESOURCE_CAPABILITIES = {
26
+ "version": "2024-11-05",
27
+ "resources": [
28
+ {
29
+ "name": "code_file",
30
+ "description": "Access to code file content",
31
+ "uri_template": "code://file/{file_path}",
32
+ "mime_type": "text/plain",
33
+ },
34
+ {
35
+ "name": "project_stats",
36
+ "description": "Access to project statistics and analysis data",
37
+ "uri_template": "code://stats/{stats_type}",
38
+ "mime_type": "application/json",
39
+ },
40
+ ],
41
+ }
42
+
43
+ __all__ = ["CodeFileResource", "ProjectStatsResource", "MCP_RESOURCE_CAPABILITIES"]
@@ -0,0 +1,208 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Code File Resource for MCP
4
+
5
+ This module provides MCP resource implementation for accessing code file content.
6
+ The resource allows dynamic access to file content through URI-based identification.
7
+ """
8
+
9
+ import logging
10
+ import re
11
+ from pathlib import Path
12
+ from typing import Any
13
+
14
+ from tree_sitter_analyzer.encoding_utils import read_file_safe
15
+
16
+ logger = logging.getLogger(__name__)
17
+
18
+
19
+ class CodeFileResource:
20
+ """
21
+ MCP resource for accessing code file content
22
+
23
+ This resource provides access to code file content through the MCP protocol.
24
+ It supports reading files with proper encoding detection and error handling.
25
+
26
+ URI Format: code://file/{file_path}
27
+
28
+ Examples:
29
+ - code://file/src/main/java/Example.java
30
+ - code://file/scripts/helper.py
31
+ - code://file/test.js
32
+ """
33
+
34
+ def __init__(self) -> None:
35
+ """Initialize the code file resource"""
36
+ self._uri_pattern = re.compile(r"^code://file/(.+)$")
37
+
38
+ def get_resource_info(self) -> dict[str, Any]:
39
+ """
40
+ Get resource information for MCP registration
41
+
42
+ Returns:
43
+ Dict containing resource metadata
44
+ """
45
+ return {
46
+ "name": "code_file",
47
+ "description": "Access to code file content through URI-based identification",
48
+ "uri_template": "code://file/{file_path}",
49
+ "mime_type": "text/plain",
50
+ }
51
+
52
+ def matches_uri(self, uri: str) -> bool:
53
+ """
54
+ Check if the URI matches this resource pattern
55
+
56
+ Args:
57
+ uri: The URI to check
58
+
59
+ Returns:
60
+ True if the URI matches the code file pattern
61
+ """
62
+ return bool(self._uri_pattern.match(uri))
63
+
64
+ def _extract_file_path(self, uri: str) -> str:
65
+ """
66
+ Extract file path from URI
67
+
68
+ Args:
69
+ uri: The URI to extract path from
70
+
71
+ Returns:
72
+ The extracted file path
73
+
74
+ Raises:
75
+ ValueError: If URI format is invalid
76
+ """
77
+ match = self._uri_pattern.match(uri)
78
+ if not match:
79
+ raise ValueError(f"Invalid URI format: {uri}")
80
+
81
+ return match.group(1)
82
+
83
+ async def _read_file_content(self, file_path: str) -> str:
84
+ """
85
+ Read file content with proper encoding detection
86
+
87
+ Args:
88
+ file_path: Path to the file to read
89
+
90
+ Returns:
91
+ File content as string
92
+
93
+ Raises:
94
+ FileNotFoundError: If file doesn't exist
95
+ PermissionError: If file cannot be read due to permissions
96
+ OSError: If file cannot be read due to other OS errors
97
+ """
98
+ try:
99
+ # Use existing encoding-safe file reader
100
+ # Check if file exists first
101
+ if not Path(file_path).exists():
102
+ raise FileNotFoundError(f"File not found: {file_path}")
103
+
104
+ content, encoding = read_file_safe(file_path)
105
+ return content
106
+
107
+ except FileNotFoundError:
108
+ logger.error(f"File not found: {file_path}")
109
+ raise
110
+ except PermissionError:
111
+ logger.error(f"Permission denied reading file: {file_path}")
112
+ raise
113
+ except OSError as e:
114
+ logger.error(f"OS error reading file {file_path}: {e}")
115
+ raise
116
+ except Exception as e:
117
+ logger.error(f"Unexpected error reading file {file_path}: {e}")
118
+ raise OSError(f"Failed to read file: {e}") from e
119
+
120
+ def _validate_file_path(self, file_path: str) -> None:
121
+ """
122
+ Validate file path for security and correctness
123
+
124
+ Args:
125
+ file_path: The file path to validate
126
+
127
+ Raises:
128
+ ValueError: If file path is invalid or potentially dangerous
129
+ """
130
+ if not file_path:
131
+ raise ValueError("File path cannot be empty")
132
+
133
+ # Check for null bytes
134
+ if "\x00" in file_path:
135
+ raise ValueError("File path contains null bytes")
136
+
137
+ # Check for potentially dangerous path traversal
138
+ if ".." in file_path:
139
+ raise ValueError(f"Path traversal not allowed: {file_path}")
140
+
141
+ # Additional security checks could be added here
142
+ # For example, restricting to certain directories
143
+
144
+ async def read_resource(self, uri: str) -> str:
145
+ """
146
+ Read resource content from URI
147
+
148
+ Args:
149
+ uri: The resource URI to read
150
+
151
+ Returns:
152
+ Resource content as string
153
+
154
+ Raises:
155
+ ValueError: If URI format is invalid
156
+ FileNotFoundError: If file doesn't exist
157
+ PermissionError: If file cannot be read due to permissions
158
+ OSError: If file cannot be read due to other errors
159
+ """
160
+ logger.debug(f"Reading resource: {uri}")
161
+
162
+ # Validate URI format
163
+ if not self.matches_uri(uri):
164
+ raise ValueError(f"URI does not match code file pattern: {uri}")
165
+
166
+ # Extract file path
167
+ file_path = self._extract_file_path(uri)
168
+
169
+ # Validate file path
170
+ self._validate_file_path(file_path)
171
+
172
+ # Read file content
173
+ try:
174
+ content = await self._read_file_content(file_path)
175
+ logger.debug(
176
+ f"Successfully read {len(content)} characters from {file_path}"
177
+ )
178
+ return content
179
+
180
+ except Exception as e:
181
+ logger.error(f"Failed to read resource {uri}: {e}")
182
+ raise
183
+
184
+ def get_supported_schemes(self) -> list[str]:
185
+ """
186
+ Get list of supported URI schemes
187
+
188
+ Returns:
189
+ List of supported schemes
190
+ """
191
+ return ["code"]
192
+
193
+ def get_supported_resource_types(self) -> list[str]:
194
+ """
195
+ Get list of supported resource types
196
+
197
+ Returns:
198
+ List of supported resource types
199
+ """
200
+ return ["file"]
201
+
202
+ def __str__(self) -> str:
203
+ """String representation of the resource"""
204
+ return "CodeFileResource(pattern=code://file/{file_path})"
205
+
206
+ def __repr__(self) -> str:
207
+ """Detailed string representation of the resource"""
208
+ return f"CodeFileResource(uri_pattern={self._uri_pattern.pattern})"