tree-sitter-analyzer 0.9.9__py3-none-any.whl → 1.0.0__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 +132 -132
- tree_sitter_analyzer/api.py +542 -533
- tree_sitter_analyzer/cli/commands/base_command.py +181 -181
- tree_sitter_analyzer/cli/commands/partial_read_command.py +139 -139
- tree_sitter_analyzer/cli/info_commands.py +124 -121
- tree_sitter_analyzer/cli_main.py +327 -328
- tree_sitter_analyzer/core/analysis_engine.py +584 -584
- tree_sitter_analyzer/file_handler.py +212 -210
- tree_sitter_analyzer/formatters/base_formatter.py +169 -167
- tree_sitter_analyzer/interfaces/cli.py +535 -535
- tree_sitter_analyzer/mcp/server.py +655 -650
- tree_sitter_analyzer/mcp/tools/__init__.py +30 -30
- tree_sitter_analyzer/mcp/utils/path_resolver.py +414 -194
- tree_sitter_analyzer/output_manager.py +257 -253
- tree_sitter_analyzer/project_detector.py +330 -330
- tree_sitter_analyzer/security/boundary_manager.py +260 -251
- tree_sitter_analyzer/security/validator.py +257 -246
- tree_sitter_analyzer/table_formatter.py +710 -708
- tree_sitter_analyzer/utils.py +335 -336
- {tree_sitter_analyzer-0.9.9.dist-info → tree_sitter_analyzer-1.0.0.dist-info}/METADATA +30 -4
- {tree_sitter_analyzer-0.9.9.dist-info → tree_sitter_analyzer-1.0.0.dist-info}/RECORD +23 -23
- {tree_sitter_analyzer-0.9.9.dist-info → tree_sitter_analyzer-1.0.0.dist-info}/WHEEL +0 -0
- {tree_sitter_analyzer-0.9.9.dist-info → tree_sitter_analyzer-1.0.0.dist-info}/entry_points.txt +0 -0
|
@@ -1,167 +1,169 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""
|
|
3
|
-
Base formatter for language-specific table formatting.
|
|
4
|
-
"""
|
|
5
|
-
|
|
6
|
-
import csv
|
|
7
|
-
import io
|
|
8
|
-
import
|
|
9
|
-
from
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
result = self.
|
|
35
|
-
elif self.format_type == "
|
|
36
|
-
result = self.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
str(field.get("
|
|
74
|
-
f"{field.get('
|
|
75
|
-
"",
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
str(method.get("
|
|
90
|
-
|
|
91
|
-
method.get("
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
csv_content =
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
param_strs.append(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
cleaned =
|
|
166
|
-
|
|
167
|
-
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Base formatter for language-specific table formatting.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import csv
|
|
7
|
+
import io
|
|
8
|
+
from abc import ABC, abstractmethod
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class BaseTableFormatter(ABC):
|
|
13
|
+
"""Base class for language-specific table formatters"""
|
|
14
|
+
|
|
15
|
+
def __init__(self, format_type: str = "full"):
|
|
16
|
+
self.format_type = format_type
|
|
17
|
+
|
|
18
|
+
def _get_platform_newline(self) -> str:
|
|
19
|
+
"""Get platform-specific newline code"""
|
|
20
|
+
import os
|
|
21
|
+
|
|
22
|
+
return "\r\n" if os.name == "nt" else "\n" # Windows uses \r\n, others use \n
|
|
23
|
+
|
|
24
|
+
def _convert_to_platform_newlines(self, text: str) -> str:
|
|
25
|
+
"""Convert regular \n to platform-specific newline code"""
|
|
26
|
+
platform_newline = self._get_platform_newline()
|
|
27
|
+
if platform_newline != "\n":
|
|
28
|
+
return text.replace("\n", platform_newline)
|
|
29
|
+
return text
|
|
30
|
+
|
|
31
|
+
def format_structure(self, structure_data: dict[str, Any]) -> str:
|
|
32
|
+
"""Format structure data in table format"""
|
|
33
|
+
if self.format_type == "full":
|
|
34
|
+
result = self._format_full_table(structure_data)
|
|
35
|
+
elif self.format_type == "compact":
|
|
36
|
+
result = self._format_compact_table(structure_data)
|
|
37
|
+
elif self.format_type == "csv":
|
|
38
|
+
result = self._format_csv(structure_data)
|
|
39
|
+
else:
|
|
40
|
+
raise ValueError(f"Unsupported format type: {self.format_type}")
|
|
41
|
+
|
|
42
|
+
# Finally convert to platform-specific newline code
|
|
43
|
+
if self.format_type == "csv":
|
|
44
|
+
return result
|
|
45
|
+
|
|
46
|
+
return self._convert_to_platform_newlines(result)
|
|
47
|
+
|
|
48
|
+
@abstractmethod
|
|
49
|
+
def _format_full_table(self, data: dict[str, Any]) -> str:
|
|
50
|
+
"""Full table format (language-specific implementation)"""
|
|
51
|
+
pass
|
|
52
|
+
|
|
53
|
+
@abstractmethod
|
|
54
|
+
def _format_compact_table(self, data: dict[str, Any]) -> str:
|
|
55
|
+
"""Compact table format (language-specific implementation)"""
|
|
56
|
+
pass
|
|
57
|
+
|
|
58
|
+
def _format_csv(self, data: dict[str, Any]) -> str:
|
|
59
|
+
"""CSV format (common implementation)"""
|
|
60
|
+
output = io.StringIO()
|
|
61
|
+
writer = csv.writer(output, lineterminator="\n")
|
|
62
|
+
|
|
63
|
+
# Header
|
|
64
|
+
writer.writerow(
|
|
65
|
+
["Type", "Name", "Signature", "Visibility", "Lines", "Complexity", "Doc"]
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
# Fields
|
|
69
|
+
for field in data.get("fields", []):
|
|
70
|
+
writer.writerow(
|
|
71
|
+
[
|
|
72
|
+
"Field",
|
|
73
|
+
str(field.get("name", "")),
|
|
74
|
+
f"{str(field.get('name', ''))}:{str(field.get('type', ''))}",
|
|
75
|
+
str(field.get("visibility", "")),
|
|
76
|
+
f"{field.get('line_range', {}).get('start', 0)}-{field.get('line_range', {}).get('end', 0)}",
|
|
77
|
+
"",
|
|
78
|
+
self._clean_csv_text(
|
|
79
|
+
self._extract_doc_summary(str(field.get("javadoc", "")))
|
|
80
|
+
),
|
|
81
|
+
]
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
# Methods
|
|
85
|
+
for method in data.get("methods", []):
|
|
86
|
+
writer.writerow(
|
|
87
|
+
[
|
|
88
|
+
"Constructor" if method.get("is_constructor", False) else "Method",
|
|
89
|
+
str(method.get("name", "")),
|
|
90
|
+
self._clean_csv_text(self._create_full_signature(method)),
|
|
91
|
+
str(method.get("visibility", "")),
|
|
92
|
+
f"{method.get('line_range', {}).get('start', 0)}-{method.get('line_range', {}).get('end', 0)}",
|
|
93
|
+
method.get("complexity_score", 0),
|
|
94
|
+
self._clean_csv_text(
|
|
95
|
+
self._extract_doc_summary(str(method.get("javadoc", "")))
|
|
96
|
+
),
|
|
97
|
+
]
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
csv_content = output.getvalue()
|
|
101
|
+
csv_content = csv_content.replace("\r\n", "\n").replace("\r", "\n")
|
|
102
|
+
csv_content = csv_content.rstrip("\n")
|
|
103
|
+
output.close()
|
|
104
|
+
|
|
105
|
+
return csv_content
|
|
106
|
+
|
|
107
|
+
# Common helper methods
|
|
108
|
+
def _create_full_signature(self, method: dict[str, Any]) -> str:
|
|
109
|
+
"""Create complete method signature"""
|
|
110
|
+
params = method.get("parameters", [])
|
|
111
|
+
param_strs = []
|
|
112
|
+
for param in params:
|
|
113
|
+
if isinstance(param, dict):
|
|
114
|
+
param_type = str(param.get("type", "Object"))
|
|
115
|
+
param_name = str(param.get("name", "param"))
|
|
116
|
+
param_strs.append(f"{param_name}:{param_type}")
|
|
117
|
+
else:
|
|
118
|
+
param_strs.append(str(param))
|
|
119
|
+
|
|
120
|
+
params_str = ", ".join(param_strs)
|
|
121
|
+
return_type = str(method.get("return_type", "void"))
|
|
122
|
+
|
|
123
|
+
modifiers = []
|
|
124
|
+
if method.get("is_static", False):
|
|
125
|
+
modifiers.append("[static]")
|
|
126
|
+
|
|
127
|
+
modifier_str = " ".join(modifiers)
|
|
128
|
+
signature = f"({params_str}):{return_type}"
|
|
129
|
+
|
|
130
|
+
if modifier_str:
|
|
131
|
+
signature += f" {modifier_str}"
|
|
132
|
+
|
|
133
|
+
return signature
|
|
134
|
+
|
|
135
|
+
def _convert_visibility(self, visibility: str) -> str:
|
|
136
|
+
"""Convert visibility to symbol"""
|
|
137
|
+
mapping = {"public": "+", "private": "-", "protected": "#", "package": "~"}
|
|
138
|
+
return mapping.get(visibility, visibility)
|
|
139
|
+
|
|
140
|
+
def _extract_doc_summary(self, javadoc: str) -> str:
|
|
141
|
+
"""Extract summary from documentation"""
|
|
142
|
+
if not javadoc:
|
|
143
|
+
return "-"
|
|
144
|
+
|
|
145
|
+
# Remove comment symbols
|
|
146
|
+
clean_doc = (
|
|
147
|
+
javadoc.replace("/**", "").replace("*/", "").replace("*", "").strip()
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
# Get first line
|
|
151
|
+
lines = clean_doc.split("\n")
|
|
152
|
+
first_line = lines[0].strip()
|
|
153
|
+
|
|
154
|
+
# Truncate if too long
|
|
155
|
+
if len(first_line) > 50:
|
|
156
|
+
first_line = first_line[:47] + "..."
|
|
157
|
+
|
|
158
|
+
return first_line.replace("|", "\\|").replace("\n", " ")
|
|
159
|
+
|
|
160
|
+
def _clean_csv_text(self, text: str) -> str:
|
|
161
|
+
"""Text cleaning for CSV format"""
|
|
162
|
+
if not text:
|
|
163
|
+
return ""
|
|
164
|
+
|
|
165
|
+
cleaned = text.replace("\r\n", " ").replace("\r", " ").replace("\n", " ")
|
|
166
|
+
cleaned = " ".join(cleaned.split())
|
|
167
|
+
cleaned = cleaned.replace('"', '""')
|
|
168
|
+
|
|
169
|
+
return cleaned
|