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,859 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Python Language Queries
|
|
4
|
+
|
|
5
|
+
Comprehensive Tree-sitter queries for Python language constructs.
|
|
6
|
+
Covers functions, classes, variables, imports, decorators, async/await,
|
|
7
|
+
type hints, and modern Python features.
|
|
8
|
+
Equivalent to JavaScript query coverage for consistent language support.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
# Function definitions
|
|
12
|
+
FUNCTIONS = """
|
|
13
|
+
(function_definition
|
|
14
|
+
name: (identifier) @function.name
|
|
15
|
+
parameters: (parameters) @function.params
|
|
16
|
+
body: (block) @function.body) @function.definition
|
|
17
|
+
|
|
18
|
+
(function_definition
|
|
19
|
+
name: (identifier) @function.name
|
|
20
|
+
parameters: (parameters) @function.params
|
|
21
|
+
body: (block) @function.body) @function.async
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
# Class definitions
|
|
25
|
+
CLASSES = """
|
|
26
|
+
(class_definition
|
|
27
|
+
name: (identifier) @class.name
|
|
28
|
+
superclasses: (argument_list)? @class.superclasses
|
|
29
|
+
body: (block) @class.body) @class.definition
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
# Import statements
|
|
33
|
+
IMPORTS = """
|
|
34
|
+
(import_statement
|
|
35
|
+
name: (dotted_name) @import.name) @import.statement
|
|
36
|
+
|
|
37
|
+
(import_from_statement
|
|
38
|
+
module_name: (dotted_name)? @import.module
|
|
39
|
+
name: (dotted_name) @import.name) @import.from
|
|
40
|
+
|
|
41
|
+
(import_from_statement
|
|
42
|
+
module_name: (dotted_name)? @import.module
|
|
43
|
+
name: (aliased_import) @import.aliased_item) @import.from_aliased
|
|
44
|
+
|
|
45
|
+
(aliased_import
|
|
46
|
+
name: (dotted_name) @import.name
|
|
47
|
+
alias: (identifier) @import.alias) @import.aliased
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
# Variable assignments
|
|
51
|
+
VARIABLES = """
|
|
52
|
+
(assignment
|
|
53
|
+
left: (identifier) @variable.name
|
|
54
|
+
right: (_) @variable.value) @variable.assignment
|
|
55
|
+
|
|
56
|
+
(assignment
|
|
57
|
+
left: (pattern_list) @variable.pattern
|
|
58
|
+
right: (_) @variable.value) @variable.multiple
|
|
59
|
+
|
|
60
|
+
(augmented_assignment
|
|
61
|
+
left: (identifier) @variable.name
|
|
62
|
+
right: (_) @variable.value) @variable.augmented
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
# Decorators
|
|
66
|
+
DECORATORS = """
|
|
67
|
+
(decorator
|
|
68
|
+
(identifier) @decorator.name) @decorator.simple
|
|
69
|
+
|
|
70
|
+
(decorator
|
|
71
|
+
(call
|
|
72
|
+
function: (identifier) @decorator.name
|
|
73
|
+
arguments: (argument_list) @decorator.args)) @decorator.call
|
|
74
|
+
|
|
75
|
+
(decorator
|
|
76
|
+
(attribute
|
|
77
|
+
object: (identifier) @decorator.object
|
|
78
|
+
attribute: (identifier) @decorator.name)) @decorator.attribute
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
# Method definitions
|
|
82
|
+
METHODS = """
|
|
83
|
+
(function_definition
|
|
84
|
+
name: (identifier) @method.name
|
|
85
|
+
parameters: (parameters
|
|
86
|
+
(identifier) @method.self
|
|
87
|
+
. (_)*) @method.params
|
|
88
|
+
body: (block) @method.body) @method.definition
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
# Exception handling
|
|
92
|
+
EXCEPTIONS = """
|
|
93
|
+
(try_statement
|
|
94
|
+
body: (block) @try.body
|
|
95
|
+
(except_clause
|
|
96
|
+
type: (_)? @except.type
|
|
97
|
+
name: (identifier)? @except.name
|
|
98
|
+
body: (block) @except.body)*
|
|
99
|
+
(else_clause
|
|
100
|
+
body: (block) @else.body)?
|
|
101
|
+
(finally_clause
|
|
102
|
+
body: (block) @finally.body)?) @try.statement
|
|
103
|
+
|
|
104
|
+
(raise_statement
|
|
105
|
+
(call
|
|
106
|
+
function: (identifier) @exception.name
|
|
107
|
+
arguments: (argument_list)? @exception.args)) @raise.statement
|
|
108
|
+
"""
|
|
109
|
+
|
|
110
|
+
# Comprehensions
|
|
111
|
+
COMPREHENSIONS = """
|
|
112
|
+
(list_comprehension
|
|
113
|
+
body: (_) @comprehension.body
|
|
114
|
+
(for_in_clause
|
|
115
|
+
left: (_) @comprehension.var
|
|
116
|
+
right: (_) @comprehension.iter)) @list.comprehension
|
|
117
|
+
|
|
118
|
+
(dictionary_comprehension
|
|
119
|
+
body: (pair
|
|
120
|
+
key: (_) @comprehension.key
|
|
121
|
+
value: (_) @comprehension.value)
|
|
122
|
+
(for_in_clause
|
|
123
|
+
left: (_) @comprehension.var
|
|
124
|
+
right: (_) @comprehension.iter)) @dict.comprehension
|
|
125
|
+
|
|
126
|
+
(set_comprehension
|
|
127
|
+
body: (_) @comprehension.body
|
|
128
|
+
(for_in_clause
|
|
129
|
+
left: (_) @comprehension.var
|
|
130
|
+
right: (_) @comprehension.iter)) @set.comprehension
|
|
131
|
+
"""
|
|
132
|
+
|
|
133
|
+
# Comments and docstrings
|
|
134
|
+
COMMENTS = """
|
|
135
|
+
(comment) @comment
|
|
136
|
+
|
|
137
|
+
(expression_statement
|
|
138
|
+
(string) @docstring)
|
|
139
|
+
"""
|
|
140
|
+
|
|
141
|
+
# Type hints and annotations
|
|
142
|
+
TYPE_HINTS = """
|
|
143
|
+
(function_definition
|
|
144
|
+
parameters: (parameters
|
|
145
|
+
(typed_parameter
|
|
146
|
+
type: (_) @type.param)) @type.function_param)
|
|
147
|
+
|
|
148
|
+
(function_definition
|
|
149
|
+
return_type: (_) @type.return) @type.function_return
|
|
150
|
+
|
|
151
|
+
(assignment
|
|
152
|
+
type: (_) @type.variable) @type.variable_annotation
|
|
153
|
+
"""
|
|
154
|
+
|
|
155
|
+
# Async/await patterns
|
|
156
|
+
ASYNC_PATTERNS = """
|
|
157
|
+
(function_definition) @async.function
|
|
158
|
+
|
|
159
|
+
(await
|
|
160
|
+
(call) @async.await_call) @async.await
|
|
161
|
+
|
|
162
|
+
(async_for_statement) @async.for
|
|
163
|
+
|
|
164
|
+
(async_with_statement) @async.with
|
|
165
|
+
"""
|
|
166
|
+
|
|
167
|
+
# F-strings and string formatting
|
|
168
|
+
STRING_FORMATTING = """
|
|
169
|
+
(formatted_string
|
|
170
|
+
(interpolation) @string.interpolation) @string.fstring
|
|
171
|
+
|
|
172
|
+
(call
|
|
173
|
+
function: (attribute
|
|
174
|
+
object: (_)
|
|
175
|
+
attribute: (identifier) @string.format_method))
|
|
176
|
+
"""
|
|
177
|
+
|
|
178
|
+
# Context managers
|
|
179
|
+
CONTEXT_MANAGERS = """
|
|
180
|
+
(with_statement
|
|
181
|
+
(with_clause
|
|
182
|
+
(with_item
|
|
183
|
+
value: (_) @context.manager)) @context.clause) @context.with
|
|
184
|
+
|
|
185
|
+
(async_with_statement
|
|
186
|
+
(with_clause
|
|
187
|
+
(with_item
|
|
188
|
+
value: (_) @context.manager)) @context.clause) @context.async_with
|
|
189
|
+
"""
|
|
190
|
+
|
|
191
|
+
# Lambda expressions
|
|
192
|
+
LAMBDAS = """
|
|
193
|
+
(lambda
|
|
194
|
+
parameters: (lambda_parameters)? @lambda.params
|
|
195
|
+
body: (_) @lambda.body) @lambda.expression
|
|
196
|
+
"""
|
|
197
|
+
|
|
198
|
+
# Modern Python patterns
|
|
199
|
+
MODERN_PATTERNS = """
|
|
200
|
+
(match_statement
|
|
201
|
+
subject: (_) @match.subject
|
|
202
|
+
body: (case_clause)+ @match.cases) @pattern.match
|
|
203
|
+
|
|
204
|
+
(case_clause
|
|
205
|
+
pattern: (_) @case.pattern
|
|
206
|
+
guard: (_)? @case.guard
|
|
207
|
+
consequence: (block) @case.body) @pattern.case
|
|
208
|
+
|
|
209
|
+
(walrus_operator
|
|
210
|
+
left: (_) @walrus.target
|
|
211
|
+
right: (_) @walrus.value) @assignment.walrus
|
|
212
|
+
"""
|
|
213
|
+
|
|
214
|
+
# Python-specific comprehensive query library
|
|
215
|
+
PYTHON_QUERIES: dict[str, str] = {
|
|
216
|
+
# --- Basic Structure ---
|
|
217
|
+
"function": """
|
|
218
|
+
(function_definition) @function
|
|
219
|
+
""",
|
|
220
|
+
"function_definition": """
|
|
221
|
+
(function_definition
|
|
222
|
+
name: (identifier) @function_name
|
|
223
|
+
parameters: (parameters) @parameters
|
|
224
|
+
body: (block) @body) @function_definition
|
|
225
|
+
""",
|
|
226
|
+
"async_function": """
|
|
227
|
+
(function_definition
|
|
228
|
+
"async" @async_keyword
|
|
229
|
+
name: (identifier) @function_name
|
|
230
|
+
parameters: (parameters) @parameters
|
|
231
|
+
body: (block) @body) @async_function
|
|
232
|
+
""",
|
|
233
|
+
"method": """
|
|
234
|
+
(function_definition
|
|
235
|
+
name: (identifier) @method_name
|
|
236
|
+
parameters: (parameters
|
|
237
|
+
(identifier) @self_param
|
|
238
|
+
. (_)*) @method_params
|
|
239
|
+
body: (block) @method_body) @method_definition
|
|
240
|
+
""",
|
|
241
|
+
"lambda": """
|
|
242
|
+
(lambda
|
|
243
|
+
parameters: (lambda_parameters)? @lambda_params
|
|
244
|
+
body: (_) @lambda_body) @lambda_expression
|
|
245
|
+
""",
|
|
246
|
+
# --- Classes ---
|
|
247
|
+
"class": """
|
|
248
|
+
(class_definition) @class
|
|
249
|
+
""",
|
|
250
|
+
"class_definition": """
|
|
251
|
+
(class_definition
|
|
252
|
+
name: (identifier) @class_name
|
|
253
|
+
superclasses: (argument_list)? @superclasses
|
|
254
|
+
body: (block) @body) @class_definition
|
|
255
|
+
""",
|
|
256
|
+
"class_method": """
|
|
257
|
+
(class_definition
|
|
258
|
+
body: (block
|
|
259
|
+
(function_definition
|
|
260
|
+
name: (identifier) @method_name
|
|
261
|
+
parameters: (parameters) @parameters
|
|
262
|
+
body: (block) @method_body))) @class_method
|
|
263
|
+
""",
|
|
264
|
+
"constructor": """
|
|
265
|
+
(function_definition
|
|
266
|
+
name: (identifier) @constructor_name
|
|
267
|
+
(#match? @constructor_name "__init__")
|
|
268
|
+
parameters: (parameters) @parameters
|
|
269
|
+
body: (block) @body) @constructor
|
|
270
|
+
""",
|
|
271
|
+
"property": """
|
|
272
|
+
(decorated_definition
|
|
273
|
+
(decorator
|
|
274
|
+
(identifier) @decorator_name
|
|
275
|
+
(#match? @decorator_name "property"))
|
|
276
|
+
(function_definition
|
|
277
|
+
name: (identifier) @property_name)) @property_definition
|
|
278
|
+
""",
|
|
279
|
+
"staticmethod": """
|
|
280
|
+
(decorated_definition
|
|
281
|
+
(decorator
|
|
282
|
+
(identifier) @decorator_name
|
|
283
|
+
(#match? @decorator_name "staticmethod"))
|
|
284
|
+
(function_definition
|
|
285
|
+
name: (identifier) @method_name)) @static_method
|
|
286
|
+
""",
|
|
287
|
+
"classmethod": """
|
|
288
|
+
(decorated_definition
|
|
289
|
+
(decorator
|
|
290
|
+
(identifier) @decorator_name
|
|
291
|
+
(#match? @decorator_name "classmethod"))
|
|
292
|
+
(function_definition
|
|
293
|
+
name: (identifier) @method_name)) @class_method_decorator
|
|
294
|
+
""",
|
|
295
|
+
# --- Variables and Assignments ---
|
|
296
|
+
"variable": """
|
|
297
|
+
(assignment) @variable
|
|
298
|
+
""",
|
|
299
|
+
"assignment": """
|
|
300
|
+
(assignment
|
|
301
|
+
left: (identifier) @variable_name
|
|
302
|
+
right: (_) @value) @assignment
|
|
303
|
+
""",
|
|
304
|
+
"multiple_assignment": """
|
|
305
|
+
(assignment
|
|
306
|
+
left: (pattern_list) @variables
|
|
307
|
+
right: (_) @value) @multiple_assignment
|
|
308
|
+
""",
|
|
309
|
+
"augmented_assignment": """
|
|
310
|
+
(augmented_assignment
|
|
311
|
+
left: (identifier) @variable_name
|
|
312
|
+
right: (_) @value) @augmented_assignment
|
|
313
|
+
""",
|
|
314
|
+
"global_statement": """
|
|
315
|
+
(global_statement
|
|
316
|
+
(identifier) @global_var) @global_declaration
|
|
317
|
+
""",
|
|
318
|
+
"nonlocal_statement": """
|
|
319
|
+
(nonlocal_statement
|
|
320
|
+
(identifier) @nonlocal_var) @nonlocal_declaration
|
|
321
|
+
""",
|
|
322
|
+
# --- Imports ---
|
|
323
|
+
"import": """
|
|
324
|
+
(import_statement) @import
|
|
325
|
+
""",
|
|
326
|
+
"import_statement": """
|
|
327
|
+
(import_statement
|
|
328
|
+
name: (dotted_name) @import_name) @import_statement
|
|
329
|
+
""",
|
|
330
|
+
"import_from": """
|
|
331
|
+
(import_from_statement
|
|
332
|
+
module_name: (dotted_name)? @module_name
|
|
333
|
+
name: (dotted_name) @import_name) @import_from
|
|
334
|
+
""",
|
|
335
|
+
"import_from_list": """
|
|
336
|
+
(import_from_statement
|
|
337
|
+
module_name: (dotted_name)? @module_name
|
|
338
|
+
name: (aliased_import) @import_item) @import_from_list
|
|
339
|
+
""",
|
|
340
|
+
"aliased_import": """
|
|
341
|
+
(aliased_import
|
|
342
|
+
name: (dotted_name) @import_name
|
|
343
|
+
alias: (identifier) @alias) @aliased_import
|
|
344
|
+
""",
|
|
345
|
+
"import_star": """
|
|
346
|
+
(import_from_statement
|
|
347
|
+
module_name: (dotted_name) @module_name
|
|
348
|
+
name: (wildcard_import) @star_import) @import_star
|
|
349
|
+
""",
|
|
350
|
+
# --- Decorators ---
|
|
351
|
+
"decorator": """
|
|
352
|
+
(decorator) @decorator
|
|
353
|
+
""",
|
|
354
|
+
"decorator_simple": """
|
|
355
|
+
(decorator
|
|
356
|
+
(identifier) @decorator_name) @decorator_simple
|
|
357
|
+
""",
|
|
358
|
+
"decorator_call": """
|
|
359
|
+
(decorator
|
|
360
|
+
(call
|
|
361
|
+
function: (identifier) @decorator_name
|
|
362
|
+
arguments: (argument_list) @decorator_args)) @decorator_call
|
|
363
|
+
""",
|
|
364
|
+
"decorator_attribute": """
|
|
365
|
+
(decorator
|
|
366
|
+
(attribute
|
|
367
|
+
object: (identifier) @decorator_object
|
|
368
|
+
attribute: (identifier) @decorator_name)) @decorator_attribute
|
|
369
|
+
""",
|
|
370
|
+
"decorated_function": """
|
|
371
|
+
(decorated_definition
|
|
372
|
+
(decorator)+ @decorators
|
|
373
|
+
(function_definition
|
|
374
|
+
name: (identifier) @function_name)) @decorated_function
|
|
375
|
+
""",
|
|
376
|
+
"decorated_class": """
|
|
377
|
+
(decorated_definition
|
|
378
|
+
(decorator)+ @decorators
|
|
379
|
+
(class_definition
|
|
380
|
+
name: (identifier) @class_name)) @decorated_class
|
|
381
|
+
""",
|
|
382
|
+
# --- Control Flow ---
|
|
383
|
+
"if_statement": """
|
|
384
|
+
(if_statement
|
|
385
|
+
condition: (_) @condition
|
|
386
|
+
consequence: (block) @then_branch
|
|
387
|
+
alternative: (_)? @else_branch) @if_statement
|
|
388
|
+
""",
|
|
389
|
+
"for_statement": """
|
|
390
|
+
(for_statement
|
|
391
|
+
left: (_) @loop_var
|
|
392
|
+
right: (_) @iterable
|
|
393
|
+
body: (block) @body) @for_statement
|
|
394
|
+
""",
|
|
395
|
+
"while_statement": """
|
|
396
|
+
(while_statement
|
|
397
|
+
condition: (_) @condition
|
|
398
|
+
body: (block) @body) @while_statement
|
|
399
|
+
""",
|
|
400
|
+
"with_statement": """
|
|
401
|
+
(with_statement
|
|
402
|
+
(with_clause
|
|
403
|
+
(with_item
|
|
404
|
+
value: (_) @context_manager)) @with_clause
|
|
405
|
+
body: (block) @body) @with_statement
|
|
406
|
+
""",
|
|
407
|
+
"async_with": """
|
|
408
|
+
(async_with_statement
|
|
409
|
+
(with_clause
|
|
410
|
+
(with_item
|
|
411
|
+
value: (_) @context_manager)) @with_clause
|
|
412
|
+
body: (block) @body) @async_with_statement
|
|
413
|
+
""",
|
|
414
|
+
"async_for": """
|
|
415
|
+
(async_for_statement
|
|
416
|
+
left: (_) @loop_var
|
|
417
|
+
right: (_) @async_iterable
|
|
418
|
+
body: (block) @body) @async_for_statement
|
|
419
|
+
""",
|
|
420
|
+
# --- Exception Handling ---
|
|
421
|
+
"try_statement": """
|
|
422
|
+
(try_statement
|
|
423
|
+
body: (block) @try_body
|
|
424
|
+
(except_clause)* @except_clauses
|
|
425
|
+
(else_clause)? @else_clause
|
|
426
|
+
(finally_clause)? @finally_clause) @try_statement
|
|
427
|
+
""",
|
|
428
|
+
"except_clause": """
|
|
429
|
+
(except_clause
|
|
430
|
+
type: (_)? @exception_type
|
|
431
|
+
name: (identifier)? @exception_name
|
|
432
|
+
body: (block) @except_body) @except_clause
|
|
433
|
+
""",
|
|
434
|
+
"raise_statement": """
|
|
435
|
+
(raise_statement
|
|
436
|
+
(call
|
|
437
|
+
function: (identifier) @exception_name
|
|
438
|
+
arguments: (argument_list)? @exception_args)) @raise_statement
|
|
439
|
+
""",
|
|
440
|
+
"assert_statement": """
|
|
441
|
+
(assert_statement
|
|
442
|
+
(_) @assertion
|
|
443
|
+
(_)? @message) @assert_statement
|
|
444
|
+
""",
|
|
445
|
+
# --- Comprehensions ---
|
|
446
|
+
"list_comprehension": """
|
|
447
|
+
(list_comprehension
|
|
448
|
+
body: (_) @comprehension_body
|
|
449
|
+
(for_in_clause
|
|
450
|
+
left: (_) @comprehension_var
|
|
451
|
+
right: (_) @comprehension_iter)) @list_comprehension
|
|
452
|
+
""",
|
|
453
|
+
"dict_comprehension": """
|
|
454
|
+
(dictionary_comprehension
|
|
455
|
+
body: (pair
|
|
456
|
+
key: (_) @comprehension_key
|
|
457
|
+
value: (_) @comprehension_value)
|
|
458
|
+
(for_in_clause
|
|
459
|
+
left: (_) @comprehension_var
|
|
460
|
+
right: (_) @comprehension_iter)) @dict_comprehension
|
|
461
|
+
""",
|
|
462
|
+
"set_comprehension": """
|
|
463
|
+
(set_comprehension
|
|
464
|
+
body: (_) @comprehension_body
|
|
465
|
+
(for_in_clause
|
|
466
|
+
left: (_) @comprehension_var
|
|
467
|
+
right: (_) @comprehension_iter)) @set_comprehension
|
|
468
|
+
""",
|
|
469
|
+
"generator_expression": """
|
|
470
|
+
(generator_expression
|
|
471
|
+
body: (_) @generator_body
|
|
472
|
+
(for_in_clause
|
|
473
|
+
left: (_) @generator_var
|
|
474
|
+
right: (_) @generator_iter)) @generator_expression
|
|
475
|
+
""",
|
|
476
|
+
# --- Type Hints and Annotations ---
|
|
477
|
+
"type_hint": """
|
|
478
|
+
(typed_parameter
|
|
479
|
+
type: (_) @parameter_type) @typed_parameter
|
|
480
|
+
""",
|
|
481
|
+
"return_type": """
|
|
482
|
+
(function_definition
|
|
483
|
+
return_type: (_) @return_type) @function_with_return_type
|
|
484
|
+
""",
|
|
485
|
+
"variable_annotation": """
|
|
486
|
+
(assignment
|
|
487
|
+
type: (_) @variable_type) @annotated_assignment
|
|
488
|
+
""",
|
|
489
|
+
"type_alias": """
|
|
490
|
+
(type_alias_statement
|
|
491
|
+
name: (identifier) @alias_name
|
|
492
|
+
value: (_) @alias_type) @type_alias
|
|
493
|
+
""",
|
|
494
|
+
# --- Modern Python Features ---
|
|
495
|
+
"match_statement": """
|
|
496
|
+
(match_statement
|
|
497
|
+
subject: (_) @match_subject
|
|
498
|
+
body: (case_clause)+ @match_cases) @match_statement
|
|
499
|
+
""",
|
|
500
|
+
"case_clause": """
|
|
501
|
+
(case_clause
|
|
502
|
+
pattern: (_) @case_pattern
|
|
503
|
+
guard: (_)? @case_guard
|
|
504
|
+
consequence: (block) @case_body) @case_clause
|
|
505
|
+
""",
|
|
506
|
+
"walrus_operator": """
|
|
507
|
+
(named_expression
|
|
508
|
+
name: (identifier) @walrus_target
|
|
509
|
+
value: (_) @walrus_value) @walrus_operator
|
|
510
|
+
""",
|
|
511
|
+
"f_string": """
|
|
512
|
+
(formatted_string
|
|
513
|
+
(interpolation) @f_string_interpolation) @f_string
|
|
514
|
+
""",
|
|
515
|
+
"yield_expression": """
|
|
516
|
+
(yield
|
|
517
|
+
(_)? @yielded_value) @yield_expression
|
|
518
|
+
""",
|
|
519
|
+
"yield_from": """
|
|
520
|
+
(yield
|
|
521
|
+
"from" @yield_from_keyword
|
|
522
|
+
(_) @yielded_iterable) @yield_from_expression
|
|
523
|
+
""",
|
|
524
|
+
"await_expression": """
|
|
525
|
+
(await
|
|
526
|
+
(_) @awaited_expression) @await_expression
|
|
527
|
+
""",
|
|
528
|
+
# --- Comments and Docstrings ---
|
|
529
|
+
"comment": """
|
|
530
|
+
(comment) @comment
|
|
531
|
+
""",
|
|
532
|
+
"docstring": """
|
|
533
|
+
(expression_statement
|
|
534
|
+
(string) @docstring)
|
|
535
|
+
""",
|
|
536
|
+
"module_docstring": """
|
|
537
|
+
(module
|
|
538
|
+
(expression_statement
|
|
539
|
+
(string) @module_docstring))
|
|
540
|
+
""",
|
|
541
|
+
# --- Framework-specific Patterns ---
|
|
542
|
+
"django_model": """
|
|
543
|
+
(class_definition
|
|
544
|
+
name: (identifier) @model_name
|
|
545
|
+
superclasses: (argument_list
|
|
546
|
+
(identifier) @superclass
|
|
547
|
+
(#match? @superclass "Model|models.Model"))
|
|
548
|
+
body: (block) @model_body) @django_model
|
|
549
|
+
""",
|
|
550
|
+
"django_view": """
|
|
551
|
+
(class_definition
|
|
552
|
+
name: (identifier) @view_name
|
|
553
|
+
superclasses: (argument_list
|
|
554
|
+
(identifier) @superclass
|
|
555
|
+
(#match? @superclass "View|TemplateView|ListView|DetailView"))
|
|
556
|
+
body: (block) @view_body) @django_view
|
|
557
|
+
""",
|
|
558
|
+
"flask_route": """
|
|
559
|
+
(decorated_definition
|
|
560
|
+
(decorator
|
|
561
|
+
(call
|
|
562
|
+
function: (attribute
|
|
563
|
+
object: (identifier) @app_object
|
|
564
|
+
attribute: (identifier) @route_decorator
|
|
565
|
+
(#match? @route_decorator "route"))
|
|
566
|
+
arguments: (argument_list
|
|
567
|
+
(string) @route_path))) @flask_route_decorator
|
|
568
|
+
(function_definition
|
|
569
|
+
name: (identifier) @handler_name)) @flask_route
|
|
570
|
+
""",
|
|
571
|
+
"fastapi_endpoint": """
|
|
572
|
+
(decorated_definition
|
|
573
|
+
(decorator
|
|
574
|
+
(call
|
|
575
|
+
function: (attribute
|
|
576
|
+
object: (identifier) @app_object
|
|
577
|
+
attribute: (identifier) @http_method
|
|
578
|
+
(#match? @http_method "get|post|put|delete|patch"))
|
|
579
|
+
arguments: (argument_list
|
|
580
|
+
(string) @endpoint_path))) @fastapi_decorator
|
|
581
|
+
(function_definition
|
|
582
|
+
name: (identifier) @endpoint_name)) @fastapi_endpoint
|
|
583
|
+
""",
|
|
584
|
+
"dataclass": """
|
|
585
|
+
(decorated_definition
|
|
586
|
+
(decorator
|
|
587
|
+
(identifier) @decorator_name
|
|
588
|
+
(#match? @decorator_name "dataclass"))
|
|
589
|
+
(class_definition
|
|
590
|
+
name: (identifier) @dataclass_name)) @dataclass_definition
|
|
591
|
+
""",
|
|
592
|
+
# --- Name-only Extraction ---
|
|
593
|
+
"function_name": """
|
|
594
|
+
(function_definition
|
|
595
|
+
name: (identifier) @function_name)
|
|
596
|
+
""",
|
|
597
|
+
"class_name": """
|
|
598
|
+
(class_definition
|
|
599
|
+
name: (identifier) @class_name)
|
|
600
|
+
""",
|
|
601
|
+
"variable_name": """
|
|
602
|
+
(assignment
|
|
603
|
+
left: (identifier) @variable_name)
|
|
604
|
+
""",
|
|
605
|
+
# --- Advanced Patterns ---
|
|
606
|
+
"context_manager": """
|
|
607
|
+
(class_definition
|
|
608
|
+
body: (block
|
|
609
|
+
(function_definition
|
|
610
|
+
name: (identifier) @enter_method
|
|
611
|
+
(#match? @enter_method "__enter__"))
|
|
612
|
+
(function_definition
|
|
613
|
+
name: (identifier) @exit_method
|
|
614
|
+
(#match? @exit_method "__exit__")))) @context_manager_class
|
|
615
|
+
""",
|
|
616
|
+
"iterator": """
|
|
617
|
+
(class_definition
|
|
618
|
+
body: (block
|
|
619
|
+
(function_definition
|
|
620
|
+
name: (identifier) @iter_method
|
|
621
|
+
(#match? @iter_method "__iter__"))
|
|
622
|
+
(function_definition
|
|
623
|
+
name: (identifier) @next_method
|
|
624
|
+
(#match? @next_method "__next__")))) @iterator_class
|
|
625
|
+
""",
|
|
626
|
+
"metaclass": """
|
|
627
|
+
(class_definition
|
|
628
|
+
name: (identifier) @metaclass_name
|
|
629
|
+
superclasses: (argument_list
|
|
630
|
+
(identifier) @superclass
|
|
631
|
+
(#match? @superclass "type"))
|
|
632
|
+
body: (block) @metaclass_body) @metaclass_definition
|
|
633
|
+
""",
|
|
634
|
+
"abstract_method": """
|
|
635
|
+
(decorated_definition
|
|
636
|
+
(decorator
|
|
637
|
+
(identifier) @decorator_name
|
|
638
|
+
(#match? @decorator_name "abstractmethod"))
|
|
639
|
+
(function_definition
|
|
640
|
+
name: (identifier) @abstract_method_name)) @abstract_method
|
|
641
|
+
""",
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
# Query descriptions
|
|
645
|
+
PYTHON_QUERY_DESCRIPTIONS: dict[str, str] = {
|
|
646
|
+
"function": "Search Python function definitions",
|
|
647
|
+
"function_definition": "Search function definitions with details",
|
|
648
|
+
"async_function": "Search async function definitions",
|
|
649
|
+
"method": "Search method definitions within classes",
|
|
650
|
+
"lambda": "Search lambda expressions",
|
|
651
|
+
"class": "Search Python class definitions",
|
|
652
|
+
"class_definition": "Search class definitions with details",
|
|
653
|
+
"class_method": "Search class methods",
|
|
654
|
+
"constructor": "Search class constructors (__init__)",
|
|
655
|
+
"property": "Search property decorators",
|
|
656
|
+
"staticmethod": "Search static methods",
|
|
657
|
+
"classmethod": "Search class methods",
|
|
658
|
+
"variable": "Search variable assignments",
|
|
659
|
+
"assignment": "Search variable assignments",
|
|
660
|
+
"multiple_assignment": "Search multiple variable assignments",
|
|
661
|
+
"augmented_assignment": "Search augmented assignments (+=, -=, etc.)",
|
|
662
|
+
"global_statement": "Search global variable declarations",
|
|
663
|
+
"nonlocal_statement": "Search nonlocal variable declarations",
|
|
664
|
+
"import": "Search import statements",
|
|
665
|
+
"import_statement": "Search import statements with details",
|
|
666
|
+
"import_from": "Search from-import statements",
|
|
667
|
+
"import_from_list": "Search from-import with multiple names",
|
|
668
|
+
"aliased_import": "Search aliased imports (as keyword)",
|
|
669
|
+
"import_star": "Search star imports (from module import *)",
|
|
670
|
+
"decorator": "Search all decorators",
|
|
671
|
+
"decorator_simple": "Search simple decorators",
|
|
672
|
+
"decorator_call": "Search decorator calls with arguments",
|
|
673
|
+
"decorator_attribute": "Search attribute decorators",
|
|
674
|
+
"decorated_function": "Search decorated functions",
|
|
675
|
+
"decorated_class": "Search decorated classes",
|
|
676
|
+
"if_statement": "Search if statements",
|
|
677
|
+
"for_statement": "Search for loops",
|
|
678
|
+
"while_statement": "Search while loops",
|
|
679
|
+
"with_statement": "Search with statements (context managers)",
|
|
680
|
+
"async_with": "Search async with statements",
|
|
681
|
+
"async_for": "Search async for loops",
|
|
682
|
+
"try_statement": "Search try-except statements",
|
|
683
|
+
"except_clause": "Search except clauses",
|
|
684
|
+
"raise_statement": "Search raise statements",
|
|
685
|
+
"assert_statement": "Search assert statements",
|
|
686
|
+
"list_comprehension": "Search list comprehensions",
|
|
687
|
+
"dict_comprehension": "Search dictionary comprehensions",
|
|
688
|
+
"set_comprehension": "Search set comprehensions",
|
|
689
|
+
"generator_expression": "Search generator expressions",
|
|
690
|
+
"type_hint": "Search type hints on parameters",
|
|
691
|
+
"return_type": "Search function return type annotations",
|
|
692
|
+
"variable_annotation": "Search variable type annotations",
|
|
693
|
+
"type_alias": "Search type alias statements",
|
|
694
|
+
"match_statement": "Search match statements (Python 3.10+)",
|
|
695
|
+
"case_clause": "Search case clauses in match statements",
|
|
696
|
+
"walrus_operator": "Search walrus operator (:=)",
|
|
697
|
+
"f_string": "Search f-string literals",
|
|
698
|
+
"yield_expression": "Search yield expressions",
|
|
699
|
+
"yield_from": "Search yield from expressions",
|
|
700
|
+
"await_expression": "Search await expressions",
|
|
701
|
+
"comment": "Search all comments",
|
|
702
|
+
"docstring": "Search docstrings",
|
|
703
|
+
"module_docstring": "Search module-level docstrings",
|
|
704
|
+
"django_model": "Search Django model classes",
|
|
705
|
+
"django_view": "Search Django view classes",
|
|
706
|
+
"flask_route": "Search Flask route decorators",
|
|
707
|
+
"fastapi_endpoint": "Search FastAPI endpoint decorators",
|
|
708
|
+
"dataclass": "Search dataclass definitions",
|
|
709
|
+
"function_name": "Search function names only",
|
|
710
|
+
"class_name": "Search class names only",
|
|
711
|
+
"variable_name": "Search variable names only",
|
|
712
|
+
"context_manager": "Search context manager classes",
|
|
713
|
+
"iterator": "Search iterator classes",
|
|
714
|
+
"metaclass": "Search metaclass definitions",
|
|
715
|
+
"abstract_method": "Search abstract methods",
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
# Convert to ALL_QUERIES format for dynamic loader compatibility
|
|
719
|
+
ALL_QUERIES = {}
|
|
720
|
+
for query_name, query_string in PYTHON_QUERIES.items():
|
|
721
|
+
description = PYTHON_QUERY_DESCRIPTIONS.get(query_name, "No description")
|
|
722
|
+
ALL_QUERIES[query_name] = {"query": query_string, "description": description}
|
|
723
|
+
|
|
724
|
+
# Add legacy queries for backward compatibility
|
|
725
|
+
ALL_QUERIES["functions"] = {
|
|
726
|
+
"query": FUNCTIONS,
|
|
727
|
+
"description": "Search all function definitions (including async)",
|
|
728
|
+
}
|
|
729
|
+
ALL_QUERIES["classes"] = {
|
|
730
|
+
"query": CLASSES,
|
|
731
|
+
"description": "Search all class definitions",
|
|
732
|
+
}
|
|
733
|
+
ALL_QUERIES["imports"] = {
|
|
734
|
+
"query": IMPORTS,
|
|
735
|
+
"description": "Search all import statements",
|
|
736
|
+
}
|
|
737
|
+
ALL_QUERIES["variables"] = {
|
|
738
|
+
"query": VARIABLES,
|
|
739
|
+
"description": "Search all variable assignments",
|
|
740
|
+
}
|
|
741
|
+
ALL_QUERIES["decorators"] = {
|
|
742
|
+
"query": DECORATORS,
|
|
743
|
+
"description": "Search all decorators",
|
|
744
|
+
}
|
|
745
|
+
ALL_QUERIES["methods"] = {
|
|
746
|
+
"query": METHODS,
|
|
747
|
+
"description": "Search all method definitions within classes",
|
|
748
|
+
}
|
|
749
|
+
ALL_QUERIES["exceptions"] = {
|
|
750
|
+
"query": EXCEPTIONS,
|
|
751
|
+
"description": "Search exception handling and raise statements",
|
|
752
|
+
}
|
|
753
|
+
ALL_QUERIES["comprehensions"] = {
|
|
754
|
+
"query": COMPREHENSIONS,
|
|
755
|
+
"description": "Search list, dictionary, and set comprehensions",
|
|
756
|
+
}
|
|
757
|
+
ALL_QUERIES["comments"] = {
|
|
758
|
+
"query": COMMENTS,
|
|
759
|
+
"description": "Search comments and docstrings",
|
|
760
|
+
}
|
|
761
|
+
ALL_QUERIES["type_hints"] = {
|
|
762
|
+
"query": TYPE_HINTS,
|
|
763
|
+
"description": "Search type hints and annotations",
|
|
764
|
+
}
|
|
765
|
+
ALL_QUERIES["async_patterns"] = {
|
|
766
|
+
"query": ASYNC_PATTERNS,
|
|
767
|
+
"description": "Search async/await patterns",
|
|
768
|
+
}
|
|
769
|
+
ALL_QUERIES["string_formatting"] = {
|
|
770
|
+
"query": STRING_FORMATTING,
|
|
771
|
+
"description": "Search f-strings and string formatting",
|
|
772
|
+
}
|
|
773
|
+
ALL_QUERIES["context_managers"] = {
|
|
774
|
+
"query": CONTEXT_MANAGERS,
|
|
775
|
+
"description": "Search context managers (with statements)",
|
|
776
|
+
}
|
|
777
|
+
ALL_QUERIES["lambdas"] = {"query": LAMBDAS, "description": "Search lambda expressions"}
|
|
778
|
+
ALL_QUERIES["modern_patterns"] = {
|
|
779
|
+
"query": MODERN_PATTERNS,
|
|
780
|
+
"description": "Search modern Python patterns (match/case, walrus operator)",
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
# Convenience aliases
|
|
784
|
+
ALL_QUERIES["function_names"] = {
|
|
785
|
+
"query": FUNCTIONS,
|
|
786
|
+
"description": "Function alias - search all function definitions",
|
|
787
|
+
}
|
|
788
|
+
ALL_QUERIES["class_names"] = {
|
|
789
|
+
"query": CLASSES,
|
|
790
|
+
"description": "Class alias - search all class definitions",
|
|
791
|
+
}
|
|
792
|
+
ALL_QUERIES["all_declarations"] = {
|
|
793
|
+
"query": FUNCTIONS + "\n\n" + CLASSES + "\n\n" + VARIABLES,
|
|
794
|
+
"description": "Search all function, class, and variable declarations",
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
|
|
798
|
+
def get_python_query(name: str) -> str:
|
|
799
|
+
"""
|
|
800
|
+
Get the specified Python query
|
|
801
|
+
|
|
802
|
+
Args:
|
|
803
|
+
name: Query name
|
|
804
|
+
|
|
805
|
+
Returns:
|
|
806
|
+
Query string
|
|
807
|
+
|
|
808
|
+
Raises:
|
|
809
|
+
ValueError: When query is not found
|
|
810
|
+
"""
|
|
811
|
+
if name not in PYTHON_QUERIES:
|
|
812
|
+
available = list(PYTHON_QUERIES.keys())
|
|
813
|
+
raise ValueError(
|
|
814
|
+
f"Python query '{name}' does not exist. Available: {available}"
|
|
815
|
+
)
|
|
816
|
+
|
|
817
|
+
return PYTHON_QUERIES[name]
|
|
818
|
+
|
|
819
|
+
|
|
820
|
+
def get_python_query_description(name: str) -> str:
|
|
821
|
+
"""
|
|
822
|
+
Get the description of the specified Python query
|
|
823
|
+
|
|
824
|
+
Args:
|
|
825
|
+
name: Query name
|
|
826
|
+
|
|
827
|
+
Returns:
|
|
828
|
+
Query description
|
|
829
|
+
"""
|
|
830
|
+
return PYTHON_QUERY_DESCRIPTIONS.get(name, "No description")
|
|
831
|
+
|
|
832
|
+
|
|
833
|
+
def get_query(name: str) -> str:
|
|
834
|
+
"""Get a specific query by name."""
|
|
835
|
+
if name in ALL_QUERIES:
|
|
836
|
+
return ALL_QUERIES[name]["query"]
|
|
837
|
+
raise ValueError(
|
|
838
|
+
f"Query '{name}' not found. Available queries: {list(ALL_QUERIES.keys())}"
|
|
839
|
+
)
|
|
840
|
+
|
|
841
|
+
|
|
842
|
+
def get_all_queries() -> dict:
|
|
843
|
+
"""Get all available queries."""
|
|
844
|
+
return ALL_QUERIES
|
|
845
|
+
|
|
846
|
+
|
|
847
|
+
def list_queries() -> list:
|
|
848
|
+
"""List all available query names."""
|
|
849
|
+
return list(ALL_QUERIES.keys())
|
|
850
|
+
|
|
851
|
+
|
|
852
|
+
def get_available_python_queries() -> list[str]:
|
|
853
|
+
"""
|
|
854
|
+
Get list of available Python queries
|
|
855
|
+
|
|
856
|
+
Returns:
|
|
857
|
+
List of query names
|
|
858
|
+
"""
|
|
859
|
+
return list(PYTHON_QUERIES.keys())
|