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,192 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Kotlin Language Queries
|
|
4
|
+
|
|
5
|
+
Tree-sitter queries specific to Kotlin language constructs.
|
|
6
|
+
Covers classes, functions, properties, interfaces, and other Kotlin-specific elements.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
# Kotlin-specific query library
|
|
10
|
+
KOTLIN_QUERIES: dict[str, str] = {
|
|
11
|
+
# --- Basic Structure ---
|
|
12
|
+
"package": """
|
|
13
|
+
(package_header) @package
|
|
14
|
+
""",
|
|
15
|
+
"class": """
|
|
16
|
+
(class_declaration) @class
|
|
17
|
+
""",
|
|
18
|
+
"object": """
|
|
19
|
+
(object_declaration) @object
|
|
20
|
+
""",
|
|
21
|
+
"interface": """
|
|
22
|
+
(class_declaration
|
|
23
|
+
(#match? @class "interface")) @interface
|
|
24
|
+
""",
|
|
25
|
+
# --- Functions ---
|
|
26
|
+
"function": """
|
|
27
|
+
(function_declaration) @function
|
|
28
|
+
""",
|
|
29
|
+
"lambda": """
|
|
30
|
+
(lambda_literal) @lambda
|
|
31
|
+
""",
|
|
32
|
+
# --- Properties and Variables ---
|
|
33
|
+
"property": """
|
|
34
|
+
(property_declaration) @property
|
|
35
|
+
""",
|
|
36
|
+
"val": """
|
|
37
|
+
(property_declaration
|
|
38
|
+
(#match? @property "^val")) @val
|
|
39
|
+
""",
|
|
40
|
+
"var": """
|
|
41
|
+
(property_declaration
|
|
42
|
+
(#match? @property "^var")) @var
|
|
43
|
+
""",
|
|
44
|
+
# --- Annotations ---
|
|
45
|
+
"annotation": """
|
|
46
|
+
(annotation) @annotation
|
|
47
|
+
""",
|
|
48
|
+
# --- Detailed Queries ---
|
|
49
|
+
"class_with_body": """
|
|
50
|
+
(class_declaration
|
|
51
|
+
(simple_identifier) @name
|
|
52
|
+
(class_body) @body) @class_with_body
|
|
53
|
+
""",
|
|
54
|
+
"function_with_body": """
|
|
55
|
+
(function_declaration
|
|
56
|
+
(simple_identifier) @name
|
|
57
|
+
(function_body) @body) @function_with_body
|
|
58
|
+
""",
|
|
59
|
+
# --- Modifiers ---
|
|
60
|
+
"data_class": """
|
|
61
|
+
(class_declaration
|
|
62
|
+
(modifiers "data")
|
|
63
|
+
(simple_identifier) @name) @data_class
|
|
64
|
+
""",
|
|
65
|
+
"sealed_class": """
|
|
66
|
+
(class_declaration
|
|
67
|
+
(modifiers "sealed")
|
|
68
|
+
(simple_identifier) @name) @sealed_class
|
|
69
|
+
""",
|
|
70
|
+
"suspend_function": """
|
|
71
|
+
(function_declaration
|
|
72
|
+
(modifiers "suspend")
|
|
73
|
+
(simple_identifier) @name) @suspend_function
|
|
74
|
+
""",
|
|
75
|
+
# --- Names ---
|
|
76
|
+
"class_name": """
|
|
77
|
+
(class_declaration
|
|
78
|
+
(simple_identifier) @class_name)
|
|
79
|
+
""",
|
|
80
|
+
"function_name": """
|
|
81
|
+
(function_declaration
|
|
82
|
+
(simple_identifier) @function_name)
|
|
83
|
+
""",
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
# Query descriptions
|
|
87
|
+
KOTLIN_QUERY_DESCRIPTIONS: dict[str, str] = {
|
|
88
|
+
"package": "Extract Kotlin package header",
|
|
89
|
+
"class": "Extract Kotlin class declarations",
|
|
90
|
+
"object": "Extract Kotlin object declarations",
|
|
91
|
+
"interface": "Extract Kotlin interface declarations",
|
|
92
|
+
"function": "Extract Kotlin function declarations",
|
|
93
|
+
"lambda": "Extract Kotlin lambda literals",
|
|
94
|
+
"property": "Extract Kotlin property declarations",
|
|
95
|
+
"val": "Extract Kotlin read-only properties (val)",
|
|
96
|
+
"var": "Extract Kotlin mutable properties (var)",
|
|
97
|
+
"annotation": "Extract Kotlin annotations",
|
|
98
|
+
"class_with_body": "Extract class declarations with body",
|
|
99
|
+
"function_with_body": "Extract function declarations with body",
|
|
100
|
+
"data_class": "Extract data classes",
|
|
101
|
+
"sealed_class": "Extract sealed classes",
|
|
102
|
+
"suspend_function": "Extract suspend functions",
|
|
103
|
+
"class_name": "Extract class names only",
|
|
104
|
+
"function_name": "Extract function names only",
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def get_kotlin_query(name: str) -> str:
|
|
109
|
+
"""
|
|
110
|
+
Get the specified Kotlin query
|
|
111
|
+
|
|
112
|
+
Args:
|
|
113
|
+
name: Query name
|
|
114
|
+
|
|
115
|
+
Returns:
|
|
116
|
+
Query string
|
|
117
|
+
|
|
118
|
+
Raises:
|
|
119
|
+
ValueError: When query is not found
|
|
120
|
+
"""
|
|
121
|
+
if name not in KOTLIN_QUERIES:
|
|
122
|
+
available = list(KOTLIN_QUERIES.keys())
|
|
123
|
+
raise ValueError(
|
|
124
|
+
f"Kotlin query '{name}' does not exist. Available: {available}"
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
return KOTLIN_QUERIES[name]
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def get_kotlin_query_description(name: str) -> str:
|
|
131
|
+
"""
|
|
132
|
+
Get the description of the specified Kotlin query
|
|
133
|
+
|
|
134
|
+
Args:
|
|
135
|
+
name: Query name
|
|
136
|
+
|
|
137
|
+
Returns:
|
|
138
|
+
Query description
|
|
139
|
+
"""
|
|
140
|
+
return KOTLIN_QUERY_DESCRIPTIONS.get(name, "No description")
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
# Convert to ALL_QUERIES format for dynamic loader compatibility
|
|
144
|
+
ALL_QUERIES = {}
|
|
145
|
+
for query_name, query_string in KOTLIN_QUERIES.items():
|
|
146
|
+
description = KOTLIN_QUERY_DESCRIPTIONS.get(query_name, "No description")
|
|
147
|
+
ALL_QUERIES[query_name] = {"query": query_string, "description": description}
|
|
148
|
+
|
|
149
|
+
# Add common query aliases for cross-language compatibility
|
|
150
|
+
ALL_QUERIES["functions"] = {
|
|
151
|
+
"query": KOTLIN_QUERIES["function"],
|
|
152
|
+
"description": "Search all function declarations (alias for function)",
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
ALL_QUERIES["methods"] = {
|
|
156
|
+
"query": KOTLIN_QUERIES["function"],
|
|
157
|
+
"description": "Search all function declarations (alias for function)",
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
ALL_QUERIES["classes"] = {
|
|
161
|
+
"query": KOTLIN_QUERIES["class"],
|
|
162
|
+
"description": "Search all class declarations (alias for class)",
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def get_query(name: str) -> str:
|
|
167
|
+
"""Get a specific query by name."""
|
|
168
|
+
if name in ALL_QUERIES:
|
|
169
|
+
return ALL_QUERIES[name]["query"]
|
|
170
|
+
raise ValueError(
|
|
171
|
+
f"Query '{name}' not found. Available queries: {list(ALL_QUERIES.keys())}"
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def get_all_queries() -> dict:
|
|
176
|
+
"""Get all available queries."""
|
|
177
|
+
return ALL_QUERIES
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def list_queries() -> list:
|
|
181
|
+
"""List all available query names."""
|
|
182
|
+
return list(ALL_QUERIES.keys())
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def get_available_kotlin_queries() -> list[str]:
|
|
186
|
+
"""
|
|
187
|
+
Get list of available Kotlin queries
|
|
188
|
+
|
|
189
|
+
Returns:
|
|
190
|
+
List of query names
|
|
191
|
+
"""
|
|
192
|
+
return list(KOTLIN_QUERIES.keys())
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Markdown Query Definitions
|
|
4
|
+
|
|
5
|
+
Tree-sitter queries for extracting Markdown elements including headers,
|
|
6
|
+
links, code blocks, lists, and other structural elements.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
# Markdown element extraction queries - simplified for compatibility
|
|
10
|
+
MARKDOWN_QUERIES: dict[str, str] = {
|
|
11
|
+
# Headers (H1-H6) - simplified
|
|
12
|
+
"headers": """
|
|
13
|
+
(atx_heading) @header
|
|
14
|
+
(setext_heading) @header
|
|
15
|
+
""",
|
|
16
|
+
# Code blocks - simplified
|
|
17
|
+
"code_blocks": """
|
|
18
|
+
(fenced_code_block) @code_block
|
|
19
|
+
(indented_code_block) @code_block
|
|
20
|
+
""",
|
|
21
|
+
# Inline code - simplified
|
|
22
|
+
"inline_code": """
|
|
23
|
+
(inline) @inline
|
|
24
|
+
""",
|
|
25
|
+
# Links - simplified to avoid invalid node types
|
|
26
|
+
"links": """
|
|
27
|
+
(inline) @inline
|
|
28
|
+
""",
|
|
29
|
+
# Images - simplified to avoid invalid node types
|
|
30
|
+
"images": """
|
|
31
|
+
(inline) @inline
|
|
32
|
+
""",
|
|
33
|
+
# Lists - simplified to avoid invalid node types
|
|
34
|
+
"lists": """
|
|
35
|
+
(list) @list
|
|
36
|
+
(list_item) @list_item
|
|
37
|
+
""",
|
|
38
|
+
# Emphasis and strong - simplified
|
|
39
|
+
"emphasis": """
|
|
40
|
+
(inline) @inline
|
|
41
|
+
""",
|
|
42
|
+
# Blockquotes - simplified
|
|
43
|
+
"blockquotes": """
|
|
44
|
+
(block_quote) @blockquote
|
|
45
|
+
""",
|
|
46
|
+
# Tables - simplified
|
|
47
|
+
"tables": """
|
|
48
|
+
(pipe_table) @table
|
|
49
|
+
""",
|
|
50
|
+
# Horizontal rules - simplified
|
|
51
|
+
"horizontal_rules": """
|
|
52
|
+
(thematic_break) @hr
|
|
53
|
+
""",
|
|
54
|
+
# HTML blocks - simplified
|
|
55
|
+
"html_blocks": """
|
|
56
|
+
(html_block) @html_block
|
|
57
|
+
""",
|
|
58
|
+
# Inline HTML - simplified
|
|
59
|
+
"inline_html": """
|
|
60
|
+
(inline) @inline
|
|
61
|
+
""",
|
|
62
|
+
# Strikethrough - simplified
|
|
63
|
+
"strikethrough": """
|
|
64
|
+
(inline) @inline
|
|
65
|
+
""",
|
|
66
|
+
# Task lists - simplified
|
|
67
|
+
"task_lists": """
|
|
68
|
+
(list_item) @list_item
|
|
69
|
+
""",
|
|
70
|
+
# Footnotes - simplified
|
|
71
|
+
"footnotes": """
|
|
72
|
+
(paragraph) @paragraph
|
|
73
|
+
(inline) @inline
|
|
74
|
+
""",
|
|
75
|
+
# All text content - simplified
|
|
76
|
+
"text_content": """
|
|
77
|
+
(paragraph) @paragraph
|
|
78
|
+
(inline) @inline
|
|
79
|
+
""",
|
|
80
|
+
# Document structure - simplified
|
|
81
|
+
"document": """
|
|
82
|
+
(document) @document
|
|
83
|
+
""",
|
|
84
|
+
# All elements (comprehensive) - simplified
|
|
85
|
+
"all_elements": """
|
|
86
|
+
(atx_heading) @heading
|
|
87
|
+
(setext_heading) @heading
|
|
88
|
+
(fenced_code_block) @code_block
|
|
89
|
+
(indented_code_block) @code_block
|
|
90
|
+
(inline) @inline
|
|
91
|
+
(list) @list
|
|
92
|
+
(list_item) @list_item
|
|
93
|
+
(block_quote) @blockquote
|
|
94
|
+
(pipe_table) @table
|
|
95
|
+
(thematic_break) @hr
|
|
96
|
+
(html_block) @html_block
|
|
97
|
+
(paragraph) @paragraph
|
|
98
|
+
(link_reference_definition) @reference
|
|
99
|
+
""",
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
# Query aliases for convenience
|
|
103
|
+
QUERY_ALIASES: dict[str, str] = {
|
|
104
|
+
"heading": "headers",
|
|
105
|
+
"h1": "headers",
|
|
106
|
+
"h2": "headers",
|
|
107
|
+
"h3": "headers",
|
|
108
|
+
"h4": "headers",
|
|
109
|
+
"h5": "headers",
|
|
110
|
+
"h6": "headers",
|
|
111
|
+
"code": "code_blocks",
|
|
112
|
+
"fenced_code": "code_blocks",
|
|
113
|
+
"code_span": "inline_code",
|
|
114
|
+
"link": "links",
|
|
115
|
+
"url": "links",
|
|
116
|
+
"image": "images",
|
|
117
|
+
"img": "images",
|
|
118
|
+
"list": "lists",
|
|
119
|
+
"ul": "lists",
|
|
120
|
+
"ol": "lists",
|
|
121
|
+
"em": "emphasis",
|
|
122
|
+
"strong": "emphasis",
|
|
123
|
+
"bold": "emphasis",
|
|
124
|
+
"italic": "emphasis",
|
|
125
|
+
"quote": "blockquotes",
|
|
126
|
+
"blockquote": "blockquotes",
|
|
127
|
+
"table": "tables",
|
|
128
|
+
"hr": "horizontal_rules",
|
|
129
|
+
"html": "html_blocks",
|
|
130
|
+
"strike": "strikethrough",
|
|
131
|
+
"task": "task_lists",
|
|
132
|
+
"todo": "task_lists",
|
|
133
|
+
"footnote": "footnotes",
|
|
134
|
+
"note": "footnotes",
|
|
135
|
+
"text": "text_content",
|
|
136
|
+
"paragraph": "text_content",
|
|
137
|
+
"all": "all_elements",
|
|
138
|
+
"everything": "all_elements",
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def get_query(query_name: str) -> str:
|
|
143
|
+
"""
|
|
144
|
+
Get a query by name, supporting aliases
|
|
145
|
+
|
|
146
|
+
Args:
|
|
147
|
+
query_name: Name of the query or alias
|
|
148
|
+
|
|
149
|
+
Returns:
|
|
150
|
+
Query string
|
|
151
|
+
|
|
152
|
+
Raises:
|
|
153
|
+
KeyError: If query name is not found
|
|
154
|
+
"""
|
|
155
|
+
# Check direct queries first
|
|
156
|
+
if query_name in MARKDOWN_QUERIES:
|
|
157
|
+
return MARKDOWN_QUERIES[query_name]
|
|
158
|
+
|
|
159
|
+
# Check aliases
|
|
160
|
+
if query_name in QUERY_ALIASES:
|
|
161
|
+
actual_query = QUERY_ALIASES[query_name]
|
|
162
|
+
return MARKDOWN_QUERIES[actual_query]
|
|
163
|
+
|
|
164
|
+
raise KeyError(f"Unknown query: {query_name}")
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def get_available_queries() -> list[str]:
|
|
168
|
+
"""
|
|
169
|
+
Get list of all available query names including aliases
|
|
170
|
+
|
|
171
|
+
Returns:
|
|
172
|
+
List of query names
|
|
173
|
+
"""
|
|
174
|
+
queries = list(MARKDOWN_QUERIES.keys())
|
|
175
|
+
aliases = list(QUERY_ALIASES.keys())
|
|
176
|
+
return sorted(queries + aliases)
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def get_query_info(query_name: str) -> dict[str, str | bool]:
|
|
180
|
+
"""
|
|
181
|
+
Get information about a query
|
|
182
|
+
|
|
183
|
+
Args:
|
|
184
|
+
query_name: Name of the query
|
|
185
|
+
|
|
186
|
+
Returns:
|
|
187
|
+
Dictionary with query information
|
|
188
|
+
"""
|
|
189
|
+
try:
|
|
190
|
+
query_string = get_query(query_name)
|
|
191
|
+
is_alias = query_name in QUERY_ALIASES
|
|
192
|
+
actual_name = (
|
|
193
|
+
QUERY_ALIASES.get(query_name, query_name) if is_alias else query_name
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
return {
|
|
197
|
+
"name": query_name,
|
|
198
|
+
"actual_name": actual_name,
|
|
199
|
+
"is_alias": is_alias,
|
|
200
|
+
"query": query_string,
|
|
201
|
+
"description": _get_query_description(actual_name),
|
|
202
|
+
}
|
|
203
|
+
except KeyError:
|
|
204
|
+
return {"error": f"Query '{query_name}' not found"}
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def _get_query_description(query_name: str) -> str:
|
|
208
|
+
"""Get description for a query"""
|
|
209
|
+
descriptions = {
|
|
210
|
+
"headers": "Extract all heading elements (H1-H6, both ATX and Setext styles)",
|
|
211
|
+
"code_blocks": "Extract fenced and indented code blocks",
|
|
212
|
+
"inline_code": "Extract inline code spans",
|
|
213
|
+
"links": "Extract all types of links (inline, reference, autolinks)",
|
|
214
|
+
"images": "Extract image elements (inline and reference)",
|
|
215
|
+
"lists": "Extract ordered and unordered lists",
|
|
216
|
+
"emphasis": "Extract emphasis and strong emphasis elements",
|
|
217
|
+
"blockquotes": "Extract blockquote elements",
|
|
218
|
+
"tables": "Extract pipe table elements",
|
|
219
|
+
"horizontal_rules": "Extract horizontal rule elements",
|
|
220
|
+
"html_blocks": "Extract HTML block elements",
|
|
221
|
+
"inline_html": "Extract inline HTML elements",
|
|
222
|
+
"strikethrough": "Extract strikethrough elements",
|
|
223
|
+
"task_lists": "Extract task list items (checkboxes)",
|
|
224
|
+
"footnotes": "Extract footnote references and definitions",
|
|
225
|
+
"text_content": "Extract all text content",
|
|
226
|
+
"document": "Extract document root",
|
|
227
|
+
"all_elements": "Extract all Markdown elements",
|
|
228
|
+
}
|
|
229
|
+
return descriptions.get(query_name, "No description available")
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def get_all_queries() -> dict[str, str]:
|
|
233
|
+
"""
|
|
234
|
+
Get all queries for the query loader
|
|
235
|
+
|
|
236
|
+
Returns:
|
|
237
|
+
Dictionary mapping query names to query strings
|
|
238
|
+
"""
|
|
239
|
+
# Combine direct queries and aliases
|
|
240
|
+
all_queries = MARKDOWN_QUERIES.copy()
|
|
241
|
+
|
|
242
|
+
# Add aliases that point to actual queries
|
|
243
|
+
for alias, target in QUERY_ALIASES.items():
|
|
244
|
+
if target in MARKDOWN_QUERIES:
|
|
245
|
+
all_queries[alias] = MARKDOWN_QUERIES[target]
|
|
246
|
+
|
|
247
|
+
return all_queries
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
# Export main functions and constants
|
|
251
|
+
__all__ = [
|
|
252
|
+
"MARKDOWN_QUERIES",
|
|
253
|
+
"QUERY_ALIASES",
|
|
254
|
+
"get_query",
|
|
255
|
+
"get_available_queries",
|
|
256
|
+
"get_query_info",
|
|
257
|
+
"get_all_queries",
|
|
258
|
+
]
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"""
|
|
2
|
+
PHP Tree-sitter Queries
|
|
3
|
+
|
|
4
|
+
Defines tree-sitter queries for efficient PHP element extraction.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
# Query for PHP classes, interfaces, traits, and enums
|
|
8
|
+
PHP_CLASS_QUERY = """
|
|
9
|
+
(class_declaration
|
|
10
|
+
name: (name) @class.name) @class.definition
|
|
11
|
+
|
|
12
|
+
(interface_declaration
|
|
13
|
+
name: (name) @interface.name) @interface.definition
|
|
14
|
+
|
|
15
|
+
(trait_declaration
|
|
16
|
+
name: (name) @trait.name) @trait.definition
|
|
17
|
+
|
|
18
|
+
(enum_declaration
|
|
19
|
+
name: (name) @enum.name) @enum.definition
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
# Query for PHP methods
|
|
23
|
+
PHP_METHOD_QUERY = """
|
|
24
|
+
(method_declaration
|
|
25
|
+
name: (name) @method.name
|
|
26
|
+
parameters: (formal_parameters) @method.parameters) @method.definition
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
# Query for PHP functions
|
|
30
|
+
PHP_FUNCTION_QUERY = """
|
|
31
|
+
(function_definition
|
|
32
|
+
name: (name) @function.name
|
|
33
|
+
parameters: (formal_parameters) @function.parameters) @function.definition
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
# Query for PHP properties
|
|
37
|
+
PHP_PROPERTY_QUERY = """
|
|
38
|
+
(property_declaration
|
|
39
|
+
(property_element
|
|
40
|
+
(variable_name) @property.name)) @property.definition
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
# Query for PHP constants
|
|
44
|
+
PHP_CONSTANT_QUERY = """
|
|
45
|
+
(const_declaration
|
|
46
|
+
(const_element
|
|
47
|
+
name: (name) @constant.name)) @constant.definition
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
# Query for PHP use statements
|
|
51
|
+
PHP_USE_QUERY = """
|
|
52
|
+
(namespace_use_declaration
|
|
53
|
+
(namespace_use_clause
|
|
54
|
+
(qualified_name) @import.name)) @import.definition
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
# Query for PHP namespaces
|
|
58
|
+
PHP_NAMESPACE_QUERY = """
|
|
59
|
+
(namespace_definition
|
|
60
|
+
name: (namespace_name) @namespace.name) @namespace.definition
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
# Query for PHP attributes (PHP 8+)
|
|
64
|
+
PHP_ATTRIBUTE_QUERY = """
|
|
65
|
+
(attribute_list
|
|
66
|
+
(attribute_group
|
|
67
|
+
(attribute
|
|
68
|
+
name: (name) @attribute.name))) @attribute.definition
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
# Query for PHP magic methods
|
|
72
|
+
PHP_MAGIC_METHOD_QUERY = """
|
|
73
|
+
(method_declaration
|
|
74
|
+
name: (name) @magic.method.name
|
|
75
|
+
(#match? @magic.method.name "^__")) @magic.method.definition
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
# Combined query for all PHP elements
|
|
79
|
+
PHP_ALL_ELEMENTS_QUERY = f"""
|
|
80
|
+
{PHP_CLASS_QUERY}
|
|
81
|
+
|
|
82
|
+
{PHP_METHOD_QUERY}
|
|
83
|
+
|
|
84
|
+
{PHP_FUNCTION_QUERY}
|
|
85
|
+
|
|
86
|
+
{PHP_PROPERTY_QUERY}
|
|
87
|
+
|
|
88
|
+
{PHP_CONSTANT_QUERY}
|
|
89
|
+
|
|
90
|
+
{PHP_USE_QUERY}
|
|
91
|
+
|
|
92
|
+
{PHP_NAMESPACE_QUERY}
|
|
93
|
+
|
|
94
|
+
{PHP_ATTRIBUTE_QUERY}
|
|
95
|
+
"""
|