tree-sitter-analyzer 1.8.4__py3-none-any.whl → 1.9.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.
Potentially problematic release.
This version of tree-sitter-analyzer might be problematic. Click here for more details.
- tree_sitter_analyzer/__init__.py +1 -1
- tree_sitter_analyzer/api.py +4 -4
- tree_sitter_analyzer/cli/argument_validator.py +29 -17
- tree_sitter_analyzer/cli/commands/advanced_command.py +7 -5
- tree_sitter_analyzer/cli/commands/structure_command.py +7 -5
- tree_sitter_analyzer/cli/commands/summary_command.py +10 -6
- tree_sitter_analyzer/cli/commands/table_command.py +8 -7
- tree_sitter_analyzer/cli/info_commands.py +1 -1
- tree_sitter_analyzer/cli_main.py +3 -2
- tree_sitter_analyzer/core/analysis_engine.py +5 -5
- tree_sitter_analyzer/core/cache_service.py +3 -1
- tree_sitter_analyzer/core/query.py +17 -5
- tree_sitter_analyzer/core/query_service.py +1 -1
- tree_sitter_analyzer/encoding_utils.py +3 -3
- tree_sitter_analyzer/exceptions.py +61 -50
- tree_sitter_analyzer/file_handler.py +3 -0
- tree_sitter_analyzer/formatters/base_formatter.py +10 -5
- tree_sitter_analyzer/formatters/formatter_registry.py +83 -68
- tree_sitter_analyzer/formatters/html_formatter.py +90 -64
- tree_sitter_analyzer/formatters/javascript_formatter.py +21 -16
- tree_sitter_analyzer/formatters/language_formatter_factory.py +7 -6
- tree_sitter_analyzer/formatters/markdown_formatter.py +247 -124
- tree_sitter_analyzer/formatters/python_formatter.py +61 -38
- tree_sitter_analyzer/formatters/typescript_formatter.py +113 -45
- tree_sitter_analyzer/interfaces/mcp_server.py +2 -2
- tree_sitter_analyzer/language_detector.py +6 -6
- tree_sitter_analyzer/language_loader.py +3 -1
- tree_sitter_analyzer/languages/css_plugin.py +120 -61
- tree_sitter_analyzer/languages/html_plugin.py +159 -62
- tree_sitter_analyzer/languages/java_plugin.py +42 -34
- tree_sitter_analyzer/languages/javascript_plugin.py +59 -30
- tree_sitter_analyzer/languages/markdown_plugin.py +402 -368
- tree_sitter_analyzer/languages/python_plugin.py +111 -64
- tree_sitter_analyzer/languages/typescript_plugin.py +241 -132
- tree_sitter_analyzer/mcp/server.py +22 -18
- tree_sitter_analyzer/mcp/tools/analyze_scale_tool.py +13 -8
- tree_sitter_analyzer/mcp/tools/base_tool.py +2 -2
- tree_sitter_analyzer/mcp/tools/fd_rg_utils.py +232 -26
- tree_sitter_analyzer/mcp/tools/find_and_grep_tool.py +31 -23
- tree_sitter_analyzer/mcp/tools/list_files_tool.py +21 -19
- tree_sitter_analyzer/mcp/tools/query_tool.py +17 -18
- tree_sitter_analyzer/mcp/tools/read_partial_tool.py +30 -31
- tree_sitter_analyzer/mcp/tools/search_content_tool.py +131 -77
- tree_sitter_analyzer/mcp/tools/table_format_tool.py +29 -16
- tree_sitter_analyzer/mcp/utils/file_output_factory.py +64 -51
- tree_sitter_analyzer/mcp/utils/file_output_manager.py +34 -24
- tree_sitter_analyzer/mcp/utils/gitignore_detector.py +8 -4
- tree_sitter_analyzer/models.py +7 -5
- tree_sitter_analyzer/plugins/base.py +9 -7
- tree_sitter_analyzer/plugins/manager.py +1 -0
- tree_sitter_analyzer/queries/css.py +2 -21
- tree_sitter_analyzer/queries/html.py +2 -15
- tree_sitter_analyzer/queries/markdown.py +30 -41
- tree_sitter_analyzer/queries/python.py +20 -5
- tree_sitter_analyzer/query_loader.py +5 -5
- tree_sitter_analyzer/security/validator.py +114 -86
- tree_sitter_analyzer/utils/__init__.py +58 -28
- tree_sitter_analyzer/utils/tree_sitter_compat.py +72 -65
- tree_sitter_analyzer/utils.py +26 -15
- {tree_sitter_analyzer-1.8.4.dist-info → tree_sitter_analyzer-1.9.1.dist-info}/METADATA +23 -6
- tree_sitter_analyzer-1.9.1.dist-info/RECORD +109 -0
- tree_sitter_analyzer-1.8.4.dist-info/RECORD +0 -109
- {tree_sitter_analyzer-1.8.4.dist-info → tree_sitter_analyzer-1.9.1.dist-info}/WHEEL +0 -0
- {tree_sitter_analyzer-1.8.4.dist-info → tree_sitter_analyzer-1.9.1.dist-info}/entry_points.txt +0 -0
|
@@ -1221,7 +1221,7 @@ class JavaScriptElementExtractor(ElementExtractor):
|
|
|
1221
1221
|
def extract_elements(self, tree: "tree_sitter.Tree", source_code: str) -> list:
|
|
1222
1222
|
"""Extract elements from source code using tree-sitter AST"""
|
|
1223
1223
|
elements = []
|
|
1224
|
-
|
|
1224
|
+
|
|
1225
1225
|
try:
|
|
1226
1226
|
elements.extend(self.extract_functions(tree, source_code))
|
|
1227
1227
|
elements.extend(self.extract_classes(tree, source_code))
|
|
@@ -1229,7 +1229,7 @@ class JavaScriptElementExtractor(ElementExtractor):
|
|
|
1229
1229
|
elements.extend(self.extract_imports(tree, source_code))
|
|
1230
1230
|
except Exception as e:
|
|
1231
1231
|
log_error(f"Failed to extract elements: {e}")
|
|
1232
|
-
|
|
1232
|
+
|
|
1233
1233
|
return elements
|
|
1234
1234
|
|
|
1235
1235
|
def _get_variable_kind(self, var_data: dict | str) -> str:
|
|
@@ -1359,7 +1359,7 @@ class JavaScriptPlugin(LanguagePlugin):
|
|
|
1359
1359
|
def __init__(self) -> None:
|
|
1360
1360
|
self._extractor = JavaScriptElementExtractor()
|
|
1361
1361
|
self._language: tree_sitter.Language | None = None
|
|
1362
|
-
|
|
1362
|
+
|
|
1363
1363
|
# Legacy compatibility attributes for tests
|
|
1364
1364
|
self.language = "javascript"
|
|
1365
1365
|
self.extractor = self._extractor
|
|
@@ -1440,23 +1440,36 @@ class JavaScriptPlugin(LanguagePlugin):
|
|
|
1440
1440
|
],
|
|
1441
1441
|
}
|
|
1442
1442
|
|
|
1443
|
-
def execute_query_strategy(
|
|
1443
|
+
def execute_query_strategy(
|
|
1444
|
+
self, tree: "tree_sitter.Tree", source_code: str, query_key: str
|
|
1445
|
+
) -> list[dict]:
|
|
1444
1446
|
"""
|
|
1445
1447
|
Execute query strategy for JavaScript language
|
|
1446
|
-
|
|
1448
|
+
|
|
1447
1449
|
Args:
|
|
1448
1450
|
tree: Tree-sitter tree object
|
|
1449
1451
|
source_code: Source code string
|
|
1450
1452
|
query_key: Query key to execute
|
|
1451
|
-
|
|
1453
|
+
|
|
1452
1454
|
Returns:
|
|
1453
1455
|
List of query results
|
|
1454
1456
|
"""
|
|
1455
1457
|
# Use the extractor to get elements based on query_key
|
|
1456
1458
|
extractor = self.get_extractor()
|
|
1457
|
-
|
|
1459
|
+
|
|
1458
1460
|
# Map query keys to extraction methods
|
|
1459
|
-
if query_key in [
|
|
1461
|
+
if query_key in [
|
|
1462
|
+
"function",
|
|
1463
|
+
"functions",
|
|
1464
|
+
"async_function",
|
|
1465
|
+
"async_functions",
|
|
1466
|
+
"arrow_function",
|
|
1467
|
+
"arrow_functions",
|
|
1468
|
+
"method",
|
|
1469
|
+
"methods",
|
|
1470
|
+
"constructor",
|
|
1471
|
+
"constructors",
|
|
1472
|
+
]:
|
|
1460
1473
|
elements = extractor.extract_functions(tree, source_code)
|
|
1461
1474
|
elif query_key in ["class", "classes", "react_component", "react_components"]:
|
|
1462
1475
|
elements = extractor.extract_classes(tree, source_code)
|
|
@@ -1467,7 +1480,7 @@ class JavaScriptPlugin(LanguagePlugin):
|
|
|
1467
1480
|
else:
|
|
1468
1481
|
# For unknown query keys, return empty list
|
|
1469
1482
|
return []
|
|
1470
|
-
|
|
1483
|
+
|
|
1471
1484
|
# Convert elements to query result format
|
|
1472
1485
|
results = []
|
|
1473
1486
|
for element in elements:
|
|
@@ -1480,17 +1493,17 @@ class JavaScriptPlugin(LanguagePlugin):
|
|
|
1480
1493
|
"name": element.name,
|
|
1481
1494
|
}
|
|
1482
1495
|
results.append(result)
|
|
1483
|
-
|
|
1496
|
+
|
|
1484
1497
|
return results
|
|
1485
|
-
|
|
1498
|
+
|
|
1486
1499
|
def _get_node_type_for_element(self, element) -> str:
|
|
1487
1500
|
"""Get appropriate node type for element"""
|
|
1488
|
-
from ..models import Function,
|
|
1489
|
-
|
|
1501
|
+
from ..models import Class, Function, Import, Variable
|
|
1502
|
+
|
|
1490
1503
|
if isinstance(element, Function):
|
|
1491
|
-
if hasattr(element,
|
|
1504
|
+
if hasattr(element, "is_arrow") and element.is_arrow:
|
|
1492
1505
|
return "arrow_function"
|
|
1493
|
-
elif hasattr(element,
|
|
1506
|
+
elif hasattr(element, "is_method") and element.is_method:
|
|
1494
1507
|
return "method_definition"
|
|
1495
1508
|
else:
|
|
1496
1509
|
return "function_declaration"
|
|
@@ -1506,7 +1519,7 @@ class JavaScriptPlugin(LanguagePlugin):
|
|
|
1506
1519
|
def get_element_categories(self) -> dict[str, list[str]]:
|
|
1507
1520
|
"""
|
|
1508
1521
|
Get element categories mapping query keys to node types
|
|
1509
|
-
|
|
1522
|
+
|
|
1510
1523
|
Returns:
|
|
1511
1524
|
Dictionary mapping query keys to lists of node types
|
|
1512
1525
|
"""
|
|
@@ -1522,21 +1535,17 @@ class JavaScriptPlugin(LanguagePlugin):
|
|
|
1522
1535
|
"methods": ["method_definition"],
|
|
1523
1536
|
"constructor": ["method_definition"],
|
|
1524
1537
|
"constructors": ["method_definition"],
|
|
1525
|
-
|
|
1526
1538
|
# Class-related queries
|
|
1527
1539
|
"class": ["class_declaration", "class_expression"],
|
|
1528
1540
|
"classes": ["class_declaration", "class_expression"],
|
|
1529
|
-
|
|
1530
1541
|
# Variable-related queries
|
|
1531
1542
|
"variable": ["variable_declaration", "lexical_declaration"],
|
|
1532
1543
|
"variables": ["variable_declaration", "lexical_declaration"],
|
|
1533
|
-
|
|
1534
1544
|
# Import/Export-related queries
|
|
1535
1545
|
"import": ["import_statement"],
|
|
1536
1546
|
"imports": ["import_statement"],
|
|
1537
1547
|
"export": ["export_statement"],
|
|
1538
1548
|
"exports": ["export_statement"],
|
|
1539
|
-
|
|
1540
1549
|
# React-specific queries
|
|
1541
1550
|
"react_component": ["class_declaration", "function_declaration"],
|
|
1542
1551
|
"react_components": ["class_declaration", "function_declaration"],
|
|
@@ -1544,12 +1553,20 @@ class JavaScriptPlugin(LanguagePlugin):
|
|
|
1544
1553
|
"react_hooks": ["function_declaration"],
|
|
1545
1554
|
"jsx_element": ["jsx_element", "jsx_self_closing_element"],
|
|
1546
1555
|
"jsx_elements": ["jsx_element", "jsx_self_closing_element"],
|
|
1547
|
-
|
|
1548
1556
|
# Generic queries
|
|
1549
1557
|
"all_elements": [
|
|
1550
|
-
"function_declaration",
|
|
1551
|
-
"
|
|
1552
|
-
"
|
|
1558
|
+
"function_declaration",
|
|
1559
|
+
"function_expression",
|
|
1560
|
+
"arrow_function",
|
|
1561
|
+
"method_definition",
|
|
1562
|
+
"class_declaration",
|
|
1563
|
+
"class_expression",
|
|
1564
|
+
"variable_declaration",
|
|
1565
|
+
"lexical_declaration",
|
|
1566
|
+
"import_statement",
|
|
1567
|
+
"export_statement",
|
|
1568
|
+
"jsx_element",
|
|
1569
|
+
"jsx_self_closing_element",
|
|
1553
1570
|
],
|
|
1554
1571
|
}
|
|
1555
1572
|
|
|
@@ -1632,21 +1649,33 @@ class JavaScriptPlugin(LanguagePlugin):
|
|
|
1632
1649
|
def extract_elements(self, tree: "tree_sitter.Tree", source_code: str) -> dict:
|
|
1633
1650
|
"""Extract elements from source code using tree-sitter AST"""
|
|
1634
1651
|
try:
|
|
1635
|
-
if tree is None or not hasattr(tree,
|
|
1636
|
-
return {
|
|
1637
|
-
|
|
1652
|
+
if tree is None or not hasattr(tree, "root_node") or tree.root_node is None:
|
|
1653
|
+
return {
|
|
1654
|
+
"functions": [],
|
|
1655
|
+
"classes": [],
|
|
1656
|
+
"variables": [],
|
|
1657
|
+
"imports": [],
|
|
1658
|
+
"exports": [],
|
|
1659
|
+
}
|
|
1660
|
+
|
|
1638
1661
|
functions = self._extractor.extract_functions(tree, source_code)
|
|
1639
1662
|
classes = self._extractor.extract_classes(tree, source_code)
|
|
1640
1663
|
variables = self._extractor.extract_variables(tree, source_code)
|
|
1641
1664
|
imports = self._extractor.extract_imports(tree, source_code)
|
|
1642
|
-
|
|
1665
|
+
|
|
1643
1666
|
return {
|
|
1644
1667
|
"functions": functions,
|
|
1645
1668
|
"classes": classes,
|
|
1646
1669
|
"variables": variables,
|
|
1647
1670
|
"imports": imports,
|
|
1648
|
-
"exports": [] # TODO: Implement exports extraction
|
|
1671
|
+
"exports": [], # TODO: Implement exports extraction
|
|
1649
1672
|
}
|
|
1650
1673
|
except Exception as e:
|
|
1651
1674
|
log_error(f"Failed to extract elements: {e}")
|
|
1652
|
-
return {
|
|
1675
|
+
return {
|
|
1676
|
+
"functions": [],
|
|
1677
|
+
"classes": [],
|
|
1678
|
+
"variables": [],
|
|
1679
|
+
"imports": [],
|
|
1680
|
+
"exports": [],
|
|
1681
|
+
}
|