tree-sitter-analyzer 1.9.1__py3-none-any.whl → 1.9.3__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 +10 -6
- tree_sitter_analyzer/cli/argument_validator.py +1 -1
- tree_sitter_analyzer/cli/commands/advanced_command.py +3 -6
- tree_sitter_analyzer/cli/commands/query_command.py +3 -1
- tree_sitter_analyzer/cli/commands/table_command.py +3 -3
- tree_sitter_analyzer/constants.py +5 -3
- tree_sitter_analyzer/core/analysis_engine.py +1 -1
- tree_sitter_analyzer/core/cache_service.py +1 -1
- tree_sitter_analyzer/core/engine.py +1 -1
- tree_sitter_analyzer/core/query.py +0 -2
- tree_sitter_analyzer/exceptions.py +1 -1
- tree_sitter_analyzer/file_handler.py +6 -6
- tree_sitter_analyzer/formatters/base_formatter.py +1 -1
- tree_sitter_analyzer/formatters/html_formatter.py +24 -14
- tree_sitter_analyzer/formatters/javascript_formatter.py +28 -21
- tree_sitter_analyzer/formatters/language_formatter_factory.py +7 -4
- tree_sitter_analyzer/formatters/markdown_formatter.py +4 -4
- tree_sitter_analyzer/formatters/python_formatter.py +4 -4
- tree_sitter_analyzer/formatters/typescript_formatter.py +1 -1
- tree_sitter_analyzer/interfaces/mcp_adapter.py +4 -2
- tree_sitter_analyzer/interfaces/mcp_server.py +10 -10
- tree_sitter_analyzer/language_detector.py +30 -5
- tree_sitter_analyzer/language_loader.py +46 -26
- tree_sitter_analyzer/languages/css_plugin.py +6 -6
- tree_sitter_analyzer/languages/html_plugin.py +12 -8
- tree_sitter_analyzer/languages/java_plugin.py +307 -520
- tree_sitter_analyzer/languages/javascript_plugin.py +22 -78
- tree_sitter_analyzer/languages/markdown_plugin.py +277 -297
- tree_sitter_analyzer/languages/python_plugin.py +47 -85
- tree_sitter_analyzer/languages/typescript_plugin.py +48 -123
- tree_sitter_analyzer/mcp/resources/project_stats_resource.py +14 -8
- tree_sitter_analyzer/mcp/server.py +38 -23
- tree_sitter_analyzer/mcp/tools/analyze_scale_tool.py +10 -7
- tree_sitter_analyzer/mcp/tools/analyze_scale_tool_cli_compatible.py +51 -7
- tree_sitter_analyzer/mcp/tools/fd_rg_utils.py +15 -2
- tree_sitter_analyzer/mcp/tools/find_and_grep_tool.py +8 -6
- tree_sitter_analyzer/mcp/tools/list_files_tool.py +6 -6
- tree_sitter_analyzer/mcp/tools/search_content_tool.py +48 -19
- tree_sitter_analyzer/mcp/tools/table_format_tool.py +13 -8
- tree_sitter_analyzer/mcp/utils/file_output_manager.py +8 -3
- tree_sitter_analyzer/mcp/utils/gitignore_detector.py +24 -12
- tree_sitter_analyzer/mcp/utils/path_resolver.py +2 -2
- tree_sitter_analyzer/models.py +16 -0
- tree_sitter_analyzer/mypy_current_errors.txt +2 -0
- tree_sitter_analyzer/plugins/base.py +66 -0
- tree_sitter_analyzer/queries/java.py +1 -1
- tree_sitter_analyzer/queries/javascript.py +3 -8
- tree_sitter_analyzer/queries/markdown.py +1 -1
- tree_sitter_analyzer/queries/python.py +2 -2
- tree_sitter_analyzer/security/boundary_manager.py +2 -5
- tree_sitter_analyzer/security/regex_checker.py +2 -2
- tree_sitter_analyzer/security/validator.py +5 -1
- tree_sitter_analyzer/table_formatter.py +4 -4
- tree_sitter_analyzer/utils/__init__.py +27 -116
- tree_sitter_analyzer/{utils.py → utils/logging.py} +2 -2
- tree_sitter_analyzer/utils/tree_sitter_compat.py +2 -2
- {tree_sitter_analyzer-1.9.1.dist-info → tree_sitter_analyzer-1.9.3.dist-info}/METADATA +70 -30
- tree_sitter_analyzer-1.9.3.dist-info/RECORD +110 -0
- tree_sitter_analyzer-1.9.1.dist-info/RECORD +0 -109
- {tree_sitter_analyzer-1.9.1.dist-info → tree_sitter_analyzer-1.9.3.dist-info}/WHEEL +0 -0
- {tree_sitter_analyzer-1.9.1.dist-info → tree_sitter_analyzer-1.9.3.dist-info}/entry_points.txt +0 -0
|
@@ -34,6 +34,10 @@ class ElementExtractor(ABC):
|
|
|
34
34
|
meaningful code elements like functions, classes, variables, etc.
|
|
35
35
|
"""
|
|
36
36
|
|
|
37
|
+
def __init__(self) -> None:
|
|
38
|
+
"""Initialize the element extractor."""
|
|
39
|
+
self.current_file: str = "" # Current file being processed
|
|
40
|
+
|
|
37
41
|
@abstractmethod
|
|
38
42
|
def extract_functions(
|
|
39
43
|
self, tree: "tree_sitter.Tree", source_code: str
|
|
@@ -98,6 +102,36 @@ class ElementExtractor(ABC):
|
|
|
98
102
|
"""
|
|
99
103
|
pass
|
|
100
104
|
|
|
105
|
+
def extract_packages(self, tree: "tree_sitter.Tree", source_code: str) -> list[Any]:
|
|
106
|
+
"""
|
|
107
|
+
Extract package declarations from the syntax tree.
|
|
108
|
+
|
|
109
|
+
Args:
|
|
110
|
+
tree: Tree-sitter AST
|
|
111
|
+
source_code: Original source code
|
|
112
|
+
|
|
113
|
+
Returns:
|
|
114
|
+
List of extracted package objects
|
|
115
|
+
"""
|
|
116
|
+
# Default implementation returns empty list
|
|
117
|
+
return []
|
|
118
|
+
|
|
119
|
+
def extract_annotations(
|
|
120
|
+
self, tree: "tree_sitter.Tree", source_code: str
|
|
121
|
+
) -> list[Any]:
|
|
122
|
+
"""
|
|
123
|
+
Extract annotations from the syntax tree.
|
|
124
|
+
|
|
125
|
+
Args:
|
|
126
|
+
tree: Tree-sitter AST
|
|
127
|
+
source_code: Original source code
|
|
128
|
+
|
|
129
|
+
Returns:
|
|
130
|
+
List of extracted annotation objects
|
|
131
|
+
"""
|
|
132
|
+
# Default implementation returns empty list
|
|
133
|
+
return []
|
|
134
|
+
|
|
101
135
|
def extract_all_elements(
|
|
102
136
|
self, tree: "tree_sitter.Tree", source_code: str
|
|
103
137
|
) -> list[CodeElement]:
|
|
@@ -123,6 +157,38 @@ class ElementExtractor(ABC):
|
|
|
123
157
|
|
|
124
158
|
return elements
|
|
125
159
|
|
|
160
|
+
def extract_html_elements(
|
|
161
|
+
self, tree: "tree_sitter.Tree", source_code: str
|
|
162
|
+
) -> list[Any]:
|
|
163
|
+
"""
|
|
164
|
+
Extract HTML elements from the syntax tree.
|
|
165
|
+
|
|
166
|
+
Args:
|
|
167
|
+
tree: Tree-sitter AST
|
|
168
|
+
source_code: Original source code
|
|
169
|
+
|
|
170
|
+
Returns:
|
|
171
|
+
List of extracted HTML elements
|
|
172
|
+
"""
|
|
173
|
+
# Default implementation returns empty list
|
|
174
|
+
return []
|
|
175
|
+
|
|
176
|
+
def extract_css_rules(
|
|
177
|
+
self, tree: "tree_sitter.Tree", source_code: str
|
|
178
|
+
) -> list[Any]:
|
|
179
|
+
"""
|
|
180
|
+
Extract CSS rules from the syntax tree.
|
|
181
|
+
|
|
182
|
+
Args:
|
|
183
|
+
tree: Tree-sitter AST
|
|
184
|
+
source_code: Original source code
|
|
185
|
+
|
|
186
|
+
Returns:
|
|
187
|
+
List of extracted CSS rules
|
|
188
|
+
"""
|
|
189
|
+
# Default implementation returns empty list
|
|
190
|
+
return []
|
|
191
|
+
|
|
126
192
|
|
|
127
193
|
class LanguagePlugin(ABC):
|
|
128
194
|
"""
|
|
@@ -181,7 +181,7 @@ JAVA_QUERIES: dict[str, str] = {
|
|
|
181
181
|
# --- Structural Information Extraction Queries ---
|
|
182
182
|
"javadoc_comment": """
|
|
183
183
|
(block_comment) @javadoc_comment
|
|
184
|
-
(#match? @javadoc_comment "
|
|
184
|
+
(#match? @javadoc_comment "^/\\\\\\\\\\\\*\\\\\\\\\\\\*")
|
|
185
185
|
""",
|
|
186
186
|
"class_with_javadoc": """
|
|
187
187
|
(class_declaration
|
|
@@ -56,13 +56,13 @@ JAVASCRIPT_QUERIES: dict[str, str] = {
|
|
|
56
56
|
"class_declaration": """
|
|
57
57
|
(class_declaration
|
|
58
58
|
name: (identifier) @class_name
|
|
59
|
-
|
|
59
|
+
(class_heritage)? @superclass
|
|
60
60
|
body: (class_body) @body) @class_declaration
|
|
61
61
|
""",
|
|
62
62
|
"class_expression": """
|
|
63
63
|
(class_expression
|
|
64
64
|
name: (identifier)? @class_name
|
|
65
|
-
|
|
65
|
+
(class_heritage)? @superclass
|
|
66
66
|
body: (class_body) @body) @class_expression
|
|
67
67
|
""",
|
|
68
68
|
"class_method": """
|
|
@@ -542,13 +542,8 @@ FUNCTIONS = """
|
|
|
542
542
|
CLASSES = """
|
|
543
543
|
(class_declaration
|
|
544
544
|
name: (identifier) @class.name
|
|
545
|
-
|
|
545
|
+
(class_heritage)? @class.superclass
|
|
546
546
|
body: (class_body) @class.body) @class.declaration
|
|
547
|
-
|
|
548
|
-
(class_expression
|
|
549
|
-
name: (identifier)? @class.name
|
|
550
|
-
superclass: (class_heritage)? @class.superclass
|
|
551
|
-
body: (class_body) @class.body) @class.expression
|
|
552
547
|
"""
|
|
553
548
|
|
|
554
549
|
VARIABLES = """
|
|
@@ -176,7 +176,7 @@ def get_available_queries() -> list[str]:
|
|
|
176
176
|
return sorted(queries + aliases)
|
|
177
177
|
|
|
178
178
|
|
|
179
|
-
def get_query_info(query_name: str) -> dict[str, str]:
|
|
179
|
+
def get_query_info(query_name: str) -> dict[str, str | bool]:
|
|
180
180
|
"""
|
|
181
181
|
Get information about a query
|
|
182
182
|
|
|
@@ -40,7 +40,7 @@ IMPORTS = """
|
|
|
40
40
|
|
|
41
41
|
(import_from_statement
|
|
42
42
|
module_name: (dotted_name)? @import.module
|
|
43
|
-
name: (
|
|
43
|
+
name: (aliased_import) @import.aliased_item) @import.from_aliased
|
|
44
44
|
|
|
45
45
|
(aliased_import
|
|
46
46
|
name: (dotted_name) @import.name
|
|
@@ -335,7 +335,7 @@ PYTHON_QUERIES: dict[str, str] = {
|
|
|
335
335
|
"import_from_list": """
|
|
336
336
|
(import_from_statement
|
|
337
337
|
module_name: (dotted_name)? @module_name
|
|
338
|
-
name: (
|
|
338
|
+
name: (aliased_import) @import_item) @import_from_list
|
|
339
339
|
""",
|
|
340
340
|
"aliased_import": """
|
|
341
341
|
(aliased_import
|
|
@@ -45,8 +45,6 @@ class ProjectBoundaryManager:
|
|
|
45
45
|
# Handle both string and Path objects
|
|
46
46
|
if isinstance(project_root, str):
|
|
47
47
|
project_path = Path(project_root)
|
|
48
|
-
elif isinstance(project_root, Path):
|
|
49
|
-
project_path = project_root
|
|
50
48
|
else:
|
|
51
49
|
raise SecurityError(f"Invalid project root type: {type(project_root)}")
|
|
52
50
|
|
|
@@ -150,18 +148,17 @@ class ProjectBoundaryManager:
|
|
|
150
148
|
real_path = Path(file_path).resolve()
|
|
151
149
|
try:
|
|
152
150
|
rel_path = real_path.relative_to(Path(self.project_root))
|
|
153
|
-
rel_path = str(rel_path)
|
|
154
151
|
except ValueError:
|
|
155
152
|
# Path is not relative to project root
|
|
156
153
|
log_warning(f"Path not relative to project root: {file_path}")
|
|
157
154
|
return None
|
|
158
155
|
|
|
159
156
|
# Ensure relative path doesn't start with ..
|
|
160
|
-
if rel_path.startswith(".."):
|
|
157
|
+
if str(rel_path).startswith(".."):
|
|
161
158
|
log_warning(f"Relative path calculation failed: {rel_path}")
|
|
162
159
|
return None
|
|
163
160
|
|
|
164
|
-
return rel_path
|
|
161
|
+
return str(rel_path)
|
|
165
162
|
|
|
166
163
|
except Exception as e:
|
|
167
164
|
log_warning(f"Relative path calculation error: {e}")
|
|
@@ -219,9 +219,9 @@ class RegexSafetyChecker:
|
|
|
219
219
|
|
|
220
220
|
# Calculate complexity score
|
|
221
221
|
metrics["complexity_score"] = (
|
|
222
|
-
metrics["length"] * 0.1
|
|
222
|
+
int(metrics["length"] * 0.1)
|
|
223
223
|
+ metrics["quantifiers"] * 2
|
|
224
|
-
+ metrics["groups"] * 1.5
|
|
224
|
+
+ int(metrics["groups"] * 1.5)
|
|
225
225
|
+ metrics["alternations"] * 3
|
|
226
226
|
+ metrics["character_classes"] * 1
|
|
227
227
|
)
|
|
@@ -36,6 +36,8 @@ class SecurityValidator:
|
|
|
36
36
|
Args:
|
|
37
37
|
project_root: Optional project root directory for boundary checks
|
|
38
38
|
"""
|
|
39
|
+
self.boundary_manager: ProjectBoundaryManager | None
|
|
40
|
+
|
|
39
41
|
# Ensure project_root is properly resolved if provided
|
|
40
42
|
if project_root:
|
|
41
43
|
try:
|
|
@@ -488,7 +490,9 @@ class SecurityValidator:
|
|
|
488
490
|
or "CI" in os.environ
|
|
489
491
|
or "GITHUB_ACTIONS" in os.environ
|
|
490
492
|
or any(
|
|
491
|
-
"test" in arg.lower()
|
|
493
|
+
"test" in arg.lower()
|
|
494
|
+
for arg in getattr(getattr(os, "sys", None), "argv", [])
|
|
495
|
+
if hasattr(os, "sys")
|
|
492
496
|
)
|
|
493
497
|
)
|
|
494
498
|
|
|
@@ -665,7 +665,7 @@ class TableFormatter:
|
|
|
665
665
|
|
|
666
666
|
# Map<String,Object> -> M<S,O>
|
|
667
667
|
if "Map<" in type_name:
|
|
668
|
-
return (
|
|
668
|
+
return str(
|
|
669
669
|
type_name.replace("Map<", "M<")
|
|
670
670
|
.replace("String", "S")
|
|
671
671
|
.replace("Object", "O")
|
|
@@ -673,17 +673,17 @@ class TableFormatter:
|
|
|
673
673
|
|
|
674
674
|
# List<String> -> L<S>
|
|
675
675
|
if "List<" in type_name:
|
|
676
|
-
return type_name.replace("List<", "L<").replace("String", "S")
|
|
676
|
+
return str(type_name.replace("List<", "L<").replace("String", "S"))
|
|
677
677
|
|
|
678
678
|
# String[] -> S[]
|
|
679
679
|
if "[]" in type_name:
|
|
680
680
|
base_type = type_name.replace("[]", "")
|
|
681
681
|
if base_type:
|
|
682
|
-
return type_mapping.get(base_type, base_type[0].upper()) + "[]"
|
|
682
|
+
return str(type_mapping.get(base_type, base_type[0].upper())) + "[]"
|
|
683
683
|
else:
|
|
684
684
|
return "O[]"
|
|
685
685
|
|
|
686
|
-
return type_mapping.get(type_name, type_name)
|
|
686
|
+
return str(type_mapping.get(type_name, type_name))
|
|
687
687
|
|
|
688
688
|
def _convert_visibility(self, visibility: str) -> str:
|
|
689
689
|
"""Convert visibility to symbol"""
|
|
@@ -3,132 +3,38 @@
|
|
|
3
3
|
Utilities package for tree_sitter_analyzer.
|
|
4
4
|
|
|
5
5
|
This package contains utility modules for various functionality
|
|
6
|
-
including tree-sitter API compatibility.
|
|
6
|
+
including tree-sitter API compatibility and logging.
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
9
|
# Import from tree-sitter compatibility module
|
|
10
10
|
from .tree_sitter_compat import TreeSitterQueryCompat, get_node_text_safe, log_api_info
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
utils_module.log_debug,
|
|
32
|
-
utils_module.log_error,
|
|
33
|
-
utils_module.log_warning,
|
|
34
|
-
utils_module.log_info,
|
|
35
|
-
utils_module.log_performance,
|
|
36
|
-
utils_module.QuietMode,
|
|
37
|
-
utils_module.safe_print,
|
|
38
|
-
utils_module.LoggingContext,
|
|
39
|
-
utils_module.setup_performance_logger,
|
|
40
|
-
utils_module.create_performance_logger,
|
|
41
|
-
)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
# Import logging functions
|
|
45
|
-
try:
|
|
46
|
-
(
|
|
47
|
-
setup_logger,
|
|
48
|
-
log_debug,
|
|
49
|
-
log_error,
|
|
50
|
-
log_warning,
|
|
51
|
-
log_info,
|
|
52
|
-
log_performance,
|
|
53
|
-
QuietMode,
|
|
54
|
-
safe_print,
|
|
55
|
-
LoggingContext,
|
|
56
|
-
setup_performance_logger,
|
|
57
|
-
create_performance_logger,
|
|
58
|
-
) = _import_logging_functions()
|
|
59
|
-
except Exception:
|
|
60
|
-
# Fallback logging functions if import fails
|
|
61
|
-
def setup_logger(name="tree_sitter_analyzer", level=30):
|
|
62
|
-
import logging
|
|
63
|
-
|
|
64
|
-
logger = logging.getLogger(name)
|
|
65
|
-
if not logger.handlers:
|
|
66
|
-
handler = logging.StreamHandler()
|
|
67
|
-
formatter = logging.Formatter(
|
|
68
|
-
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
|
69
|
-
)
|
|
70
|
-
handler.setFormatter(formatter)
|
|
71
|
-
logger.addHandler(handler)
|
|
72
|
-
logger.setLevel(level)
|
|
73
|
-
return logger
|
|
74
|
-
|
|
75
|
-
def log_debug(msg, *args, **kwargs):
|
|
76
|
-
pass
|
|
77
|
-
|
|
78
|
-
def log_error(msg, *args, **kwargs):
|
|
79
|
-
print(f"ERROR: {msg}", *args)
|
|
80
|
-
|
|
81
|
-
def log_warning(msg, *args, **kwargs):
|
|
82
|
-
print(f"WARNING: {msg}", *args)
|
|
83
|
-
|
|
84
|
-
def log_info(msg, *args, **kwargs):
|
|
85
|
-
print(f"INFO: {msg}", *args)
|
|
86
|
-
|
|
87
|
-
def log_performance(operation, execution_time=None, details=None):
|
|
88
|
-
pass
|
|
89
|
-
|
|
90
|
-
# Fallback QuietMode class
|
|
91
|
-
class QuietMode:
|
|
92
|
-
def __init__(self, enabled=True):
|
|
93
|
-
self.enabled = enabled
|
|
94
|
-
|
|
95
|
-
def __enter__(self):
|
|
96
|
-
return self
|
|
97
|
-
|
|
98
|
-
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
99
|
-
pass
|
|
100
|
-
|
|
101
|
-
# Fallback LoggingContext class
|
|
102
|
-
class LoggingContext:
|
|
103
|
-
def __init__(self, enabled=True, level=None):
|
|
104
|
-
self.enabled = enabled
|
|
105
|
-
self.level = level
|
|
106
|
-
|
|
107
|
-
def __enter__(self):
|
|
108
|
-
return self
|
|
109
|
-
|
|
110
|
-
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
111
|
-
pass
|
|
112
|
-
|
|
113
|
-
def setup_performance_logger():
|
|
114
|
-
import logging
|
|
115
|
-
|
|
116
|
-
return logging.getLogger("performance")
|
|
117
|
-
|
|
118
|
-
def create_performance_logger(name):
|
|
119
|
-
import logging
|
|
120
|
-
|
|
121
|
-
return logging.getLogger(f"{name}.performance")
|
|
122
|
-
|
|
123
|
-
def safe_print(message, level="info", quiet=False):
|
|
124
|
-
if not quiet:
|
|
125
|
-
print(message)
|
|
126
|
-
|
|
12
|
+
# Import logging functions directly from logging module
|
|
13
|
+
from .logging import (
|
|
14
|
+
LoggingContext,
|
|
15
|
+
QuietMode,
|
|
16
|
+
SafeStreamHandler,
|
|
17
|
+
create_performance_logger,
|
|
18
|
+
log_debug,
|
|
19
|
+
log_error,
|
|
20
|
+
log_info,
|
|
21
|
+
log_performance,
|
|
22
|
+
log_warning,
|
|
23
|
+
logger,
|
|
24
|
+
perf_logger,
|
|
25
|
+
safe_print,
|
|
26
|
+
setup_logger,
|
|
27
|
+
setup_performance_logger,
|
|
28
|
+
setup_safe_logging_shutdown,
|
|
29
|
+
suppress_output,
|
|
30
|
+
)
|
|
127
31
|
|
|
128
32
|
__all__ = [
|
|
33
|
+
# Tree-sitter compatibility
|
|
129
34
|
"TreeSitterQueryCompat",
|
|
130
35
|
"get_node_text_safe",
|
|
131
36
|
"log_api_info",
|
|
37
|
+
# Logging functionality
|
|
132
38
|
"setup_logger",
|
|
133
39
|
"log_debug",
|
|
134
40
|
"log_error",
|
|
@@ -140,4 +46,9 @@ __all__ = [
|
|
|
140
46
|
"LoggingContext",
|
|
141
47
|
"setup_performance_logger",
|
|
142
48
|
"create_performance_logger",
|
|
49
|
+
"SafeStreamHandler",
|
|
50
|
+
"setup_safe_logging_shutdown",
|
|
51
|
+
"suppress_output",
|
|
52
|
+
"logger",
|
|
53
|
+
"perf_logger",
|
|
143
54
|
]
|
|
@@ -154,7 +154,7 @@ class SafeStreamHandler(logging.StreamHandler):
|
|
|
154
154
|
A StreamHandler that safely handles closed streams
|
|
155
155
|
"""
|
|
156
156
|
|
|
157
|
-
def __init__(self, stream=None):
|
|
157
|
+
def __init__(self, stream: Any = None) -> None:
|
|
158
158
|
# Default to sys.stderr to keep stdout clean for MCP stdio
|
|
159
159
|
super().__init__(stream if stream is not None else sys.stderr)
|
|
160
160
|
|
|
@@ -449,4 +449,4 @@ class LoggingContext:
|
|
|
449
449
|
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
|
|
450
450
|
if self.enabled and self.old_level is not None:
|
|
451
451
|
# Always restore the saved level
|
|
452
|
-
self.target_logger.setLevel(self.old_level)
|
|
452
|
+
self.target_logger.setLevel(self.old_level)
|
|
@@ -235,7 +235,7 @@ def get_node_text_safe(node: Any, source_code: str, encoding: str = "utf-8") ->
|
|
|
235
235
|
line = lines[start_point[0]]
|
|
236
236
|
start_col = max(0, min(start_point[1], len(line)))
|
|
237
237
|
end_col = max(start_col, min(end_point[1], len(line)))
|
|
238
|
-
return line[start_col:end_col]
|
|
238
|
+
return str(line[start_col:end_col])
|
|
239
239
|
else:
|
|
240
240
|
# Multiple lines
|
|
241
241
|
result_lines = []
|
|
@@ -258,7 +258,7 @@ def get_node_text_safe(node: Any, source_code: str, encoding: str = "utf-8") ->
|
|
|
258
258
|
return ""
|
|
259
259
|
|
|
260
260
|
|
|
261
|
-
def log_api_info():
|
|
261
|
+
def log_api_info() -> None:
|
|
262
262
|
"""Log information about available tree-sitter APIs."""
|
|
263
263
|
try:
|
|
264
264
|
import tree_sitter
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tree-sitter-analyzer
|
|
3
|
-
Version: 1.9.
|
|
3
|
+
Version: 1.9.3
|
|
4
4
|
Summary: AI-era enterprise-grade code analysis tool with comprehensive HTML/CSS support, dynamic plugin architecture, and MCP integration
|
|
5
5
|
Project-URL: Homepage, https://github.com/aimasteracc/tree-sitter-analyzer
|
|
6
6
|
Project-URL: Documentation, https://github.com/aimasteracc/tree-sitter-analyzer#readme
|
|
@@ -33,6 +33,7 @@ Classifier: Typing :: Typed
|
|
|
33
33
|
Requires-Python: >=3.10
|
|
34
34
|
Requires-Dist: cachetools>=5.0.0
|
|
35
35
|
Requires-Dist: chardet>=5.0.0
|
|
36
|
+
Requires-Dist: deepdiff>=6.7.1
|
|
36
37
|
Requires-Dist: mcp>=1.12.3
|
|
37
38
|
Requires-Dist: psutil>=5.9.8
|
|
38
39
|
Requires-Dist: tree-sitter-cpp<0.25.0,>=0.23.4
|
|
@@ -202,7 +203,7 @@ Description-Content-Type: text/markdown
|
|
|
202
203
|
[](https://codecov.io/gh/aimasteracc/tree-sitter-analyzer)
|
|
203
204
|
[](#quality-assurance)
|
|
204
205
|
[](https://pypi.org/project/tree-sitter-analyzer/)
|
|
205
|
-
[](https://github.com/aimasteracc/tree-sitter-analyzer/releases)
|
|
206
207
|
[](https://zread.ai/aimasteracc/tree-sitter-analyzer)
|
|
207
208
|
[](https://github.com/aimasteracc/tree-sitter-analyzer)
|
|
208
209
|
|
|
@@ -250,9 +251,8 @@ Tree-sitter Analyzer is an enterprise-grade code analysis tool designed for the
|
|
|
250
251
|
| **HTML** | 🆕 Complete Support | DOM structure analysis, element classification, attribute extraction, hierarchical relationships |
|
|
251
252
|
| **CSS** | 🆕 Complete Support | Selector analysis, property classification, style rule extraction, intelligent categorization |
|
|
252
253
|
| **Markdown** | Complete Support | Headers, code blocks, links, images, tables, task lists, blockquotes |
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
| **Go** | Basic Support | Basic syntax parsing |
|
|
254
|
+
|
|
255
|
+
**Note:** Currently, only the above 7 languages have complete plugin implementations. Languages such as C/C++, Rust, Go, JSON are defined in `LanguageDetector` but do not have functional plugin implementations at this time.
|
|
256
256
|
|
|
257
257
|
### 🏆 Production Ready
|
|
258
258
|
- **3,370 Tests** - 100% pass rate, enterprise-grade quality assurance
|
|
@@ -397,21 +397,21 @@ uv add "tree-sitter-analyzer[all,mcp]"
|
|
|
397
397
|
|
|
398
398
|
```bash
|
|
399
399
|
# View help
|
|
400
|
-
uv run
|
|
400
|
+
uv run tree-sitter-analyzer --help
|
|
401
401
|
|
|
402
402
|
# Analyze large file scale (1419 lines completed instantly)
|
|
403
|
-
uv run
|
|
403
|
+
uv run tree-sitter-analyzer examples/BigService.java --advanced --output-format text
|
|
404
404
|
|
|
405
405
|
# Generate detailed structure table for code files
|
|
406
|
-
uv run
|
|
406
|
+
uv run tree-sitter-analyzer examples/BigService.java --table full
|
|
407
407
|
|
|
408
408
|
# 🆕 HTML/CSS analysis with new architecture
|
|
409
|
-
uv run
|
|
410
|
-
uv run
|
|
411
|
-
uv run
|
|
409
|
+
uv run tree-sitter-analyzer examples/comprehensive_sample.html --table full
|
|
410
|
+
uv run tree-sitter-analyzer examples/comprehensive_sample.css --advanced --output-format text
|
|
411
|
+
uv run tree-sitter-analyzer examples/comprehensive_sample.html --structure
|
|
412
412
|
|
|
413
413
|
# Precise code extraction
|
|
414
|
-
uv run
|
|
414
|
+
uv run tree-sitter-analyzer examples/BigService.java --partial-read --start-line 93 --end-line 106
|
|
415
415
|
```
|
|
416
416
|
|
|
417
417
|
---
|
|
@@ -744,47 +744,47 @@ The `suppress_output` parameter in the `analyze_code_structure` tool:
|
|
|
744
744
|
|
|
745
745
|
```bash
|
|
746
746
|
# Quick analysis (show summary information)
|
|
747
|
-
uv run
|
|
747
|
+
uv run tree-sitter-analyzer examples/BigService.java --summary
|
|
748
748
|
|
|
749
749
|
# Detailed analysis (show complete structure)
|
|
750
|
-
uv run
|
|
750
|
+
uv run tree-sitter-analyzer examples/BigService.java --structure
|
|
751
751
|
|
|
752
752
|
# Advanced analysis (including complexity metrics)
|
|
753
|
-
uv run
|
|
753
|
+
uv run tree-sitter-analyzer examples/BigService.java --advanced
|
|
754
754
|
|
|
755
755
|
# Generate complete structure table
|
|
756
|
-
uv run
|
|
756
|
+
uv run tree-sitter-analyzer examples/BigService.java --table full
|
|
757
757
|
|
|
758
758
|
# 🆕 HTML/CSS analysis with new architecture
|
|
759
|
-
uv run
|
|
760
|
-
uv run
|
|
761
|
-
uv run
|
|
762
|
-
uv run
|
|
759
|
+
uv run tree-sitter-analyzer examples/comprehensive_sample.html --table full
|
|
760
|
+
uv run tree-sitter-analyzer examples/comprehensive_sample.css --table full
|
|
761
|
+
uv run tree-sitter-analyzer examples/comprehensive_sample.html --advanced
|
|
762
|
+
uv run tree-sitter-analyzer examples/comprehensive_sample.css --advanced
|
|
763
763
|
|
|
764
764
|
# Specify output format
|
|
765
|
-
uv run
|
|
766
|
-
uv run
|
|
765
|
+
uv run tree-sitter-analyzer examples/BigService.java --advanced --output-format json
|
|
766
|
+
uv run tree-sitter-analyzer examples/BigService.java --advanced --output-format text
|
|
767
767
|
|
|
768
768
|
# Precise code extraction
|
|
769
|
-
uv run
|
|
769
|
+
uv run tree-sitter-analyzer examples/BigService.java --partial-read --start-line 93 --end-line 106
|
|
770
770
|
|
|
771
771
|
# Specify programming language
|
|
772
|
-
uv run
|
|
772
|
+
uv run tree-sitter-analyzer script.py --language python --table full
|
|
773
773
|
```
|
|
774
774
|
|
|
775
775
|
#### 🔍 Query and Filter Commands
|
|
776
776
|
|
|
777
777
|
```bash
|
|
778
778
|
# Query specific elements
|
|
779
|
-
uv run
|
|
780
|
-
uv run
|
|
779
|
+
uv run tree-sitter-analyzer examples/BigService.java --query-key methods
|
|
780
|
+
uv run tree-sitter-analyzer examples/BigService.java --query-key classes
|
|
781
781
|
|
|
782
782
|
# 🆕 v1.8.2 Correct Usage Examples
|
|
783
783
|
# Correct: Use --query-key with --filter combination
|
|
784
|
-
uv run
|
|
784
|
+
uv run tree-sitter-analyzer examples/BigService.java --query-key methods --filter "name=main"
|
|
785
785
|
|
|
786
786
|
# Correct: Generate complete structure table
|
|
787
|
-
uv run
|
|
787
|
+
uv run tree-sitter-analyzer examples/BigService.java --table full
|
|
788
788
|
|
|
789
789
|
# 🚫 v1.8.2 Incorrect Usage Examples (will show error)
|
|
790
790
|
# Incorrect: Using --table and --query-key together (exclusive parameters)
|
|
@@ -881,7 +881,7 @@ uv run python -m tree_sitter_analyzer --show-query-languages
|
|
|
881
881
|
| **✂️ Intelligent Code Extraction** | Precision Extraction Tool | Precise extraction by line range<br>Preserves original formatting and indentation<br>Includes position metadata<br>Efficient processing of large files | Zero-loss format preservation<br>Memory-optimized algorithms<br>Streaming processing support |
|
|
882
882
|
| **🔍 Advanced Query Filtering** | Multi-dimensional Filters | **Exact match**: `--filter "name=main"`<br>**Pattern match**: `--filter "name=~auth*"`<br>**Parameter filter**: `--filter "params=2"`<br>**Modifier filter**: `--filter "static=true,public=true"`<br>**Compound conditions**: Combine multiple conditions for precise queries | Flexible query syntax<br>High-performance indexing<br>Intelligent caching mechanisms |
|
|
883
883
|
| **🔗 AI Assistant Integration** | MCP Protocol Support | **Claude Desktop** - Full MCP support<br>**Cursor IDE** - Built-in MCP integration<br>**Roo Code** - MCP protocol support<br>**Other MCP-compatible tools** - Universal MCP server | Standard MCP protocol<br>Plug-and-play design<br>Cross-platform compatibility |
|
|
884
|
-
| **🌍 Multi-language Support** | Enterprise Language Engine | **Java** - Complete support, including Spring, JPA frameworks<br>**Python** - Complete support, including type annotations, decorators<br>**JavaScript** - Enterprise-grade support, including ES6+, React/Vue/Angular, JSX<br>**TypeScript** - **Complete support**, including interfaces, types, decorators, TSX/JSX, framework detection<br>**HTML** - **🆕 Complete support**, including DOM structure, element classification, attribute extraction<br>**CSS** - **🆕 Complete support**, including selector analysis, property classification, style rules<br>**Markdown** - **Complete support**, including headers, code blocks, links, images, tables, task lists, blockquotes<br>**C/C++, Rust, Go
|
|
884
|
+
| **🌍 Multi-language Support** | Enterprise Language Engine | **Java** - Complete support, including Spring, JPA frameworks<br>**Python** - Complete support, including type annotations, decorators<br>**JavaScript** - Enterprise-grade support, including ES6+, React/Vue/Angular, JSX<br>**TypeScript** - **Complete support**, including interfaces, types, decorators, TSX/JSX, framework detection<br>**HTML** - **🆕 Complete support**, including DOM structure, element classification, attribute extraction<br>**CSS** - **🆕 Complete support**, including selector analysis, property classification, style rules<br>**Markdown** - **Complete support**, including headers, code blocks, links, images, tables, task lists, blockquotes<br><br>**Note**: Currently 7 languages have complete plugin implementations (Java, Python, JavaScript, TypeScript, HTML, CSS, Markdown). Languages such as C/C++, Rust, Go are defined but not yet implemented. | Framework-aware parsing<br>Syntax extension support<br>Continuous language updates |
|
|
885
885
|
| **📁 Advanced File Search** | fd+ripgrep Integration | **ListFilesTool** - Intelligent file discovery with multiple filtering conditions<br>**SearchContentTool** - Intelligent content search using regular expressions<br>**FindAndGrepTool** - Combined discovery and search, two-stage workflow | Rust-based high-performance tools<br>Parallel processing capabilities<br>Intelligent cache optimization |
|
|
886
886
|
| **🏗️ Unified Element System** | Revolutionary Architecture Design | **Single element list** - Unified management of all code elements (classes, methods, fields, imports, packages)<br>**Consistent element types** - Each element has an `element_type` attribute<br>**Simplified API** - Clearer interfaces and reduced complexity<br>**Better maintainability** - Single source of truth for all code elements | Unified data model<br>Type safety guarantees<br>Extensible design |
|
|
887
887
|
|
|
@@ -950,16 +950,56 @@ The project maintains high-quality test coverage. For detailed module coverage i
|
|
|
950
950
|
## 9. 📚 Documentation & Support
|
|
951
951
|
|
|
952
952
|
### 📖 Complete Documentation
|
|
953
|
-
This project provides complete documentation support
|
|
953
|
+
This project provides complete documentation support:
|
|
954
954
|
|
|
955
|
+
#### 🎯 Essential Developer Documentation
|
|
956
|
+
- **[Change Management Quick Guide](CHANGE_MANAGEMENT_GUIDE.md)** ⭐ - **PMP vs OpenSpec Usage Rules** (1-minute check)
|
|
957
|
+
- **[PMP-Compliant Document System](docs/ja/README.md)** - Complete guide for project management, feature specifications, and test management
|
|
958
|
+
- [Project Charter](docs/ja/project-management/00_プロジェクト憲章.md) - Overall project vision
|
|
959
|
+
- [Change Management Policy](docs/ja/project-management/05_変更管理方針.md) - Detailed change management rules
|
|
960
|
+
- [Quality Management Plan](docs/ja/project-management/03_品質管理計画.md) - Quality standards and KPIs
|
|
961
|
+
- [Test Strategy](docs/ja/test-management/00_テスト戦略.md) - Testing approach (3,370+ cases)
|
|
962
|
+
|
|
963
|
+
#### 📚 User Documentation
|
|
955
964
|
- **Quick Start Guide** - See the [Quick Start](#3--quick-start) section of this README
|
|
956
965
|
- **MCP Configuration Guide** - See the [AI Users Configuration](#31--ai-users-claude-desktop-cursor-etc) section
|
|
957
966
|
- **CLI Usage Guide** - See the [Complete CLI Commands](#6--complete-cli-commands) section
|
|
958
967
|
- **Core Features Documentation** - See the [Core Features](#7-️-core-features) section
|
|
968
|
+
|
|
969
|
+
#### 🔧 Technical Documentation
|
|
959
970
|
- **Contributing Guide** - See [docs/CONTRIBUTING.md](docs/CONTRIBUTING.md) for development guidelines and document management
|
|
960
971
|
- **Analysis Results** - See [docs/analysis/](docs/analysis/) for project analysis reports and metrics
|
|
961
972
|
- **Feature Specifications** - See [specs/](specs/) for detailed feature specifications and implementation plans
|
|
962
973
|
|
|
974
|
+
### 🔄 MCP Compatibility Testing
|
|
975
|
+
For developers working with multiple versions of tree-sitter-analyzer, we provide a comprehensive compatibility testing framework, now featuring a **Smart JSON Comparison System**.
|
|
976
|
+
|
|
977
|
+
- **[MCP Compatibility Test Standard](docs/mcp_compatibility_test_standard.md)** - Complete standardized process for version compatibility testing
|
|
978
|
+
- **[Compatibility Test Tools](compatibility_test/README.md)** - Automated testing tools and scripts for version comparison
|
|
979
|
+
- **[Troubleshooting Guide](compatibility_test/troubleshooting_guide.md)** - Solutions for common compatibility testing issues
|
|
980
|
+
|
|
981
|
+
**Technical Documentation:**
|
|
982
|
+
- **[MCP Direct Execution Technical Background](compatibility_test/MCP_DIRECT_EXECUTION_TECHNICAL_BACKGROUND.md)** - Technical rationale for why compatibility tests can execute tool classes directly without MCP server
|
|
983
|
+
- **[Smart JSON Comparison System](docs/SMART_JSON_COMPARISON_SYSTEM.md)** - In-depth explanation of the new configuration-driven comparison system.
|
|
984
|
+
|
|
985
|
+
**Key Features:**
|
|
986
|
+
- **Smart JSON Comparison**: Advanced, configuration-driven comparison of complex JSON outputs.
|
|
987
|
+
- **Configuration-Driven**: Use `comparison_config.json` to define comparison rules, ignore fields, and normalize data.
|
|
988
|
+
- **Performance Field Filtering**: Automatically ignores volatile performance fields (e.g., `execution_time`) for stable comparisons.
|
|
989
|
+
- **Array Normalization**: Normalizes and sorts arrays based on a specified key, ensuring order-independent comparisons.
|
|
990
|
+
- **Normalized Output Generation**: Create normalized versions of JSON files for easier manual review and debugging.
|
|
991
|
+
- **Deep Difference Analysis**: Utilizes the `deepdiff` library for granular and interpretable difference reporting.
|
|
992
|
+
|
|
993
|
+
**Quick Start:**
|
|
994
|
+
```bash
|
|
995
|
+
# Run a standard comparison between two versions
|
|
996
|
+
python compatibility_test/scripts/run_compatibility_test.py --version-a 1.9.2 --version-b 1.9.3
|
|
997
|
+
|
|
998
|
+
# Use the smart comparison feature for complex JSON outputs
|
|
999
|
+
python compatibility_test/scripts/analyze_differences.py --version-a 1.9.2 --version-b 1.9.3 --smart-compare --generate-normalized
|
|
1000
|
+
|
|
1001
|
+
```
|
|
1002
|
+
|
|
963
1003
|
### 🤖 AI Collaboration Support
|
|
964
1004
|
This project supports AI-assisted development with professional quality control:
|
|
965
1005
|
|