tree-sitter-analyzer 0.9.2__py3-none-any.whl → 0.9.4__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 (37) hide show
  1. tree_sitter_analyzer/__init__.py +1 -1
  2. tree_sitter_analyzer/cli/commands/base_command.py +2 -3
  3. tree_sitter_analyzer/cli/commands/default_command.py +18 -18
  4. tree_sitter_analyzer/cli/commands/partial_read_command.py +139 -141
  5. tree_sitter_analyzer/cli/commands/query_command.py +92 -88
  6. tree_sitter_analyzer/cli/commands/table_command.py +235 -235
  7. tree_sitter_analyzer/cli/info_commands.py +121 -121
  8. tree_sitter_analyzer/cli_main.py +307 -303
  9. tree_sitter_analyzer/core/analysis_engine.py +584 -576
  10. tree_sitter_analyzer/core/cache_service.py +6 -5
  11. tree_sitter_analyzer/core/query.py +502 -502
  12. tree_sitter_analyzer/encoding_utils.py +6 -2
  13. tree_sitter_analyzer/exceptions.py +400 -406
  14. tree_sitter_analyzer/formatters/java_formatter.py +291 -291
  15. tree_sitter_analyzer/formatters/python_formatter.py +259 -259
  16. tree_sitter_analyzer/interfaces/cli.py +1 -1
  17. tree_sitter_analyzer/interfaces/cli_adapter.py +3 -3
  18. tree_sitter_analyzer/interfaces/mcp_server.py +426 -425
  19. tree_sitter_analyzer/language_detector.py +398 -398
  20. tree_sitter_analyzer/language_loader.py +224 -224
  21. tree_sitter_analyzer/languages/java_plugin.py +1202 -1202
  22. tree_sitter_analyzer/mcp/resources/project_stats_resource.py +559 -555
  23. tree_sitter_analyzer/mcp/server.py +30 -9
  24. tree_sitter_analyzer/mcp/tools/read_partial_tool.py +21 -4
  25. tree_sitter_analyzer/mcp/tools/table_format_tool.py +22 -4
  26. tree_sitter_analyzer/mcp/utils/error_handler.py +569 -567
  27. tree_sitter_analyzer/models.py +470 -470
  28. tree_sitter_analyzer/project_detector.py +330 -317
  29. tree_sitter_analyzer/security/__init__.py +22 -22
  30. tree_sitter_analyzer/security/boundary_manager.py +243 -237
  31. tree_sitter_analyzer/security/regex_checker.py +297 -292
  32. tree_sitter_analyzer/table_formatter.py +703 -652
  33. tree_sitter_analyzer/utils.py +53 -22
  34. {tree_sitter_analyzer-0.9.2.dist-info → tree_sitter_analyzer-0.9.4.dist-info}/METADATA +13 -13
  35. {tree_sitter_analyzer-0.9.2.dist-info → tree_sitter_analyzer-0.9.4.dist-info}/RECORD +37 -37
  36. {tree_sitter_analyzer-0.9.2.dist-info → tree_sitter_analyzer-0.9.4.dist-info}/WHEEL +0 -0
  37. {tree_sitter_analyzer-0.9.2.dist-info → tree_sitter_analyzer-0.9.4.dist-info}/entry_points.txt +0 -0
@@ -11,7 +11,7 @@ Architecture:
11
11
  - Data Models: Generic and language-specific code element representations
