tree-sitter-analyzer 1.0.0__py3-none-any.whl → 1.1.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.

Files changed (29) hide show
  1. tree_sitter_analyzer/__init__.py +132 -132
  2. tree_sitter_analyzer/api.py +542 -542
  3. tree_sitter_analyzer/cli/commands/base_command.py +181 -181
  4. tree_sitter_analyzer/cli/commands/partial_read_command.py +139 -139
  5. tree_sitter_analyzer/cli/info_commands.py +124 -124
  6. tree_sitter_analyzer/cli_main.py +327 -327
  7. tree_sitter_analyzer/core/analysis_engine.py +584 -584
  8. tree_sitter_analyzer/core/query_service.py +162 -162
  9. tree_sitter_analyzer/file_handler.py +212 -212
  10. tree_sitter_analyzer/formatters/base_formatter.py +169 -169
  11. tree_sitter_analyzer/interfaces/cli.py +535 -535
  12. tree_sitter_analyzer/mcp/__init__.py +1 -1
  13. tree_sitter_analyzer/mcp/resources/__init__.py +1 -1
  14. tree_sitter_analyzer/mcp/resources/project_stats_resource.py +16 -5
  15. tree_sitter_analyzer/mcp/server.py +655 -655
  16. tree_sitter_analyzer/mcp/tools/__init__.py +30 -30
  17. tree_sitter_analyzer/mcp/utils/__init__.py +2 -2
  18. tree_sitter_analyzer/mcp/utils/error_handler.py +569 -569
  19. tree_sitter_analyzer/mcp/utils/path_resolver.py +414 -414
  20. tree_sitter_analyzer/output_manager.py +257 -257
  21. tree_sitter_analyzer/project_detector.py +330 -330
  22. tree_sitter_analyzer/security/boundary_manager.py +260 -260
  23. tree_sitter_analyzer/security/validator.py +257 -257
  24. tree_sitter_analyzer/table_formatter.py +710 -710
  25. tree_sitter_analyzer/utils.py +335 -335
  26. {tree_sitter_analyzer-1.0.0.dist-info → tree_sitter_analyzer-1.1.0.dist-info}/METADATA +11 -11
  27. {tree_sitter_analyzer-1.0.0.dist-info → tree_sitter_analyzer-1.1.0.dist-info}/RECORD +29 -29
  28. {tree_sitter_analyzer-1.0.0.dist-info → tree_sitter_analyzer-1.1.0.dist-info}/WHEEL +0 -0
  29. {tree_sitter_analyzer-1.0.0.dist-info → tree_sitter_analyzer-1.1.0.dist-info}/entry_points.txt +0 -0
@@ -1,169 +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
- 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
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