tree-sitter-analyzer 0.6.2__py3-none-any.whl → 0.8.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.
- tree_sitter_analyzer/__init__.py +132 -132
- tree_sitter_analyzer/__main__.py +11 -11
- tree_sitter_analyzer/api.py +533 -533
- tree_sitter_analyzer/cli/__init__.py +39 -39
- tree_sitter_analyzer/cli/__main__.py +12 -12
- tree_sitter_analyzer/cli/commands/__init__.py +26 -26
- tree_sitter_analyzer/cli/commands/advanced_command.py +88 -88
- tree_sitter_analyzer/cli/commands/base_command.py +160 -160
- tree_sitter_analyzer/cli/commands/default_command.py +18 -18
- tree_sitter_analyzer/cli/commands/partial_read_command.py +141 -141
- tree_sitter_analyzer/cli/commands/query_command.py +81 -81
- tree_sitter_analyzer/cli/commands/structure_command.py +138 -138
- tree_sitter_analyzer/cli/commands/summary_command.py +101 -101
- tree_sitter_analyzer/cli/commands/table_command.py +235 -235
- tree_sitter_analyzer/cli/info_commands.py +121 -121
- tree_sitter_analyzer/cli_main.py +297 -297
- tree_sitter_analyzer/core/__init__.py +15 -15
- tree_sitter_analyzer/core/analysis_engine.py +555 -555
- tree_sitter_analyzer/core/cache_service.py +320 -320
- tree_sitter_analyzer/core/engine.py +566 -566
- tree_sitter_analyzer/core/parser.py +293 -293
- tree_sitter_analyzer/encoding_utils.py +459 -459
- tree_sitter_analyzer/exceptions.py +406 -337
- tree_sitter_analyzer/file_handler.py +210 -210
- tree_sitter_analyzer/formatters/__init__.py +1 -1
- tree_sitter_analyzer/formatters/base_formatter.py +167 -167
- tree_sitter_analyzer/formatters/formatter_factory.py +78 -78
- tree_sitter_analyzer/interfaces/__init__.py +9 -9
- tree_sitter_analyzer/interfaces/cli.py +528 -528
- tree_sitter_analyzer/interfaces/cli_adapter.py +343 -343
- tree_sitter_analyzer/interfaces/mcp_adapter.py +206 -206
- tree_sitter_analyzer/interfaces/mcp_server.py +425 -405
- tree_sitter_analyzer/languages/__init__.py +10 -10
- tree_sitter_analyzer/languages/javascript_plugin.py +446 -446
- tree_sitter_analyzer/languages/python_plugin.py +755 -755
- tree_sitter_analyzer/mcp/__init__.py +31 -31
- tree_sitter_analyzer/mcp/resources/__init__.py +44 -44
- tree_sitter_analyzer/mcp/resources/code_file_resource.py +209 -209
- tree_sitter_analyzer/mcp/server.py +346 -333
- tree_sitter_analyzer/mcp/tools/__init__.py +30 -30
- tree_sitter_analyzer/mcp/tools/analyze_scale_tool.py +654 -654
- tree_sitter_analyzer/mcp/tools/analyze_scale_tool_cli_compatible.py +247 -247
- tree_sitter_analyzer/mcp/tools/base_tool.py +54 -54
- tree_sitter_analyzer/mcp/tools/read_partial_tool.py +300 -300
- tree_sitter_analyzer/mcp/tools/table_format_tool.py +362 -362
- tree_sitter_analyzer/mcp/tools/universal_analyze_tool.py +543 -543
- tree_sitter_analyzer/mcp/utils/__init__.py +107 -107
- tree_sitter_analyzer/mcp/utils/error_handler.py +549 -549
- tree_sitter_analyzer/output_manager.py +253 -253
- tree_sitter_analyzer/plugins/__init__.py +280 -280
- tree_sitter_analyzer/plugins/base.py +529 -529
- tree_sitter_analyzer/plugins/manager.py +379 -379
- tree_sitter_analyzer/queries/__init__.py +26 -26
- tree_sitter_analyzer/queries/java.py +391 -391
- tree_sitter_analyzer/queries/javascript.py +148 -148
- tree_sitter_analyzer/queries/python.py +285 -285
- tree_sitter_analyzer/queries/typescript.py +229 -229
- tree_sitter_analyzer/query_loader.py +257 -257
- tree_sitter_analyzer/security/__init__.py +22 -0
- tree_sitter_analyzer/security/boundary_manager.py +237 -0
- tree_sitter_analyzer/security/regex_checker.py +292 -0
- tree_sitter_analyzer/security/validator.py +224 -0
- tree_sitter_analyzer/table_formatter.py +652 -473
- tree_sitter_analyzer/utils.py +277 -277
- {tree_sitter_analyzer-0.6.2.dist-info → tree_sitter_analyzer-0.8.0.dist-info}/METADATA +4 -1
- tree_sitter_analyzer-0.8.0.dist-info/RECORD +76 -0
- tree_sitter_analyzer-0.6.2.dist-info/RECORD +0 -72
- {tree_sitter_analyzer-0.6.2.dist-info → tree_sitter_analyzer-0.8.0.dist-info}/WHEEL +0 -0
- {tree_sitter_analyzer-0.6.2.dist-info → tree_sitter_analyzer-0.8.0.dist-info}/entry_points.txt +0 -0
tree_sitter_analyzer/cli_main.py
CHANGED
|
@@ -1,297 +1,297 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""CLI Main Module - Entry point for command-line interface."""
|
|
3
|
-
|
|
4
|
-
import argparse
|
|
5
|
-
import logging
|
|
6
|
-
import sys
|
|
7
|
-
from typing import Any
|
|
8
|
-
|
|
9
|
-
# Import command classes
|
|
10
|
-
from .cli.commands import (
|
|
11
|
-
AdvancedCommand,
|
|
12
|
-
DefaultCommand,
|
|
13
|
-
PartialReadCommand,
|
|
14
|
-
QueryCommand,
|
|
15
|
-
StructureCommand,
|
|
16
|
-
SummaryCommand,
|
|
17
|
-
TableCommand,
|
|
18
|
-
)
|
|
19
|
-
from .cli.info_commands import (
|
|
20
|
-
DescribeQueryCommand,
|
|
21
|
-
ListQueriesCommand,
|
|
22
|
-
ShowExtensionsCommand,
|
|
23
|
-
ShowLanguagesCommand,
|
|
24
|
-
)
|
|
25
|
-
from .output_manager import output_error, output_info, output_list
|
|
26
|
-
from .query_loader import query_loader
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
class CLICommandFactory:
|
|
30
|
-
"""Factory for creating CLI commands based on arguments."""
|
|
31
|
-
|
|
32
|
-
@staticmethod
|
|
33
|
-
def create_command(args: argparse.Namespace) -> Any:
|
|
34
|
-
"""Create appropriate command based on arguments."""
|
|
35
|
-
|
|
36
|
-
# Information commands (no file analysis required)
|
|
37
|
-
if args.list_queries:
|
|
38
|
-
return ListQueriesCommand(args)
|
|
39
|
-
|
|
40
|
-
if args.describe_query:
|
|
41
|
-
return DescribeQueryCommand(args)
|
|
42
|
-
|
|
43
|
-
if args.show_supported_languages:
|
|
44
|
-
return ShowLanguagesCommand(args)
|
|
45
|
-
|
|
46
|
-
if args.show_supported_extensions:
|
|
47
|
-
return ShowExtensionsCommand(args)
|
|
48
|
-
|
|
49
|
-
# File analysis commands (require file path)
|
|
50
|
-
if not args.file_path:
|
|
51
|
-
return None
|
|
52
|
-
|
|
53
|
-
# Partial read command - highest priority for file operations
|
|
54
|
-
if hasattr(args, "partial_read") and args.partial_read:
|
|
55
|
-
return PartialReadCommand(args)
|
|
56
|
-
|
|
57
|
-
if hasattr(args, "table") and args.table:
|
|
58
|
-
return TableCommand(args)
|
|
59
|
-
|
|
60
|
-
if hasattr(args, "structure") and args.structure:
|
|
61
|
-
return StructureCommand(args)
|
|
62
|
-
|
|
63
|
-
if hasattr(args, "summary") and args.summary is not None:
|
|
64
|
-
return SummaryCommand(args)
|
|
65
|
-
|
|
66
|
-
if hasattr(args, "advanced") and args.advanced:
|
|
67
|
-
return AdvancedCommand(args)
|
|
68
|
-
|
|
69
|
-
if hasattr(args, "query_key") and args.query_key:
|
|
70
|
-
return QueryCommand(args)
|
|
71
|
-
|
|
72
|
-
if hasattr(args, "query_string") and args.query_string:
|
|
73
|
-
return QueryCommand(args)
|
|
74
|
-
|
|
75
|
-
# Default command - if file_path is provided but no specific command, use default analysis
|
|
76
|
-
return DefaultCommand(args)
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
def create_argument_parser() -> argparse.ArgumentParser:
|
|
80
|
-
"""Create and configure the argument parser."""
|
|
81
|
-
parser = argparse.ArgumentParser(
|
|
82
|
-
description="Analyze code using Tree-sitter and extract structured information.",
|
|
83
|
-
epilog="Example: tree-sitter-analyzer example.java --table=full",
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
# File path
|
|
87
|
-
parser.add_argument("file_path", nargs="?", help="Path to the file to analyze")
|
|
88
|
-
|
|
89
|
-
# Query options
|
|
90
|
-
query_group = parser.add_mutually_exclusive_group(required=False)
|
|
91
|
-
query_group.add_argument(
|
|
92
|
-
"--query-key", help="Available query key (e.g., class, method)"
|
|
93
|
-
)
|
|
94
|
-
query_group.add_argument(
|
|
95
|
-
"--query-string", help="Directly specify Tree-sitter query to execute"
|
|
96
|
-
)
|
|
97
|
-
|
|
98
|
-
# Information options
|
|
99
|
-
parser.add_argument(
|
|
100
|
-
"--list-queries",
|
|
101
|
-
action="store_true",
|
|
102
|
-
help="Display list of available query keys",
|
|
103
|
-
)
|
|
104
|
-
parser.add_argument(
|
|
105
|
-
"--describe-query", help="Display description of specified query key"
|
|
106
|
-
)
|
|
107
|
-
parser.add_argument(
|
|
108
|
-
"--show-supported-languages",
|
|
109
|
-
action="store_true",
|
|
110
|
-
help="Display list of supported languages",
|
|
111
|
-
)
|
|
112
|
-
parser.add_argument(
|
|
113
|
-
"--show-supported-extensions",
|
|
114
|
-
action="store_true",
|
|
115
|
-
help="Display list of supported file extensions",
|
|
116
|
-
)
|
|
117
|
-
parser.add_argument(
|
|
118
|
-
"--show-common-queries",
|
|
119
|
-
action="store_true",
|
|
120
|
-
help="Display list of common queries across multiple languages",
|
|
121
|
-
)
|
|
122
|
-
parser.add_argument(
|
|
123
|
-
"--show-query-languages",
|
|
124
|
-
action="store_true",
|
|
125
|
-
help="Display list of languages with query support",
|
|
126
|
-
)
|
|
127
|
-
|
|
128
|
-
# Output format options
|
|
129
|
-
parser.add_argument(
|
|
130
|
-
"--output-format",
|
|
131
|
-
choices=["json", "text"],
|
|
132
|
-
default="json",
|
|
133
|
-
help="Specify output format",
|
|
134
|
-
)
|
|
135
|
-
parser.add_argument(
|
|
136
|
-
"--table", choices=["full", "compact", "csv"], help="Output in table format"
|
|
137
|
-
)
|
|
138
|
-
parser.add_argument(
|
|
139
|
-
"--include-javadoc",
|
|
140
|
-
action="store_true",
|
|
141
|
-
help="Include JavaDoc/documentation comments in output",
|
|
142
|
-
)
|
|
143
|
-
|
|
144
|
-
# Analysis options
|
|
145
|
-
parser.add_argument(
|
|
146
|
-
"--advanced", action="store_true", help="Use advanced analysis features"
|
|
147
|
-
)
|
|
148
|
-
parser.add_argument(
|
|
149
|
-
"--summary",
|
|
150
|
-
nargs="?",
|
|
151
|
-
const="classes,methods",
|
|
152
|
-
help="Display summary of specified element types",
|
|
153
|
-
)
|
|
154
|
-
parser.add_argument(
|
|
155
|
-
"--structure",
|
|
156
|
-
action="store_true",
|
|
157
|
-
help="Output detailed structure information in JSON format",
|
|
158
|
-
)
|
|
159
|
-
parser.add_argument(
|
|
160
|
-
"--statistics", action="store_true", help="Display only statistical information"
|
|
161
|
-
)
|
|
162
|
-
|
|
163
|
-
# Language options
|
|
164
|
-
parser.add_argument(
|
|
165
|
-
"--language",
|
|
166
|
-
help="Explicitly specify language (auto-detected from extension if omitted)",
|
|
167
|
-
)
|
|
168
|
-
|
|
169
|
-
# Logging options
|
|
170
|
-
parser.add_argument(
|
|
171
|
-
"--quiet",
|
|
172
|
-
action="store_true",
|
|
173
|
-
help="Suppress INFO level logs (show errors only)",
|
|
174
|
-
)
|
|
175
|
-
|
|
176
|
-
# Partial reading options
|
|
177
|
-
parser.add_argument(
|
|
178
|
-
"--partial-read",
|
|
179
|
-
action="store_true",
|
|
180
|
-
help="Enable partial file reading mode",
|
|
181
|
-
)
|
|
182
|
-
parser.add_argument(
|
|
183
|
-
"--start-line", type=int, help="Starting line number for reading (1-based)"
|
|
184
|
-
)
|
|
185
|
-
parser.add_argument(
|
|
186
|
-
"--end-line", type=int, help="Ending line number for reading (1-based)"
|
|
187
|
-
)
|
|
188
|
-
parser.add_argument(
|
|
189
|
-
"--start-column", type=int, help="Starting column number for reading (0-based)"
|
|
190
|
-
)
|
|
191
|
-
parser.add_argument(
|
|
192
|
-
"--end-column", type=int, help="Ending column number for reading (0-based)"
|
|
193
|
-
)
|
|
194
|
-
|
|
195
|
-
return parser
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
def handle_special_commands(args: argparse.Namespace) -> int | None:
|
|
199
|
-
"""Handle special commands that don't fit the normal pattern."""
|
|
200
|
-
|
|
201
|
-
# Validate partial read options
|
|
202
|
-
if hasattr(args, "partial_read") and args.partial_read:
|
|
203
|
-
if args.start_line is None:
|
|
204
|
-
output_error("ERROR: --start-line is required")
|
|
205
|
-
return 1
|
|
206
|
-
|
|
207
|
-
if args.start_line < 1:
|
|
208
|
-
output_error("ERROR: --start-line must be 1 or greater")
|
|
209
|
-
return 1
|
|
210
|
-
|
|
211
|
-
if args.end_line and args.end_line < args.start_line:
|
|
212
|
-
output_error(
|
|
213
|
-
"ERROR: --end-line must be greater than or equal to --start-line"
|
|
214
|
-
)
|
|
215
|
-
return 1
|
|
216
|
-
|
|
217
|
-
if args.start_column is not None and args.start_column < 0:
|
|
218
|
-
output_error("ERROR: --start-column must be 0 or greater")
|
|
219
|
-
return 1
|
|
220
|
-
|
|
221
|
-
if args.end_column is not None and args.end_column < 0:
|
|
222
|
-
output_error("ERROR: --end-column must be 0 or greater")
|
|
223
|
-
return 1
|
|
224
|
-
|
|
225
|
-
# Query language commands
|
|
226
|
-
if args.show_query_languages:
|
|
227
|
-
output_list(["Languages with query support:"])
|
|
228
|
-
for lang in query_loader.list_supported_languages():
|
|
229
|
-
query_count = len(query_loader.list_queries_for_language(lang))
|
|
230
|
-
output_list([f" {lang:<15} ({query_count} queries)"])
|
|
231
|
-
return 0
|
|
232
|
-
|
|
233
|
-
if args.show_common_queries:
|
|
234
|
-
common_queries = query_loader.get_common_queries()
|
|
235
|
-
if common_queries:
|
|
236
|
-
output_list("Common queries across multiple languages:")
|
|
237
|
-
for query in common_queries:
|
|
238
|
-
output_list(f" {query}")
|
|
239
|
-
else:
|
|
240
|
-
output_info("No common queries found.")
|
|
241
|
-
return 0
|
|
242
|
-
|
|
243
|
-
return None
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
def main() -> None:
|
|
247
|
-
"""Main entry point for the CLI."""
|
|
248
|
-
# Early check for quiet mode to set environment variable before any imports
|
|
249
|
-
import os
|
|
250
|
-
|
|
251
|
-
if "--quiet" in sys.argv:
|
|
252
|
-
os.environ["LOG_LEVEL"] = "ERROR"
|
|
253
|
-
|
|
254
|
-
parser = create_argument_parser()
|
|
255
|
-
args = parser.parse_args()
|
|
256
|
-
|
|
257
|
-
# Configure logging for table output
|
|
258
|
-
if hasattr(args, "table") and args.table:
|
|
259
|
-
logging.getLogger().setLevel(logging.ERROR)
|
|
260
|
-
logging.getLogger("tree_sitter_analyzer").setLevel(logging.ERROR)
|
|
261
|
-
logging.getLogger("tree_sitter_analyzer.performance").setLevel(logging.ERROR)
|
|
262
|
-
|
|
263
|
-
# Configure logging for quiet mode
|
|
264
|
-
if hasattr(args, "quiet") and args.quiet:
|
|
265
|
-
logging.getLogger().setLevel(logging.ERROR)
|
|
266
|
-
logging.getLogger("tree_sitter_analyzer").setLevel(logging.ERROR)
|
|
267
|
-
logging.getLogger("tree_sitter_analyzer.performance").setLevel(logging.ERROR)
|
|
268
|
-
|
|
269
|
-
# Handle special commands first
|
|
270
|
-
special_result = handle_special_commands(args)
|
|
271
|
-
if special_result is not None:
|
|
272
|
-
sys.exit(special_result)
|
|
273
|
-
|
|
274
|
-
# Create and execute command
|
|
275
|
-
command = CLICommandFactory.create_command(args)
|
|
276
|
-
|
|
277
|
-
if command:
|
|
278
|
-
exit_code = command.execute()
|
|
279
|
-
sys.exit(exit_code)
|
|
280
|
-
else:
|
|
281
|
-
if not args.file_path:
|
|
282
|
-
output_error("ERROR: File path not specified.")
|
|
283
|
-
else:
|
|
284
|
-
output_error("ERROR: No executable command specified.")
|
|
285
|
-
parser.print_help()
|
|
286
|
-
sys.exit(1)
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
if __name__ == "__main__":
|
|
290
|
-
try:
|
|
291
|
-
main()
|
|
292
|
-
except KeyboardInterrupt:
|
|
293
|
-
output_info("\nOperation cancelled by user.")
|
|
294
|
-
sys.exit(1)
|
|
295
|
-
except Exception as e:
|
|
296
|
-
output_error(f"Unexpected error: {e}")
|
|
297
|
-
sys.exit(1)
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""CLI Main Module - Entry point for command-line interface."""
|
|
3
|
+
|
|
4
|
+
import argparse
|
|
5
|
+
import logging
|
|
6
|
+
import sys
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
# Import command classes
|
|
10
|
+
from .cli.commands import (
|
|
11
|
+
AdvancedCommand,
|
|
12
|
+
DefaultCommand,
|
|
13
|
+
PartialReadCommand,
|
|
14
|
+
QueryCommand,
|
|
15
|
+
StructureCommand,
|
|
16
|
+
SummaryCommand,
|
|
17
|
+
TableCommand,
|
|
18
|
+
)
|
|
19
|
+
from .cli.info_commands import (
|
|
20
|
+
DescribeQueryCommand,
|
|
21
|
+
ListQueriesCommand,
|
|
22
|
+
ShowExtensionsCommand,
|
|
23
|
+
ShowLanguagesCommand,
|
|
24
|
+
)
|
|
25
|
+
from .output_manager import output_error, output_info, output_list
|
|
26
|
+
from .query_loader import query_loader
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class CLICommandFactory:
|
|
30
|
+
"""Factory for creating CLI commands based on arguments."""
|
|
31
|
+
|
|
32
|
+
@staticmethod
|
|
33
|
+
def create_command(args: argparse.Namespace) -> Any:
|
|
34
|
+
"""Create appropriate command based on arguments."""
|
|
35
|
+
|
|
36
|
+
# Information commands (no file analysis required)
|
|
37
|
+
if args.list_queries:
|
|
38
|
+
return ListQueriesCommand(args)
|
|
39
|
+
|
|
40
|
+
if args.describe_query:
|
|
41
|
+
return DescribeQueryCommand(args)
|
|
42
|
+
|
|
43
|
+
if args.show_supported_languages:
|
|
44
|
+
return ShowLanguagesCommand(args)
|
|
45
|
+
|
|
46
|
+
if args.show_supported_extensions:
|
|
47
|
+
return ShowExtensionsCommand(args)
|
|
48
|
+
|
|
49
|
+
# File analysis commands (require file path)
|
|
50
|
+
if not args.file_path:
|
|
51
|
+
return None
|
|
52
|
+
|
|
53
|
+
# Partial read command - highest priority for file operations
|
|
54
|
+
if hasattr(args, "partial_read") and args.partial_read:
|
|
55
|
+
return PartialReadCommand(args)
|
|
56
|
+
|
|
57
|
+
if hasattr(args, "table") and args.table:
|
|
58
|
+
return TableCommand(args)
|
|
59
|
+
|
|
60
|
+
if hasattr(args, "structure") and args.structure:
|
|
61
|
+
return StructureCommand(args)
|
|
62
|
+
|
|
63
|
+
if hasattr(args, "summary") and args.summary is not None:
|
|
64
|
+
return SummaryCommand(args)
|
|
65
|
+
|
|
66
|
+
if hasattr(args, "advanced") and args.advanced:
|
|
67
|
+
return AdvancedCommand(args)
|
|
68
|
+
|
|
69
|
+
if hasattr(args, "query_key") and args.query_key:
|
|
70
|
+
return QueryCommand(args)
|
|
71
|
+
|
|
72
|
+
if hasattr(args, "query_string") and args.query_string:
|
|
73
|
+
return QueryCommand(args)
|
|
74
|
+
|
|
75
|
+
# Default command - if file_path is provided but no specific command, use default analysis
|
|
76
|
+
return DefaultCommand(args)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def create_argument_parser() -> argparse.ArgumentParser:
|
|
80
|
+
"""Create and configure the argument parser."""
|
|
81
|
+
parser = argparse.ArgumentParser(
|
|
82
|
+
description="Analyze code using Tree-sitter and extract structured information.",
|
|
83
|
+
epilog="Example: tree-sitter-analyzer example.java --table=full",
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
# File path
|
|
87
|
+
parser.add_argument("file_path", nargs="?", help="Path to the file to analyze")
|
|
88
|
+
|
|
89
|
+
# Query options
|
|
90
|
+
query_group = parser.add_mutually_exclusive_group(required=False)
|
|
91
|
+
query_group.add_argument(
|
|
92
|
+
"--query-key", help="Available query key (e.g., class, method)"
|
|
93
|
+
)
|
|
94
|
+
query_group.add_argument(
|
|
95
|
+
"--query-string", help="Directly specify Tree-sitter query to execute"
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
# Information options
|
|
99
|
+
parser.add_argument(
|
|
100
|
+
"--list-queries",
|
|
101
|
+
action="store_true",
|
|
102
|
+
help="Display list of available query keys",
|
|
103
|
+
)
|
|
104
|
+
parser.add_argument(
|
|
105
|
+
"--describe-query", help="Display description of specified query key"
|
|
106
|
+
)
|
|
107
|
+
parser.add_argument(
|
|
108
|
+
"--show-supported-languages",
|
|
109
|
+
action="store_true",
|
|
110
|
+
help="Display list of supported languages",
|
|
111
|
+
)
|
|
112
|
+
parser.add_argument(
|
|
113
|
+
"--show-supported-extensions",
|
|
114
|
+
action="store_true",
|
|
115
|
+
help="Display list of supported file extensions",
|
|
116
|
+
)
|
|
117
|
+
parser.add_argument(
|
|
118
|
+
"--show-common-queries",
|
|
119
|
+
action="store_true",
|
|
120
|
+
help="Display list of common queries across multiple languages",
|
|
121
|
+
)
|
|
122
|
+
parser.add_argument(
|
|
123
|
+
"--show-query-languages",
|
|
124
|
+
action="store_true",
|
|
125
|
+
help="Display list of languages with query support",
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
# Output format options
|
|
129
|
+
parser.add_argument(
|
|
130
|
+
"--output-format",
|
|
131
|
+
choices=["json", "text"],
|
|
132
|
+
default="json",
|
|
133
|
+
help="Specify output format",
|
|
134
|
+
)
|
|
135
|
+
parser.add_argument(
|
|
136
|
+
"--table", choices=["full", "compact", "csv"], help="Output in table format"
|
|
137
|
+
)
|
|
138
|
+
parser.add_argument(
|
|
139
|
+
"--include-javadoc",
|
|
140
|
+
action="store_true",
|
|
141
|
+
help="Include JavaDoc/documentation comments in output",
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
# Analysis options
|
|
145
|
+
parser.add_argument(
|
|
146
|
+
"--advanced", action="store_true", help="Use advanced analysis features"
|
|
147
|
+
)
|
|
148
|
+
parser.add_argument(
|
|
149
|
+
"--summary",
|
|
150
|
+
nargs="?",
|
|
151
|
+
const="classes,methods",
|
|
152
|
+
help="Display summary of specified element types",
|
|
153
|
+
)
|
|
154
|
+
parser.add_argument(
|
|
155
|
+
"--structure",
|
|
156
|
+
action="store_true",
|
|
157
|
+
help="Output detailed structure information in JSON format",
|
|
158
|
+
)
|
|
159
|
+
parser.add_argument(
|
|
160
|
+
"--statistics", action="store_true", help="Display only statistical information"
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
# Language options
|
|
164
|
+
parser.add_argument(
|
|
165
|
+
"--language",
|
|
166
|
+
help="Explicitly specify language (auto-detected from extension if omitted)",
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
# Logging options
|
|
170
|
+
parser.add_argument(
|
|
171
|
+
"--quiet",
|
|
172
|
+
action="store_true",
|
|
173
|
+
help="Suppress INFO level logs (show errors only)",
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
# Partial reading options
|
|
177
|
+
parser.add_argument(
|
|
178
|
+
"--partial-read",
|
|
179
|
+
action="store_true",
|
|
180
|
+
help="Enable partial file reading mode",
|
|
181
|
+
)
|
|
182
|
+
parser.add_argument(
|
|
183
|
+
"--start-line", type=int, help="Starting line number for reading (1-based)"
|
|
184
|
+
)
|
|
185
|
+
parser.add_argument(
|
|
186
|
+
"--end-line", type=int, help="Ending line number for reading (1-based)"
|
|
187
|
+
)
|
|
188
|
+
parser.add_argument(
|
|
189
|
+
"--start-column", type=int, help="Starting column number for reading (0-based)"
|
|
190
|
+
)
|
|
191
|
+
parser.add_argument(
|
|
192
|
+
"--end-column", type=int, help="Ending column number for reading (0-based)"
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
return parser
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def handle_special_commands(args: argparse.Namespace) -> int | None:
|
|
199
|
+
"""Handle special commands that don't fit the normal pattern."""
|
|
200
|
+
|
|
201
|
+
# Validate partial read options
|
|
202
|
+
if hasattr(args, "partial_read") and args.partial_read:
|
|
203
|
+
if args.start_line is None:
|
|
204
|
+
output_error("ERROR: --start-line is required")
|
|
205
|
+
return 1
|
|
206
|
+
|
|
207
|
+
if args.start_line < 1:
|
|
208
|
+
output_error("ERROR: --start-line must be 1 or greater")
|
|
209
|
+
return 1
|
|
210
|
+
|
|
211
|
+
if args.end_line and args.end_line < args.start_line:
|
|
212
|
+
output_error(
|
|
213
|
+
"ERROR: --end-line must be greater than or equal to --start-line"
|
|
214
|
+
)
|
|
215
|
+
return 1
|
|
216
|
+
|
|
217
|
+
if args.start_column is not None and args.start_column < 0:
|
|
218
|
+
output_error("ERROR: --start-column must be 0 or greater")
|
|
219
|
+
return 1
|
|
220
|
+
|
|
221
|
+
if args.end_column is not None and args.end_column < 0:
|
|
222
|
+
output_error("ERROR: --end-column must be 0 or greater")
|
|
223
|
+
return 1
|
|
224
|
+
|
|
225
|
+
# Query language commands
|
|
226
|
+
if args.show_query_languages:
|
|
227
|
+
output_list(["Languages with query support:"])
|
|
228
|
+
for lang in query_loader.list_supported_languages():
|
|
229
|
+
query_count = len(query_loader.list_queries_for_language(lang))
|
|
230
|
+
output_list([f" {lang:<15} ({query_count} queries)"])
|
|
231
|
+
return 0
|
|
232
|
+
|
|
233
|
+
if args.show_common_queries:
|
|
234
|
+
common_queries = query_loader.get_common_queries()
|
|
235
|
+
if common_queries:
|
|
236
|
+
output_list("Common queries across multiple languages:")
|
|
237
|
+
for query in common_queries:
|
|
238
|
+
output_list(f" {query}")
|
|
239
|
+
else:
|
|
240
|
+
output_info("No common queries found.")
|
|
241
|
+
return 0
|
|
242
|
+
|
|
243
|
+
return None
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def main() -> None:
|
|
247
|
+
"""Main entry point for the CLI."""
|
|
248
|
+
# Early check for quiet mode to set environment variable before any imports
|
|
249
|
+
import os
|
|
250
|
+
|
|
251
|
+
if "--quiet" in sys.argv:
|
|
252
|
+
os.environ["LOG_LEVEL"] = "ERROR"
|
|
253
|
+
|
|
254
|
+
parser = create_argument_parser()
|
|
255
|
+
args = parser.parse_args()
|
|
256
|
+
|
|
257
|
+
# Configure logging for table output
|
|
258
|
+
if hasattr(args, "table") and args.table:
|
|
259
|
+
logging.getLogger().setLevel(logging.ERROR)
|
|
260
|
+
logging.getLogger("tree_sitter_analyzer").setLevel(logging.ERROR)
|
|
261
|
+
logging.getLogger("tree_sitter_analyzer.performance").setLevel(logging.ERROR)
|
|
262
|
+
|
|
263
|
+
# Configure logging for quiet mode
|
|
264
|
+
if hasattr(args, "quiet") and args.quiet:
|
|
265
|
+
logging.getLogger().setLevel(logging.ERROR)
|
|
266
|
+
logging.getLogger("tree_sitter_analyzer").setLevel(logging.ERROR)
|
|
267
|
+
logging.getLogger("tree_sitter_analyzer.performance").setLevel(logging.ERROR)
|
|
268
|
+
|
|
269
|
+
# Handle special commands first
|
|
270
|
+
special_result = handle_special_commands(args)
|
|
271
|
+
if special_result is not None:
|
|
272
|
+
sys.exit(special_result)
|
|
273
|
+
|
|
274
|
+
# Create and execute command
|
|
275
|
+
command = CLICommandFactory.create_command(args)
|
|
276
|
+
|
|
277
|
+
if command:
|
|
278
|
+
exit_code = command.execute()
|
|
279
|
+
sys.exit(exit_code)
|
|
280
|
+
else:
|
|
281
|
+
if not args.file_path:
|
|
282
|
+
output_error("ERROR: File path not specified.")
|
|
283
|
+
else:
|
|
284
|
+
output_error("ERROR: No executable command specified.")
|
|
285
|
+
parser.print_help()
|
|
286
|
+
sys.exit(1)
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
if __name__ == "__main__":
|
|
290
|
+
try:
|
|
291
|
+
main()
|
|
292
|
+
except KeyboardInterrupt:
|
|
293
|
+
output_info("\nOperation cancelled by user.")
|
|
294
|
+
sys.exit(1)
|
|
295
|
+
except Exception as e:
|
|
296
|
+
output_error(f"Unexpected error: {e}")
|
|
297
|
+
sys.exit(1)
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""
|
|
3
|
-
Core module for tree_sitter_analyzer.
|
|
4
|
-
|
|
5
|
-
This module contains the core components of the new architecture:
|
|
6
|
-
- AnalysisEngine: Main analysis orchestrator
|
|
7
|
-
- Parser: Tree-sitter parsing wrapper
|
|
8
|
-
- QueryExecutor: Query execution engine
|
|
9
|
-
"""
|
|
10
|
-
|
|
11
|
-
from .engine import AnalysisEngine
|
|
12
|
-
from .parser import Parser, ParseResult
|
|
13
|
-
from .query import QueryExecutor
|
|
14
|
-
|
|
15
|
-
__all__ = ["AnalysisEngine", "Parser", "ParseResult", "QueryExecutor"]
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Core module for tree_sitter_analyzer.
|
|
4
|
+
|
|
5
|
+
This module contains the core components of the new architecture:
|
|
6
|
+
- AnalysisEngine: Main analysis orchestrator
|
|
7
|
+
- Parser: Tree-sitter parsing wrapper
|
|
8
|
+
- QueryExecutor: Query execution engine
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from .engine import AnalysisEngine
|
|
12
|
+
from .parser import Parser, ParseResult
|
|
13
|
+
from .query import QueryExecutor
|
|
14
|
+
|
|
15
|
+
__all__ = ["AnalysisEngine", "Parser", "ParseResult", "QueryExecutor"]
|