12
12
  """
13
13
 
14
- __version__ = "0.9.2"
14
+ __version__ = "0.9.3"
15
15
  __author__ = "aisheng.yu"
16
16
  __email__ = "aimasteracc@gmail.com"
17
17
 
@@ -85,9 +85,8 @@ class BaseCommand(ABC):
85
85
  if (not hasattr(self.args, "table") or not self.args.table) and (
86
86
  not hasattr(self.args, "quiet") or not self.args.quiet
87
87
  ):
88
- output_info(
89
- f"INFO: Language auto-detected from extension: {target_language}"
90
- )
88
+ # Language auto-detected - only show in verbose mode
89
+ pass
91
90
 
92
91
  # Language support validation
93
92
  if not is_language_supported(target_language):
@@ -1,18 +1,18 @@
1
- #!/usr/bin/env python3
2
- """
3
- Default Command
4
-
5
- Handles default analysis when no specific command is specified.
6
- """
7
-
8
- from ...output_manager import output_error
9
- from .base_command import BaseCommand
10
-
11
-
12
- class DefaultCommand(BaseCommand):
13
- """Default command that shows error when no specific command is given."""
14
-
15
- async def execute_async(self, language: str) -> int:
16
- """Execute default command - show error for missing options."""
17
- output_error("Please specify a query or --advanced option")
18
- return 1
1
+ #!/usr/bin/env python3
2
+ """
3
+ Default Command
4
+
5
+ Handles default analysis when no specific command is specified.
6
+ """
7
+
8
+ from ...output_manager import output_error
9
+ from .base_command import BaseCommand
10
+
11
+
12
+ class DefaultCommand(BaseCommand):
13
+ """Default command that shows error when no specific command is given."""
14
+
15
+ async def execute_async(self, language: str) -> int:
16
+ """Execute default command - show error for missing options."""
17
+ output_error("Please specify a query or --advanced option")
18
+ return 1
@@ -1,141 +1,139 @@
1
- #!/usr/bin/env python3
2
- """
3
- Partial Read Command
4
-
5
- Handles partial file reading functionality, extracting specified line ranges.
6
- """
7
-
8
- from typing import TYPE_CHECKING, Any
9
-
10
- from ...file_handler import read_file_partial
11
- from ...output_manager import output_data, output_json, output_section
12
- from .base_command import BaseCommand
13
-
14
- if TYPE_CHECKING:
15
- pass
16
-
17
-
18
- class PartialReadCommand(BaseCommand):
19
- """Command for reading partial file content by line range."""
20
-
21
- def __init__(self, args: Any) -> None:
22
- """Initialize with arguments but skip base class analysis engine setup."""
23
- self.args = args
24
- # Don't call super().__init__() to avoid unnecessary analysis engine setup
25
-
26
- def validate_file(self) -> bool:
27
- """Validate input file exists and is accessible."""
28
- if not hasattr(self.args, "file_path") or not self.args.file_path:
29
- from ...output_manager import output_error
30
-
31
- output_error("File path not specified.")
32
- return False
33
-
34
- import os
35
-
36
- if not os.path.exists(self.args.file_path):
37
- from ...output_manager import output_error
38
-
39
- output_error(f"File not found: {self.args.file_path}")
40
- return False
41
-
42
- return True
43
-
44
- def execute(self) -> int:
45
- """
46
- Execute partial read command.
47
-
48
- Returns:
49
- int: Exit code (0 for success, 1 for failure)
50
- """
51
- # Validate inputs
52
- if not self.validate_file():
53
- return 1
54
-
55
- # Validate partial read arguments
56
- if not self.args.start_line:
57
- from ...output_manager import output_error
58
-
59
- output_error("--start-line is required")
60
- return 1
61
-
62
- if self.args.start_line < 1:
63
- from ...output_manager import output_error
64
-
65
- output_error("--start-line must be 1 or greater")
66
- return 1
67
-
68
- if self.args.end_line and self.args.end_line < self.args.start_line:
69
- from ...output_manager import output_error
70
-
71
- output_error(
72
- "--end-line must be greater than or equal to --start-line"
73
- )
74
- return 1
75
-
76
- # Read partial content
77
- try:
78
- partial_content = read_file_partial(
79
- self.args.file_path,
80
- start_line=self.args.start_line,
81
- end_line=getattr(self.args, "end_line", None),
82
- start_column=getattr(self.args, "start_column", None),
83
- end_column=getattr(self.args, "end_column", None),
84
- )
85
-
86
- if partial_content is None:
87
- from ...output_manager import output_error
88
-
89
- output_error("Failed to read file partially")
90
- return 1
91
-
92
- # Output the result
93
- self._output_partial_content(partial_content)
94
- return 0
95
-
96
- except Exception as e:
97
- from ...output_manager import output_error
98
-
99
- output_error(f"Failed to read file partially: {e}")
100
- return 1
101
-
102
- def _output_partial_content(self, content: str) -> None:
103
- """Output the partial content in the specified format."""
104
- # Build result data
105
- result_data = {
106
- "file_path": self.args.file_path,
107
- "range": {
108
- "start_line": self.args.start_line,
109
- "end_line": getattr(self.args, "end_line", None),
110
- "start_column": getattr(self.args, "start_column", None),
111
- "end_column": getattr(self.args, "end_column", None),
112
- },
113
- "content": content,
114
- "content_length": len(content),
115
- }
116
-
117
- # Build range info for header
118
- range_info = f"Line {self.args.start_line}"
119
- if hasattr(self.args, "end_line") and self.args.end_line:
120
- range_info += f"-{self.args.end_line}"
121
-
122
- # Output format selection
123
- output_format = getattr(self.args, "output_format", "text")
124
-
125
- if output_format == "json":
126
- # Pure JSON output
127
- output_json(result_data)
128
- else:
129
- # Human-readable format with header
130
- output_section("Partial Read Result")
131
- output_data(f"File: {self.args.file_path}")
132
- output_data(f"Range: {range_info}")
133
- output_data(f"Characters read: {len(content)}")
134
- output_data("") # Empty line for separation
135
-
136
- # Output the actual content
137
- print(content, end="") # Use print to avoid extra formatting
138
-
139
- async def execute_async(self, language: str) -> int:
140
- """Not used for partial read command."""
141
- return self.execute()
1
+ #!/usr/bin/env python3
2
+ """
3
+ Partial Read Command
4
+
5
+ Handles partial file reading functionality, extracting specified line ranges.
6
+ """
7
+
8
+ from typing import TYPE_CHECKING, Any
9
+
10
+ from ...file_handler import read_file_partial
11
+ from ...output_manager import output_data, output_json, output_section
12
+ from .base_command import BaseCommand
13
+
14
+ if TYPE_CHECKING:
15
+ pass
16
+
17
+
18
+ class PartialReadCommand(BaseCommand):
19
+ """Command for reading partial file content by line range."""
20
+
21
+ def __init__(self, args: Any) -> None:
22
+ """Initialize with arguments but skip base class analysis engine setup."""
23
+ self.args = args
24
+ # Don't call super().__init__() to avoid unnecessary analysis engine setup
25
+
26
+ def validate_file(self) -> bool:
27
+ """Validate input file exists and is accessible."""
28
+ if not hasattr(self.args, "file_path") or not self.args.file_path:
29
+ from ...output_manager import output_error
30
+
31
+ output_error("File path not specified.")
32
+ return False
33
+
34
+ import os
35
+
36
+ if not os.path.exists(self.args.file_path):
37
+ from ...output_manager import output_error
38
+
39
+ output_error(f"File not found: {self.args.file_path}")
40
+ return False
41
+
42
+ return True
43
+
44
+ def execute(self) -> int:
45
+ """
46
+ Execute partial read command.
47
+
48
+ Returns:
49
+ int: Exit code (0 for success, 1 for failure)
50
+ """
51
+ # Validate inputs
52
+ if not self.validate_file():
53
+ return 1
54
+
55
+ # Validate partial read arguments
56
+ if not self.args.start_line:
57
+ from ...output_manager import output_error
58
+
59
+ output_error("--start-line is required")
60
+ return 1
61
+
62
+ if self.args.start_line < 1:
63
+ from ...output_manager import output_error
64
+
65
+ output_error("--start-line must be 1 or greater")
66
+ return 1
67
+
68
+ if self.args.end_line and self.args.end_line < self.args.start_line:
69
+ from ...output_manager import output_error
70
+
71
+ output_error("--end-line must be greater than or equal to --start-line")
72
+ return 1
73
+
74
+ # Read partial content
75
+ try:
76
+ partial_content = read_file_partial(
77
+ self.args.file_path,
78
+ start_line=self.args.start_line,
79
+ end_line=getattr(self.args, "end_line", None),
80
+ start_column=getattr(self.args, "start_column", None),
81
+ end_column=getattr(self.args, "end_column", None),
82
+ )
83
+
84
+ if partial_content is None:
85
+ from ...output_manager import output_error
86
+
87
+ output_error("Failed to read file partially")
88
+ return 1
89
+
90
+ # Output the result
91
+ self._output_partial_content(partial_content)
92
+ return 0
93
+
94
+ except Exception as e:
95
+ from ...output_manager import output_error
96
+
97
+ output_error(f"Failed to read file partially: {e}")
98
+ return 1
99
+
100
+ def _output_partial_content(self, content: str) -> None:
101
+ """Output the partial content in the specified format."""
102
+ # Build result data
103
+ result_data = {
104
+ "file_path": self.args.file_path,
105
+ "range": {
106
+ "start_line": self.args.start_line,
107
+ "end_line": getattr(self.args, "end_line", None),
108
+ "start_column": getattr(self.args, "start_column", None),
109
+ "end_column": getattr(self.args, "end_column", None),
110
+ },
111
+ "content": content,
112
+ "content_length": len(content),
113
+ }
114
+
115
+ # Build range info for header
116
+ range_info = f"Line {self.args.start_line}"
117
+ if hasattr(self.args, "end_line") and self.args.end_line:
118
+ range_info += f"-{self.args.end_line}"
119
+
120
+ # Output format selection
121
+ output_format = getattr(self.args, "output_format", "text")
122
+
123
+ if output_format == "json":
124
+ # Pure JSON output
125
+ output_json(result_data)
126
+ else:
127
+ # Human-readable format with header
128
+ output_section("Partial Read Result")
129
+ output_data(f"File: {self.args.file_path}")
130
+ output_data(f"Range: {range_info}")
131
+ output_data(f"Characters read: {len(content)}")
132
+ output_data("") # Empty line for separation
133
+
134
+ # Output the actual content
135
+ print(content, end="") # Use print to avoid extra formatting
136
+
137
+ async def execute_async(self, language: str) -> int:
138
+ """Not used for partial read command."""
139
+ return self.execute()
@@ -1,88 +1,92 @@
1
- #!/usr/bin/env python3
2
- """
3
- Query Command
4
-
5
- Handles query execution functionality.
6
- """
7
-
8
- from ...output_manager import output_data, output_error, output_info, output_json
9
- from ...query_loader import query_loader
10
- from .base_command import BaseCommand
11
-
12
-
13
- class QueryCommand(BaseCommand):
14
- """Command for executing queries."""
15
-
16
- async def execute_async(self, language: str) -> int:
17
- # Get the query to execute
18
- query_to_execute = None
19
-
20
- if hasattr(self.args, "query_key") and self.args.query_key:
21
- # Sanitize query key input
22
- sanitized_query_key = self.security_validator.sanitize_input(self.args.query_key, max_length=100)
23
- try:
24
- query_to_execute = query_loader.get_query(language, sanitized_query_key)
25
- if query_to_execute is None:
26
- output_error(
27
- f"Query '{sanitized_query_key}' not found for language '{language}'"
28
- )
29
- return 1
30
- except ValueError as e:
31
- output_error(f"{e}")
32
- return 1
33
- elif hasattr(self.args, "query_string") and self.args.query_string:
34
- # Security check for query string (potential regex patterns)
35
- is_safe, error_msg = self.security_validator.regex_checker.validate_pattern(self.args.query_string)
36
- if not is_safe:
37
- output_error(f"Unsafe query pattern: {error_msg}")
38
- return 1
39
- query_to_execute = self.args.query_string
40
-
41
- if not query_to_execute:
42
- output_error("No query specified.")
43
- return 1
44
-
45
- # Perform analysis
46
- analysis_result = await self.analyze_file(language)
47
- if not analysis_result:
48
- return 1
49
-
50
- # Process query results
51
- results = []
52
- if hasattr(analysis_result, "query_results") and analysis_result.query_results:
53
- results = analysis_result.query_results.get("captures", [])
54
- else:
55
- # Create basic results from elements
56
- if hasattr(analysis_result, "elements") and analysis_result.elements:
57
- for element in analysis_result.elements:
58
- results.append(
59
- {
60
- "capture_name": getattr(
61
- element, "__class__", type(element)
62
- ).__name__.lower(),
63
- "node_type": getattr(
64
- element, "__class__", type(element)
65
- ).__name__,
66
- "start_line": getattr(element, "start_line", 0),
67
- "end_line": getattr(element, "end_line", 0),
68
- "content": getattr(element, "name", str(element)),
69
- }
70
- )
71
-
72
- # Output results
73
- if results:
74
- if self.args.output_format == "json":
75
- output_json(results)
76
- else:
77
- for i, query_result in enumerate(results, 1):
78
- output_data(
79
- f"\n{i}. {query_result['capture_name']} ({query_result['node_type']})"
80
- )
81
- output_data(
82
- f" Position: Line {query_result['start_line']}-{query_result['end_line']}"
83
- )
84
- output_data(f" Content:\n{query_result['content']}")
85
- else:
86
- output_info("\nINFO: No results found matching the query.")
87
-
88
- return 0
1
+ #!/usr/bin/env python3
2
+ """
3
+ Query Command
4
+
5
+ Handles query execution functionality.
6
+ """
7
+
8
+ from ...output_manager import output_data, output_error, output_info, output_json
9
+ from ...query_loader import query_loader
10
+ from .base_command import BaseCommand
11
+
12
+
13
+ class QueryCommand(BaseCommand):
14
+ """Command for executing queries."""
15
+
16
+ async def execute_async(self, language: str) -> int:
17
+ # Get the query to execute
18
+ query_to_execute = None
19
+
20
+ if hasattr(self.args, "query_key") and self.args.query_key:
21
+ # Sanitize query key input
22
+ sanitized_query_key = self.security_validator.sanitize_input(
23
+ self.args.query_key, max_length=100
24
+ )
25
+ try:
26
+ query_to_execute = query_loader.get_query(language, sanitized_query_key)
27
+ if query_to_execute is None:
28
+ output_error(
29
+ f"Query '{sanitized_query_key}' not found for language '{language}'"
30
+ )
31
+ return 1
32
+ except ValueError as e:
33
+ output_error(f"{e}")
34
+ return 1
35
+ elif hasattr(self.args, "query_string") and self.args.query_string:
36
+ # Security check for query string (potential regex patterns)
37
+ is_safe, error_msg = self.security_validator.regex_checker.validate_pattern(
38
+ self.args.query_string
39
+ )
40
+ if not is_safe:
41
+ output_error(f"Unsafe query pattern: {error_msg}")
42
+ return 1
43
+ query_to_execute = self.args.query_string
44
+
45
+ if not query_to_execute:
46
+ output_error("No query specified.")
47
+ return 1
48
+
49
+ # Perform analysis
50
+ analysis_result = await self.analyze_file(language)
51
+ if not analysis_result:
52
+ return 1
53
+
54
+ # Process query results
55
+ results = []
56
+ if hasattr(analysis_result, "query_results") and analysis_result.query_results:
57
+ results = analysis_result.query_results.get("captures", [])
58
+ else:
59
+ # Create basic results from elements
60
+ if hasattr(analysis_result, "elements") and analysis_result.elements:
61
+ for element in analysis_result.elements:
62
+ results.append(
63
+ {
64
+ "capture_name": getattr(
65
+ element, "__class__", type(element)
66
+ ).__name__.lower(),
67
+ "node_type": getattr(
68
+ element, "__class__", type(element)
69
+ ).__name__,
70
+ "start_line": getattr(element, "start_line", 0),
71
+ "end_line": getattr(element, "end_line", 0),
72
+ "content": getattr(element, "name", str(element)),
73
+ }
74
+ )
75
+
76
+ # Output results
77
+ if results:
78
+ if self.args.output_format == "json":
79
+ output_json(results)
80
+ else:
81
+ for i, query_result in enumerate(results, 1):
82
+ output_data(
83
+ f"\n{i}. {query_result['capture_name']} ({query_result['node_type']})"
84
+ )
85
+ output_data(
86
+ f" Position: Line {query_result['start_line']}-{query_result['end_line']}"
87
+ )
88
+ output_data(f" Content:\n{query_result['content']}")
89
+ else:
90
+ output_info("\nINFO: No results found matching the query.")
91
+
92
+ return 0