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.
- tree_sitter_analyzer/__init__.py +132 -0
- tree_sitter_analyzer/__main__.py +11 -0
- tree_sitter_analyzer/api.py +853 -0
- tree_sitter_analyzer/cli/__init__.py +39 -0
- tree_sitter_analyzer/cli/__main__.py +12 -0
- tree_sitter_analyzer/cli/argument_validator.py +89 -0
- tree_sitter_analyzer/cli/commands/__init__.py +26 -0
- tree_sitter_analyzer/cli/commands/advanced_command.py +226 -0
- tree_sitter_analyzer/cli/commands/base_command.py +181 -0
- tree_sitter_analyzer/cli/commands/default_command.py +18 -0
- tree_sitter_analyzer/cli/commands/find_and_grep_cli.py +188 -0
- tree_sitter_analyzer/cli/commands/list_files_cli.py +133 -0
- tree_sitter_analyzer/cli/commands/partial_read_command.py +139 -0
- tree_sitter_analyzer/cli/commands/query_command.py +109 -0
- tree_sitter_analyzer/cli/commands/search_content_cli.py +161 -0
- tree_sitter_analyzer/cli/commands/structure_command.py +156 -0
- tree_sitter_analyzer/cli/commands/summary_command.py +116 -0
- tree_sitter_analyzer/cli/commands/table_command.py +414 -0
- tree_sitter_analyzer/cli/info_commands.py +124 -0
- tree_sitter_analyzer/cli_main.py +472 -0
- tree_sitter_analyzer/constants.py +85 -0
- tree_sitter_analyzer/core/__init__.py +15 -0
- tree_sitter_analyzer/core/analysis_engine.py +580 -0
- tree_sitter_analyzer/core/cache_service.py +333 -0
- tree_sitter_analyzer/core/engine.py +585 -0
- tree_sitter_analyzer/core/parser.py +293 -0
- tree_sitter_analyzer/core/query.py +605 -0
- tree_sitter_analyzer/core/query_filter.py +200 -0
- tree_sitter_analyzer/core/query_service.py +340 -0
- tree_sitter_analyzer/encoding_utils.py +530 -0
- tree_sitter_analyzer/exceptions.py +747 -0
- tree_sitter_analyzer/file_handler.py +246 -0
- tree_sitter_analyzer/formatters/__init__.py +1 -0
- tree_sitter_analyzer/formatters/base_formatter.py +201 -0
- tree_sitter_analyzer/formatters/csharp_formatter.py +367 -0
- tree_sitter_analyzer/formatters/formatter_config.py +197 -0
- tree_sitter_analyzer/formatters/formatter_factory.py +84 -0
- tree_sitter_analyzer/formatters/formatter_registry.py +377 -0
- tree_sitter_analyzer/formatters/formatter_selector.py +96 -0
- tree_sitter_analyzer/formatters/go_formatter.py +368 -0
- tree_sitter_analyzer/formatters/html_formatter.py +498 -0
- tree_sitter_analyzer/formatters/java_formatter.py +423 -0
- tree_sitter_analyzer/formatters/javascript_formatter.py +611 -0
- tree_sitter_analyzer/formatters/kotlin_formatter.py +268 -0
- tree_sitter_analyzer/formatters/language_formatter_factory.py +123 -0
- tree_sitter_analyzer/formatters/legacy_formatter_adapters.py +228 -0
- tree_sitter_analyzer/formatters/markdown_formatter.py +725 -0
- tree_sitter_analyzer/formatters/php_formatter.py +301 -0
- tree_sitter_analyzer/formatters/python_formatter.py +830 -0
- tree_sitter_analyzer/formatters/ruby_formatter.py +278 -0
- tree_sitter_analyzer/formatters/rust_formatter.py +233 -0
- tree_sitter_analyzer/formatters/sql_formatter_wrapper.py +689 -0
- tree_sitter_analyzer/formatters/sql_formatters.py +536 -0
- tree_sitter_analyzer/formatters/typescript_formatter.py +543 -0
- tree_sitter_analyzer/formatters/yaml_formatter.py +462 -0
- tree_sitter_analyzer/interfaces/__init__.py +9 -0
- tree_sitter_analyzer/interfaces/cli.py +535 -0
- tree_sitter_analyzer/interfaces/cli_adapter.py +359 -0
- tree_sitter_analyzer/interfaces/mcp_adapter.py +224 -0
- tree_sitter_analyzer/interfaces/mcp_server.py +428 -0
- tree_sitter_analyzer/language_detector.py +553 -0
- tree_sitter_analyzer/language_loader.py +271 -0
- tree_sitter_analyzer/languages/__init__.py +10 -0
- tree_sitter_analyzer/languages/csharp_plugin.py +1076 -0
- tree_sitter_analyzer/languages/css_plugin.py +449 -0
- tree_sitter_analyzer/languages/go_plugin.py +836 -0
- tree_sitter_analyzer/languages/html_plugin.py +496 -0
- tree_sitter_analyzer/languages/java_plugin.py +1299 -0
- tree_sitter_analyzer/languages/javascript_plugin.py +1622 -0
- tree_sitter_analyzer/languages/kotlin_plugin.py +656 -0
- tree_sitter_analyzer/languages/markdown_plugin.py +1928 -0
- tree_sitter_analyzer/languages/php_plugin.py +862 -0
- tree_sitter_analyzer/languages/python_plugin.py +1636 -0
- tree_sitter_analyzer/languages/ruby_plugin.py +757 -0
- tree_sitter_analyzer/languages/rust_plugin.py +673 -0
- tree_sitter_analyzer/languages/sql_plugin.py +2444 -0
- tree_sitter_analyzer/languages/typescript_plugin.py +1892 -0
- tree_sitter_analyzer/languages/yaml_plugin.py +695 -0
- tree_sitter_analyzer/legacy_table_formatter.py +860 -0
- tree_sitter_analyzer/mcp/__init__.py +34 -0
- tree_sitter_analyzer/mcp/resources/__init__.py +43 -0
- tree_sitter_analyzer/mcp/resources/code_file_resource.py +208 -0
- tree_sitter_analyzer/mcp/resources/project_stats_resource.py +586 -0
- tree_sitter_analyzer/mcp/server.py +869 -0
- tree_sitter_analyzer/mcp/tools/__init__.py +28 -0
- tree_sitter_analyzer/mcp/tools/analyze_scale_tool.py +779 -0
- tree_sitter_analyzer/mcp/tools/analyze_scale_tool_cli_compatible.py +291 -0
- tree_sitter_analyzer/mcp/tools/base_tool.py +139 -0
- tree_sitter_analyzer/mcp/tools/fd_rg_utils.py +816 -0
- tree_sitter_analyzer/mcp/tools/find_and_grep_tool.py +686 -0
- tree_sitter_analyzer/mcp/tools/list_files_tool.py +413 -0
- tree_sitter_analyzer/mcp/tools/output_format_validator.py +148 -0
- tree_sitter_analyzer/mcp/tools/query_tool.py +443 -0
- tree_sitter_analyzer/mcp/tools/read_partial_tool.py +464 -0
- tree_sitter_analyzer/mcp/tools/search_content_tool.py +836 -0
- tree_sitter_analyzer/mcp/tools/table_format_tool.py +572 -0
- tree_sitter_analyzer/mcp/tools/universal_analyze_tool.py +653 -0
- tree_sitter_analyzer/mcp/utils/__init__.py +113 -0
- tree_sitter_analyzer/mcp/utils/error_handler.py +569 -0
- tree_sitter_analyzer/mcp/utils/file_output_factory.py +217 -0
- tree_sitter_analyzer/mcp/utils/file_output_manager.py +322 -0
- tree_sitter_analyzer/mcp/utils/gitignore_detector.py +358 -0
- tree_sitter_analyzer/mcp/utils/path_resolver.py +414 -0
- tree_sitter_analyzer/mcp/utils/search_cache.py +343 -0
- tree_sitter_analyzer/models.py +840 -0
- tree_sitter_analyzer/mypy_current_errors.txt +2 -0
- tree_sitter_analyzer/output_manager.py +255 -0
- tree_sitter_analyzer/platform_compat/__init__.py +3 -0
- tree_sitter_analyzer/platform_compat/adapter.py +324 -0
- tree_sitter_analyzer/platform_compat/compare.py +224 -0
- tree_sitter_analyzer/platform_compat/detector.py +67 -0
- tree_sitter_analyzer/platform_compat/fixtures.py +228 -0
- tree_sitter_analyzer/platform_compat/profiles.py +217 -0
- tree_sitter_analyzer/platform_compat/record.py +55 -0
- tree_sitter_analyzer/platform_compat/recorder.py +155 -0
- tree_sitter_analyzer/platform_compat/report.py +92 -0
- tree_sitter_analyzer/plugins/__init__.py +280 -0
- tree_sitter_analyzer/plugins/base.py +647 -0
- tree_sitter_analyzer/plugins/manager.py +384 -0
- tree_sitter_analyzer/project_detector.py +328 -0
- tree_sitter_analyzer/queries/__init__.py +27 -0
- tree_sitter_analyzer/queries/csharp.py +216 -0
- tree_sitter_analyzer/queries/css.py +615 -0
- tree_sitter_analyzer/queries/go.py +275 -0
- tree_sitter_analyzer/queries/html.py +543 -0
- tree_sitter_analyzer/queries/java.py +402 -0
- tree_sitter_analyzer/queries/javascript.py +724 -0
- tree_sitter_analyzer/queries/kotlin.py +192 -0
- tree_sitter_analyzer/queries/markdown.py +258 -0
- tree_sitter_analyzer/queries/php.py +95 -0
- tree_sitter_analyzer/queries/python.py +859 -0
- tree_sitter_analyzer/queries/ruby.py +92 -0
- tree_sitter_analyzer/queries/rust.py +223 -0
- tree_sitter_analyzer/queries/sql.py +555 -0
- tree_sitter_analyzer/queries/typescript.py +871 -0
- tree_sitter_analyzer/queries/yaml.py +236 -0
- tree_sitter_analyzer/query_loader.py +272 -0
- tree_sitter_analyzer/security/__init__.py +22 -0
- tree_sitter_analyzer/security/boundary_manager.py +277 -0
- tree_sitter_analyzer/security/regex_checker.py +297 -0
- tree_sitter_analyzer/security/validator.py +599 -0
- tree_sitter_analyzer/table_formatter.py +782 -0
- tree_sitter_analyzer/utils/__init__.py +53 -0
- tree_sitter_analyzer/utils/logging.py +433 -0
- tree_sitter_analyzer/utils/tree_sitter_compat.py +289 -0
- tree_sitter_analyzer-1.9.17.1.dist-info/METADATA +485 -0
- tree_sitter_analyzer-1.9.17.1.dist-info/RECORD +149 -0
- tree_sitter_analyzer-1.9.17.1.dist-info/WHEEL +4 -0
- tree_sitter_analyzer-1.9.17.1.dist-info/entry_points.txt +25 -0
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Go Language Queries
|
|
4
|
+
|
|
5
|
+
Tree-sitter queries specific to Go language constructs.
|
|
6
|
+
Covers packages, functions, methods, structs, interfaces, and other Go-specific elements.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
# Go-specific query library
|
|
10
|
+
GO_QUERIES: dict[str, str] = {
|
|
11
|
+
# --- Basic Structure ---
|
|
12
|
+
"package": """
|
|
13
|
+
(package_clause) @package
|
|
14
|
+
""",
|
|
15
|
+
"import": """
|
|
16
|
+
(import_declaration) @import
|
|
17
|
+
""",
|
|
18
|
+
"import_spec": """
|
|
19
|
+
(import_spec) @import_spec
|
|
20
|
+
""",
|
|
21
|
+
# --- Functions and Methods ---
|
|
22
|
+
"function": """
|
|
23
|
+
(function_declaration) @function
|
|
24
|
+
""",
|
|
25
|
+
"method": """
|
|
26
|
+
(method_declaration) @method
|
|
27
|
+
""",
|
|
28
|
+
# --- Types ---
|
|
29
|
+
"struct": """
|
|
30
|
+
(type_declaration
|
|
31
|
+
(type_spec
|
|
32
|
+
type: (struct_type))) @struct
|
|
33
|
+
""",
|
|
34
|
+
"interface": """
|
|
35
|
+
(type_declaration
|
|
36
|
+
(type_spec
|
|
37
|
+
type: (interface_type))) @interface
|
|
38
|
+
""",
|
|
39
|
+
"type_alias": """
|
|
40
|
+
(type_declaration
|
|
41
|
+
(type_spec
|
|
42
|
+
type: (_))) @type_alias
|
|
43
|
+
""",
|
|
44
|
+
# --- Variables and Constants ---
|
|
45
|
+
"const": """
|
|
46
|
+
(const_declaration) @const
|
|
47
|
+
""",
|
|
48
|
+
"var": """
|
|
49
|
+
(var_declaration) @var
|
|
50
|
+
""",
|
|
51
|
+
"const_spec": """
|
|
52
|
+
(const_spec) @const_spec
|
|
53
|
+
""",
|
|
54
|
+
"var_spec": """
|
|
55
|
+
(var_spec) @var_spec
|
|
56
|
+
""",
|
|
57
|
+
# --- Concurrency ---
|
|
58
|
+
"goroutine": """
|
|
59
|
+
(go_statement) @goroutine
|
|
60
|
+
""",
|
|
61
|
+
"channel_send": """
|
|
62
|
+
(send_statement) @channel_send
|
|
63
|
+
""",
|
|
64
|
+
"channel_receive": """
|
|
65
|
+
(receive_statement) @channel_receive
|
|
66
|
+
""",
|
|
67
|
+
"select": """
|
|
68
|
+
(select_statement) @select
|
|
69
|
+
""",
|
|
70
|
+
# --- Control Flow ---
|
|
71
|
+
"defer": """
|
|
72
|
+
(defer_statement) @defer
|
|
73
|
+
""",
|
|
74
|
+
"if": """
|
|
75
|
+
(if_statement) @if
|
|
76
|
+
""",
|
|
77
|
+
"for": """
|
|
78
|
+
(for_statement) @for
|
|
79
|
+
""",
|
|
80
|
+
"switch": """
|
|
81
|
+
(expression_switch_statement) @switch
|
|
82
|
+
""",
|
|
83
|
+
"type_switch": """
|
|
84
|
+
(type_switch_statement) @type_switch
|
|
85
|
+
""",
|
|
86
|
+
# --- Name-only Extraction ---
|
|
87
|
+
"function_name": """
|
|
88
|
+
(function_declaration
|
|
89
|
+
name: (identifier) @function_name)
|
|
90
|
+
""",
|
|
91
|
+
"method_name": """
|
|
92
|
+
(method_declaration
|
|
93
|
+
name: (field_identifier) @method_name)
|
|
94
|
+
""",
|
|
95
|
+
"struct_name": """
|
|
96
|
+
(type_declaration
|
|
97
|
+
(type_spec
|
|
98
|
+
name: (type_identifier) @struct_name
|
|
99
|
+
type: (struct_type)))
|
|
100
|
+
""",
|
|
101
|
+
"interface_name": """
|
|
102
|
+
(type_declaration
|
|
103
|
+
(type_spec
|
|
104
|
+
name: (type_identifier) @interface_name
|
|
105
|
+
type: (interface_type)))
|
|
106
|
+
""",
|
|
107
|
+
# --- Detailed Queries ---
|
|
108
|
+
"function_with_body": """
|
|
109
|
+
(function_declaration
|
|
110
|
+
name: (identifier) @name
|
|
111
|
+
body: (block) @body) @function_with_body
|
|
112
|
+
""",
|
|
113
|
+
"method_with_receiver": """
|
|
114
|
+
(method_declaration
|
|
115
|
+
receiver: (parameter_list) @receiver
|
|
116
|
+
name: (field_identifier) @name
|
|
117
|
+
body: (block) @body) @method_with_receiver
|
|
118
|
+
""",
|
|
119
|
+
"struct_with_fields": """
|
|
120
|
+
(type_declaration
|
|
121
|
+
(type_spec
|
|
122
|
+
name: (type_identifier) @name
|
|
123
|
+
type: (struct_type
|
|
124
|
+
(field_declaration_list) @fields))) @struct_with_fields
|
|
125
|
+
""",
|
|
126
|
+
"interface_with_methods": """
|
|
127
|
+
(type_declaration
|
|
128
|
+
(type_spec
|
|
129
|
+
name: (type_identifier) @name
|
|
130
|
+
type: (interface_type) @methods)) @interface_with_methods
|
|
131
|
+
""",
|
|
132
|
+
# --- Comments ---
|
|
133
|
+
"comment": """
|
|
134
|
+
(comment) @comment
|
|
135
|
+
""",
|
|
136
|
+
# --- Error Handling ---
|
|
137
|
+
"error_check": """
|
|
138
|
+
(if_statement
|
|
139
|
+
condition: (binary_expression
|
|
140
|
+
left: (identifier) @err
|
|
141
|
+
(#eq? @err "err")
|
|
142
|
+
operator: "!="
|
|
143
|
+
right: (nil))) @error_check
|
|
144
|
+
""",
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
# Query descriptions
|
|
148
|
+
GO_QUERY_DESCRIPTIONS: dict[str, str] = {
|
|
149
|
+
"package": "Extract Go package declarations",
|
|
150
|
+
"import": "Extract Go import declarations",
|
|
151
|
+
"import_spec": "Extract individual import specifications",
|
|
152
|
+
"function": "Extract Go function declarations",
|
|
153
|
+
"method": "Extract Go method declarations",
|
|
154
|
+
"struct": "Extract Go struct type declarations",
|
|
155
|
+
"interface": "Extract Go interface type declarations",
|
|
156
|
+
"type_alias": "Extract Go type alias declarations",
|
|
157
|
+
"const": "Extract Go const declarations",
|
|
158
|
+
"var": "Extract Go var declarations",
|
|
159
|
+
"const_spec": "Extract individual const specifications",
|
|
160
|
+
"var_spec": "Extract individual var specifications",
|
|
161
|
+
"goroutine": "Extract goroutine (go statement) invocations",
|
|
162
|
+
"channel_send": "Extract channel send operations",
|
|
163
|
+
"channel_receive": "Extract channel receive operations",
|
|
164
|
+
"select": "Extract select statements",
|
|
165
|
+
"defer": "Extract defer statements",
|
|
166
|
+
"if": "Extract if statements",
|
|
167
|
+
"for": "Extract for statements",
|
|
168
|
+
"switch": "Extract switch statements",
|
|
169
|
+
"type_switch": "Extract type switch statements",
|
|
170
|
+
"function_name": "Extract function names only",
|
|
171
|
+
"method_name": "Extract method names only",
|
|
172
|
+
"struct_name": "Extract struct names only",
|
|
173
|
+
"interface_name": "Extract interface names only",
|
|
174
|
+
"function_with_body": "Extract function declarations with body",
|
|
175
|
+
"method_with_receiver": "Extract method declarations with receiver",
|
|
176
|
+
"struct_with_fields": "Extract struct declarations with fields",
|
|
177
|
+
"interface_with_methods": "Extract interface declarations with methods",
|
|
178
|
+
"comment": "Extract comments",
|
|
179
|
+
"error_check": "Extract error checking patterns",
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def get_go_query(name: str) -> str:
|
|
184
|
+
"""
|
|
185
|
+
Get the specified Go query
|
|
186
|
+
|
|
187
|
+
Args:
|
|
188
|
+
name: Query name
|
|
189
|
+
|
|
190
|
+
Returns:
|
|
191
|
+
Query string
|
|
192
|
+
|
|
193
|
+
Raises:
|
|
194
|
+
ValueError: When query is not found
|
|
195
|
+
"""
|
|
196
|
+
if name not in GO_QUERIES:
|
|
197
|
+
available = list(GO_QUERIES.keys())
|
|
198
|
+
raise ValueError(f"Go query '{name}' does not exist. Available: {available}")
|
|
199
|
+
|
|
200
|
+
return GO_QUERIES[name]
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def get_go_query_description(name: str) -> str:
|
|
204
|
+
"""
|
|
205
|
+
Get the description of the specified Go query
|
|
206
|
+
|
|
207
|
+
Args:
|
|
208
|
+
name: Query name
|
|
209
|
+
|
|
210
|
+
Returns:
|
|
211
|
+
Query description
|
|
212
|
+
"""
|
|
213
|
+
return GO_QUERY_DESCRIPTIONS.get(name, "No description")
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
# Convert to ALL_QUERIES format for dynamic loader compatibility
|
|
217
|
+
ALL_QUERIES = {}
|
|
218
|
+
for query_name, query_string in GO_QUERIES.items():
|
|
219
|
+
description = GO_QUERY_DESCRIPTIONS.get(query_name, "No description")
|
|
220
|
+
ALL_QUERIES[query_name] = {"query": query_string, "description": description}
|
|
221
|
+
|
|
222
|
+
# Add common query aliases for cross-language compatibility
|
|
223
|
+
ALL_QUERIES["functions"] = {
|
|
224
|
+
"query": GO_QUERIES["function"],
|
|
225
|
+
"description": "Search all function declarations (alias for function)",
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
ALL_QUERIES["methods"] = {
|
|
229
|
+
"query": GO_QUERIES["method"],
|
|
230
|
+
"description": "Search all method declarations (alias for method)",
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
ALL_QUERIES["classes"] = {
|
|
234
|
+
"query": GO_QUERIES["struct"],
|
|
235
|
+
"description": "Search all struct declarations (alias for struct)",
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
ALL_QUERIES["structs"] = {
|
|
239
|
+
"query": GO_QUERIES["struct"],
|
|
240
|
+
"description": "Search all struct declarations (alias for struct)",
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
ALL_QUERIES["interfaces"] = {
|
|
244
|
+
"query": GO_QUERIES["interface"],
|
|
245
|
+
"description": "Search all interface declarations (alias for interface)",
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def get_query(name: str) -> str:
|
|
250
|
+
"""Get a specific query by name."""
|
|
251
|
+
if name in ALL_QUERIES:
|
|
252
|
+
return ALL_QUERIES[name]["query"]
|
|
253
|
+
raise ValueError(
|
|
254
|
+
f"Query '{name}' not found. Available queries: {list(ALL_QUERIES.keys())}"
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
def get_all_queries() -> dict:
|
|
259
|
+
"""Get all available queries."""
|
|
260
|
+
return ALL_QUERIES
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
def list_queries() -> list:
|
|
264
|
+
"""List all available query names."""
|
|
265
|
+
return list(ALL_QUERIES.keys())
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def get_available_go_queries() -> list[str]:
|
|
269
|
+
"""
|
|
270
|
+
Get list of available Go queries
|
|
271
|
+
|
|
272
|
+
Returns:
|
|
273
|
+
List of query names
|
|
274
|
+
"""
|
|
275
|
+
return list(GO_QUERIES.keys())
|