tree-sitter-analyzer 0.1.3__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.

Files changed (79) hide show
  1. tree_sitter_analyzer/__init__.py +133 -121
  2. tree_sitter_analyzer/__main__.py +11 -12
  3. tree_sitter_analyzer/api.py +531 -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 +232 -233
  15. tree_sitter_analyzer/cli/info_commands.py +120 -121
  16. tree_sitter_analyzer/cli_main.py +277 -276
  17. tree_sitter_analyzer/core/__init__.py +15 -20
  18. tree_sitter_analyzer/core/analysis_engine.py +591 -574
  19. tree_sitter_analyzer/core/cache_service.py +320 -330
  20. tree_sitter_analyzer/core/engine.py +557 -560
  21. tree_sitter_analyzer/core/parser.py +293 -288
  22. tree_sitter_analyzer/core/query.py +494 -502
  23. tree_sitter_analyzer/encoding_utils.py +458 -460
  24. tree_sitter_analyzer/exceptions.py +337 -340
  25. tree_sitter_analyzer/file_handler.py +217 -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 +287 -270
  30. tree_sitter_analyzer/formatters/python_formatter.py +255 -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 +322 -319
  34. tree_sitter_analyzer/interfaces/mcp_adapter.py +180 -170
  35. tree_sitter_analyzer/interfaces/mcp_server.py +405 -416
  36. tree_sitter_analyzer/java_analyzer.py +218 -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 +1129 -1113
  41. tree_sitter_analyzer/languages/python_plugin.py +737 -712
  42. tree_sitter_analyzer/mcp/__init__.py +31 -32
  43. tree_sitter_analyzer/mcp/resources/__init__.py +44 -47
  44. tree_sitter_analyzer/mcp/resources/code_file_resource.py +212 -213
  45. tree_sitter_analyzer/mcp/resources/project_stats_resource.py +560 -550
  46. tree_sitter_analyzer/mcp/server.py +333 -345
  47. tree_sitter_analyzer/mcp/tools/__init__.py +30 -31
  48. tree_sitter_analyzer/mcp/tools/analyze_scale_tool.py +621 -557
  49. tree_sitter_analyzer/mcp/tools/analyze_scale_tool_cli_compatible.py +242 -245
  50. tree_sitter_analyzer/mcp/tools/base_tool.py +54 -55
  51. tree_sitter_analyzer/mcp/tools/read_partial_tool.py +300 -302
  52. tree_sitter_analyzer/mcp/tools/table_format_tool.py +362 -359
  53. tree_sitter_analyzer/mcp/tools/universal_analyze_tool.py +543 -476
  54. tree_sitter_analyzer/mcp/utils/__init__.py +105 -106
  55. tree_sitter_analyzer/mcp/utils/error_handler.py +549 -549
  56. tree_sitter_analyzer/models.py +470 -481
  57. tree_sitter_analyzer/output_manager.py +261 -264
  58. tree_sitter_analyzer/plugins/__init__.py +333 -334
  59. tree_sitter_analyzer/plugins/base.py +477 -446
  60. tree_sitter_analyzer/plugins/java_plugin.py +608 -625
  61. tree_sitter_analyzer/plugins/javascript_plugin.py +446 -439
  62. tree_sitter_analyzer/plugins/manager.py +362 -355
  63. tree_sitter_analyzer/plugins/plugin_loader.py +85 -83
  64. tree_sitter_analyzer/plugins/python_plugin.py +606 -598
  65. tree_sitter_analyzer/plugins/registry.py +374 -366
  66. tree_sitter_analyzer/queries/__init__.py +26 -27
  67. tree_sitter_analyzer/queries/java.py +391 -394
  68. tree_sitter_analyzer/queries/javascript.py +148 -149
  69. tree_sitter_analyzer/queries/python.py +285 -286
  70. tree_sitter_analyzer/queries/typescript.py +229 -230
  71. tree_sitter_analyzer/query_loader.py +254 -260
  72. tree_sitter_analyzer/table_formatter.py +468 -448
  73. tree_sitter_analyzer/utils.py +277 -277
  74. tree_sitter_analyzer-0.3.0.dist-info/METADATA +346 -0
  75. tree_sitter_analyzer-0.3.0.dist-info/RECORD +77 -0
  76. tree_sitter_analyzer-0.1.3.dist-info/METADATA +0 -444
  77. tree_sitter_analyzer-0.1.3.dist-info/RECORD +0 -77
  78. {tree_sitter_analyzer-0.1.3.dist-info → tree_sitter_analyzer-0.3.0.dist-info}/WHEEL +0 -0
  79. {tree_sitter_analyzer-0.1.3.dist-info → tree_sitter_analyzer-0.3.0.dist-info}/entry_points.txt +0 -0
@@ -1,32 +1,31 @@
1
- #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
- """
4
- MCP (Model Context Protocol) integration for Tree-sitter Analyzer
5
-
6
- This module provides MCP server functionality that exposes the tree-sitter
7
- analyzer capabilities through the Model Context Protocol.
8
- """
9
-
10
- from typing import Any, Dict
11
-
12
- __version__ = "1.0.0"
13
- __author__ = "Tree-sitter Analyzer Team"
14
-
15
- # MCP module metadata
16
- MCP_INFO: Dict[str, Any] = {
17
- "name": "tree-sitter-analyzer-mcp",
18
- "version": __version__,
19
- "description": "Tree-sitter based code analyzer with MCP support",
20
- "protocol_version": "2024-11-05",
21
- "capabilities": {
22
- "tools": {},
23
- "resources": {},
24
- "prompts": {},
25
- "logging": {},
26
- },
27
- }
28
-
29
- __all__ = [
30
- "MCP_INFO",
31
- "__version__",
32
- ]
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
+ __version__ = "0.2.1"
12
+ __author__ = "Tree-sitter Analyzer Team"
13
+
14
+ # MCP module metadata
15
+ MCP_INFO: dict[str, Any] = {
16
+ "name": "tree-sitter-analyzer-mcp",
17
+ "version": __version__,
18
+ "description": "Tree-sitter based code analyzer with MCP support",
19
+ "protocol_version": "2024-11-05",
20
+ "capabilities": {
21
+ "tools": {},
22
+ "resources": {},
23
+ "prompts": {},
24
+ "logging": {},
25
+ },
26
+ }
27
+
28
+ __all__ = [
29
+ "MCP_INFO",
30
+ "__version__",
31
+ ]
@@ -1,47 +1,44 @@
1
- #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
- """
4
- MCP Resources Module
5
-
6
- This module provides MCP (Model Context Protocol) resource implementations
7
- for the tree-sitter-analyzer project. Resources provide dynamic content
8
- access through URI-based identification.
9
-
10
- Resources:
11
- - CodeFileResource: Access to code file content
12
- - ProjectStatsResource: Access to project statistics and analysis data
13
-
14
- The resources integrate with existing analyzer components to provide
15
- seamless access to code analysis functionality through the MCP protocol.
16
- """
17
-
18
- from typing import Any, Dict
19
-
20
- # Resource metadata
21
- __version__ = "1.0.0"
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
- # Export main resource classes
44
- from .code_file_resource import CodeFileResource
45
- from .project_stats_resource import ProjectStatsResource
46
-
47
- __all__ = ["CodeFileResource", "ProjectStatsResource", "MCP_RESOURCE_CAPABILITIES"]
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
+ __version__ = "1.0.0"
23
+ __author__ = "Tree-Sitter Analyzer Team"
24
+
25
+ # MCP Resource capabilities
26
+ MCP_RESOURCE_CAPABILITIES = {
27
+ "version": "2024-11-05",
28
+ "resources": [
29
+ {
30
+ "name": "code_file",
31
+ "description": "Access to code file content",
32
+ "uri_template": "code://file/{file_path}",
33
+ "mime_type": "text/plain",
34
+ },
35
+ {
36
+ "name": "project_stats",
37
+ "description": "Access to project statistics and analysis data",
38
+ "uri_template": "code://stats/{stats_type}",
39
+ "mime_type": "application/json",
40
+ },
41
+ ],
42
+ }
43
+
44
+ __all__ = ["CodeFileResource", "ProjectStatsResource", "MCP_RESOURCE_CAPABILITIES"]
@@ -1,213 +1,212 @@
1
- #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
- """
4
- Code File Resource for MCP
5
-
6
- This module provides MCP resource implementation for accessing code file content.
7
- The resource allows dynamic access to file content through URI-based identification.
8
- """
9
-
10
- import logging
11
- import re
12
- from pathlib import Path
13
- from typing import Any, Dict, Optional
14
-
15
- from tree_sitter_analyzer.encoding_utils import read_file_safe
16
-
17
- logger = logging.getLogger(__name__)
18
-
19
-
20
- class CodeFileResource:
21
- """
22
- MCP resource for accessing code file content
23
-
24
- This resource provides access to code file content through the MCP protocol.
25
- It supports reading files with proper encoding detection and error handling.
26
-
27
- URI Format: code://file/{file_path}
28
-
29
- Examples:
30
- - code://file/src/main/java/Example.java
31
- - code://file/scripts/helper.py
32
- - code://file/test.js
33
- """
34
-
35
- def __init__(self) -> None:
36
- """Initialize the code file resource"""
37
- self._uri_pattern = re.compile(r"^code://file/(.+)$")
38
-
39
- def get_resource_info(self) -> Dict[str, Any]:
40
- """
41
- Get resource information for MCP registration
42
-
43
- Returns:
44
- Dict containing resource metadata
45
- """
46
- return {
47
- "name": "code_file",
48
- "description": "Access to code file content through URI-based identification",
49
- "uri_template": "code://file/{file_path}",
50
- "mime_type": "text/plain",
51
- }
52
-
53
- def matches_uri(self, uri: str) -> bool:
54
- """
55
- Check if the URI matches this resource pattern
56
-
57
- Args:
58
- uri: The URI to check
59
-
60
- Returns:
61
- True if the URI matches the code file pattern
62
- """
63
- if not isinstance(uri, str):
64
- return False
65
-
66
- return bool(self._uri_pattern.match(uri))
67
-
68
- def _extract_file_path(self, uri: str) -> str:
69
- """
70
- Extract file path from URI
71
-
72
- Args:
73
- uri: The URI to extract path from
74
-
75
- Returns:
76
- The extracted file path
77
-
78
- Raises:
79
- ValueError: If URI format is invalid
80
- """
81
- match = self._uri_pattern.match(uri)
82
- if not match:
83
- raise ValueError(f"Invalid URI format: {uri}")
84
-
85
- return match.group(1)
86
-
87
- async def _read_file_content(self, file_path: str) -> str:
88
- """
89
- Read file content with proper encoding detection
90
-
91
- Args:
92
- file_path: Path to the file to read
93
-
94
- Returns:
95
- File content as string
96
-
97
- Raises:
98
- FileNotFoundError: If file doesn't exist
99
- PermissionError: If file cannot be read due to permissions
100
- OSError: If file cannot be read due to other OS errors
101
- """
102
- try:
103
- # Use existing encoding-safe file reader
104
- # Check if file exists first
105
- if not Path(file_path).exists():
106
- raise FileNotFoundError(f"File not found: {file_path}")
107
-
108
- content, encoding = read_file_safe(file_path)
109
- return content
110
-
111
- except FileNotFoundError:
112
- logger.error(f"File not found: {file_path}")
113
- raise
114
- except PermissionError:
115
- logger.error(f"Permission denied reading file: {file_path}")
116
- raise
117
- except OSError as e:
118
- logger.error(f"OS error reading file {file_path}: {e}")
119
- raise
120
- except Exception as e:
121
- logger.error(f"Unexpected error reading file {file_path}: {e}")
122
- raise OSError(f"Failed to read file: {e}")
123
-
124
- def _validate_file_path(self, file_path: str) -> None:
125
- """
126
- Validate file path for security and correctness
127
-
128
- Args:
129
- file_path: The file path to validate
130
-
131
- Raises:
132
- ValueError: If file path is invalid or potentially dangerous
133
- """
134
- if not file_path:
135
- raise ValueError("File path cannot be empty")
136
-
137
- # Check for null bytes
138
- if "\x00" in file_path:
139
- raise ValueError("File path contains null bytes")
140
-
141
- # Check for potentially dangerous path traversal
142
- normalized_path = Path(file_path).resolve()
143
- if ".." in file_path:
144
- logger.warning(f"Potentially dangerous path traversal in: {file_path}")
145
-
146
- # Additional security checks could be added here
147
- # For example, restricting to certain directories
148
-
149
- async def read_resource(self, uri: str) -> str:
150
- """
151
- Read resource content from URI
152
-
153
- Args:
154
- uri: The resource URI to read
155
-
156
- Returns:
157
- Resource content as string
158
-
159
- Raises:
160
- ValueError: If URI format is invalid
161
- FileNotFoundError: If file doesn't exist
162
- PermissionError: If file cannot be read due to permissions
163
- OSError: If file cannot be read due to other errors
164
- """
165
- logger.debug(f"Reading resource: {uri}")
166
-
167
- # Validate URI format
168
- if not self.matches_uri(uri):
169
- raise ValueError(f"URI does not match code file pattern: {uri}")
170
-
171
- # Extract file path
172
- file_path = self._extract_file_path(uri)
173
-
174
- # Validate file path
175
- self._validate_file_path(file_path)
176
-
177
- # Read file content
178
- try:
179
- content = await self._read_file_content(file_path)
180
- logger.debug(
181
- f"Successfully read {len(content)} characters from {file_path}"
182
- )
183
- return content
184
-
185
- except Exception as e:
186
- logger.error(f"Failed to read resource {uri}: {e}")
187
- raise
188
-
189
- def get_supported_schemes(self) -> list[str]:
190
- """
191
- Get list of supported URI schemes
192
-
193
- Returns:
194
- List of supported schemes
195
- """
196
- return ["code"]
197
-
198
- def get_supported_resource_types(self) -> list[str]:
199
- """
200
- Get list of supported resource types
201
-
202
- Returns:
203
- List of supported resource types
204
- """
205
- return ["file"]
206
-
207
- def __str__(self) -> str:
208
- """String representation of the resource"""
209
- return f"CodeFileResource(pattern=code://file/{{file_path}})"
210
-
211
- def __repr__(self) -> str:
212
- """Detailed string representation of the resource"""
213
- return f"CodeFileResource(uri_pattern={self._uri_pattern.pattern})"
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
+ if not isinstance(uri, str):
63
+ return False
64
+
65
+ return bool(self._uri_pattern.match(uri))
66
+
67
+ def _extract_file_path(self, uri: str) -> str:
68
+ """
69
+ Extract file path from URI
70
+
71
+ Args:
72
+ uri: The URI to extract path from
73
+
74
+ Returns:
75
+ The extracted file path
76
+
77
+ Raises:
78
+ ValueError: If URI format is invalid
79
+ """
80
+ match = self._uri_pattern.match(uri)
81
+ if not match:
82
+ raise ValueError(f"Invalid URI format: {uri}")
83
+
84
+ return match.group(1)
85
+
86
+ async def _read_file_content(self, file_path: str) -> str:
87
+ """
88
+ Read file content with proper encoding detection
89
+
90
+ Args:
91
+ file_path: Path to the file to read
92
+
93
+ Returns:
94
+ File content as string
95
+
96
+ Raises:
97
+ FileNotFoundError: If file doesn't exist
98
+ PermissionError: If file cannot be read due to permissions
99
+ OSError: If file cannot be read due to other OS errors
100
+ """
101
+ try:
102
+ # Use existing encoding-safe file reader
103
+ # Check if file exists first
104
+ if not Path(file_path).exists():
105
+ raise FileNotFoundError(f"File not found: {file_path}")
106
+
107
+ content, encoding = read_file_safe(file_path)
108
+ return content
109
+
110
+ except FileNotFoundError:
111
+ logger.error(f"File not found: {file_path}")
112
+ raise
113
+ except PermissionError:
114
+ logger.error(f"Permission denied reading file: {file_path}")
115
+ raise
116
+ except OSError as e:
117
+ logger.error(f"OS error reading file {file_path}: {e}")
118
+ raise
119
+ except Exception as e:
120
+ logger.error(f"Unexpected error reading file {file_path}: {e}")
121
+ raise OSError(f"Failed to read file: {e}") from e
122
+
123
+ def _validate_file_path(self, file_path: str) -> None:
124
+ """
125
+ Validate file path for security and correctness
126
+
127
+ Args:
128
+ file_path: The file path to validate
129
+
130
+ Raises:
131
+ ValueError: If file path is invalid or potentially dangerous
132
+ """
133
+ if not file_path:
134
+ raise ValueError("File path cannot be empty")
135
+
136
+ # Check for null bytes
137
+ if "\x00" in file_path:
138
+ raise ValueError("File path contains null bytes")
139
+
140
+ # Check for potentially dangerous path traversal
141
+ # normalized_path = Path(file_path).resolve() # Not used currently
142
+ if ".." in file_path:
143
+ logger.warning(f"Potentially dangerous path traversal in: {file_path}")
144
+
145
+ # Additional security checks could be added here
146
+ # For example, restricting to certain directories
147
+
148
+ async def read_resource(self, uri: str) -> str:
149
+ """
150
+ Read resource content from URI
151
+
152
+ Args:
153
+ uri: The resource URI to read
154
+
155
+ Returns:
156
+ Resource content as string
157
+
158
+ Raises:
159
+ ValueError: If URI format is invalid
160
+ FileNotFoundError: If file doesn't exist
161
+ PermissionError: If file cannot be read due to permissions
162
+ OSError: If file cannot be read due to other errors
163
+ """
164
+ logger.debug(f"Reading resource: {uri}")
165
+
166
+ # Validate URI format
167
+ if not self.matches_uri(uri):
168
+ raise ValueError(f"URI does not match code file pattern: {uri}")
169
+
170
+ # Extract file path
171
+ file_path = self._extract_file_path(uri)
172
+
173
+ # Validate file path
174
+ self._validate_file_path(file_path)
175
+
176
+ # Read file content
177
+ try:
178
+ content = await self._read_file_content(file_path)
179
+ logger.debug(
180
+ f"Successfully read {len(content)} characters from {file_path}"
181
+ )
182
+ return content
183
+
184
+ except Exception as e:
185
+ logger.error(f"Failed to read resource {uri}: {e}")
186
+ raise
187
+
188
+ def get_supported_schemes(self) -> list[str]:
189
+ """
190
+ Get list of supported URI schemes
191
+
192
+ Returns:
193
+ List of supported schemes
194
+ """
195
+ return ["code"]
196
+
197
+ def get_supported_resource_types(self) -> list[str]:
198
+ """
199
+ Get list of supported resource types
200
+
201
+ Returns:
202
+ List of supported resource types
203
+ """
204
+ return ["file"]
205
+
206
+ def __str__(self) -> str:
207
+ """String representation of the resource"""
208
+ return "CodeFileResource(pattern=code://file/{file_path})"
209
+
210
+ def __repr__(self) -> str:
211
+ """Detailed string representation of the resource"""
212
+ return f"CodeFileResource(uri_pattern={self._uri_pattern.pattern})"