tree-sitter-analyzer 0.1.0__py3-none-any.whl → 0.1.2__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/interfaces/cli.py +1 -1
- tree_sitter_analyzer/mcp/server.py +45 -19
- tree_sitter_analyzer/mcp/tools/__init__.py +0 -5
- tree_sitter_analyzer/mcp/tools/analyze_scale_tool.py +1 -2
- tree_sitter_analyzer/plugins/python_plugin.py +598 -598
- tree_sitter_analyzer/utils.py +98 -22
- {tree_sitter_analyzer-0.1.0.dist-info → tree_sitter_analyzer-0.1.2.dist-info}/METADATA +69 -206
- {tree_sitter_analyzer-0.1.0.dist-info → tree_sitter_analyzer-0.1.2.dist-info}/RECORD +11 -12
- tree_sitter_analyzer-0.1.2.dist-info/entry_points.txt +8 -0
- tree_sitter_analyzer/mcp/tools/get_positions_tool.py +0 -448
- tree_sitter_analyzer-0.1.0.dist-info/entry_points.txt +0 -8
- {tree_sitter_analyzer-0.1.0.dist-info → tree_sitter_analyzer-0.1.2.dist-info}/WHEEL +0 -0
tree_sitter_analyzer/utils.py
CHANGED
|
@@ -8,6 +8,7 @@ Provides logging, debugging, and common utility functions.
|
|
|
8
8
|
|
|
9
9
|
import logging
|
|
10
10
|
import sys
|
|
11
|
+
import atexit
|
|
11
12
|
from functools import wraps
|
|
12
13
|
from typing import Any, Optional
|
|
13
14
|
|
|
@@ -33,7 +34,8 @@ def setup_logger(
|
|
|
33
34
|
logger = logging.getLogger(name)
|
|
34
35
|
|
|
35
36
|
if not logger.handlers: # Avoid duplicate handlers
|
|
36
|
-
handler
|
|
37
|
+
# Create a safe handler that won't fail on closed streams
|
|
38
|
+
handler = SafeStreamHandler(sys.stdout)
|
|
37
39
|
formatter = logging.Formatter(
|
|
38
40
|
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
|
39
41
|
)
|
|
@@ -44,28 +46,97 @@ def setup_logger(
|
|
|
44
46
|
return logger
|
|
45
47
|
|
|
46
48
|
|
|
49
|
+
class SafeStreamHandler(logging.StreamHandler):
|
|
50
|
+
"""
|
|
51
|
+
A StreamHandler that safely handles closed streams
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
def emit(self, record):
|
|
55
|
+
"""
|
|
56
|
+
Emit a record, safely handling closed streams
|
|
57
|
+
"""
|
|
58
|
+
try:
|
|
59
|
+
# Check if stream is closed before writing
|
|
60
|
+
if hasattr(self.stream, 'closed') and self.stream.closed:
|
|
61
|
+
return
|
|
62
|
+
|
|
63
|
+
# Check if we can write to the stream
|
|
64
|
+
if not hasattr(self.stream, 'write'):
|
|
65
|
+
return
|
|
66
|
+
|
|
67
|
+
super().emit(record)
|
|
68
|
+
except (ValueError, OSError, AttributeError):
|
|
69
|
+
# Silently ignore I/O errors during shutdown
|
|
70
|
+
pass
|
|
71
|
+
except Exception:
|
|
72
|
+
# For any other unexpected errors, use handleError
|
|
73
|
+
self.handleError(record)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def setup_safe_logging_shutdown():
|
|
77
|
+
"""
|
|
78
|
+
Setup safe logging shutdown to prevent I/O errors
|
|
79
|
+
"""
|
|
80
|
+
def cleanup_logging():
|
|
81
|
+
"""Clean up logging handlers safely"""
|
|
82
|
+
try:
|
|
83
|
+
# Get all loggers
|
|
84
|
+
loggers = [logging.getLogger()] + [
|
|
85
|
+
logging.getLogger(name) for name in logging.Logger.manager.loggerDict
|
|
86
|
+
]
|
|
87
|
+
|
|
88
|
+
for logger in loggers:
|
|
89
|
+
for handler in logger.handlers[:]:
|
|
90
|
+
try:
|
|
91
|
+
handler.close()
|
|
92
|
+
logger.removeHandler(handler)
|
|
93
|
+
except:
|
|
94
|
+
pass
|
|
95
|
+
except:
|
|
96
|
+
pass
|
|
97
|
+
|
|
98
|
+
# Register cleanup function
|
|
99
|
+
atexit.register(cleanup_logging)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
# Setup safe shutdown on import
|
|
103
|
+
setup_safe_logging_shutdown()
|
|
104
|
+
|
|
105
|
+
|
|
47
106
|
# Global logger instance
|
|
48
107
|
logger = setup_logger()
|
|
49
108
|
|
|
50
109
|
|
|
51
110
|
def log_info(message: str, *args: Any, **kwargs: Any) -> None:
|
|
52
111
|
"""Log info message"""
|
|
53
|
-
|
|
112
|
+
try:
|
|
113
|
+
logger.info(message, *args, **kwargs)
|
|
114
|
+
except (ValueError, OSError):
|
|
115
|
+
pass # Silently ignore I/O errors
|
|
54
116
|
|
|
55
117
|
|
|
56
118
|
def log_warning(message: str, *args: Any, **kwargs: Any) -> None:
|
|
57
119
|
"""Log warning message"""
|
|
58
|
-
|
|
120
|
+
try:
|
|
121
|
+
logger.warning(message, *args, **kwargs)
|
|
122
|
+
except (ValueError, OSError):
|
|
123
|
+
pass # Silently ignore I/O errors
|
|
59
124
|
|
|
60
125
|
|
|
61
126
|
def log_error(message: str, *args: Any, **kwargs: Any) -> None:
|
|
62
127
|
"""Log error message"""
|
|
63
|
-
|
|
128
|
+
try:
|
|
129
|
+
logger.error(message, *args, **kwargs)
|
|
130
|
+
except (ValueError, OSError):
|
|
131
|
+
pass # Silently ignore I/O errors
|
|
64
132
|
|
|
65
133
|
|
|
66
134
|
def log_debug(message: str, *args: Any, **kwargs: Any) -> None:
|
|
67
135
|
"""Log debug message"""
|
|
68
|
-
|
|
136
|
+
try:
|
|
137
|
+
logger.debug(message, *args, **kwargs)
|
|
138
|
+
except (ValueError, OSError):
|
|
139
|
+
pass # Silently ignore I/O errors
|
|
69
140
|
|
|
70
141
|
|
|
71
142
|
def suppress_output(func: Any) -> Any:
|
|
@@ -79,14 +150,16 @@ def suppress_output(func: Any) -> Any:
|
|
|
79
150
|
|
|
80
151
|
# Redirect stdout to suppress prints
|
|
81
152
|
old_stdout = sys.stdout
|
|
82
|
-
sys.stdout = (
|
|
83
|
-
open("/dev/null", "w") if sys.platform != "win32" else open("nul", "w")
|
|
84
|
-
)
|
|
85
|
-
|
|
86
153
|
try:
|
|
154
|
+
sys.stdout = (
|
|
155
|
+
open("/dev/null", "w") if sys.platform != "win32" else open("nul", "w")
|
|
156
|
+
)
|
|
87
157
|
result = func(*args, **kwargs)
|
|
88
158
|
finally:
|
|
89
|
-
|
|
159
|
+
try:
|
|
160
|
+
sys.stdout.close()
|
|
161
|
+
except:
|
|
162
|
+
pass
|
|
90
163
|
sys.stdout = old_stdout
|
|
91
164
|
|
|
92
165
|
return result
|
|
@@ -133,7 +206,7 @@ def create_performance_logger(name: str) -> logging.Logger:
|
|
|
133
206
|
perf_logger = logging.getLogger(f"{name}.performance")
|
|
134
207
|
|
|
135
208
|
if not perf_logger.handlers:
|
|
136
|
-
handler =
|
|
209
|
+
handler = SafeStreamHandler()
|
|
137
210
|
formatter = logging.Formatter("%(asctime)s - PERF - %(message)s")
|
|
138
211
|
handler.setFormatter(formatter)
|
|
139
212
|
perf_logger.addHandler(handler)
|
|
@@ -152,16 +225,19 @@ def log_performance(
|
|
|
152
225
|
details: Optional[dict] = None,
|
|
153
226
|
) -> None:
|
|
154
227
|
"""Log performance metrics"""
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
if
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
228
|
+
try:
|
|
229
|
+
message = f"{operation}"
|
|
230
|
+
if execution_time is not None:
|
|
231
|
+
message += f": {execution_time:.4f}s"
|
|
232
|
+
if details:
|
|
233
|
+
if isinstance(details, dict):
|
|
234
|
+
detail_str = ", ".join([f"{k}: {v}" for k, v in details.items()])
|
|
235
|
+
else:
|
|
236
|
+
detail_str = str(details)
|
|
237
|
+
message += f" - {detail_str}"
|
|
238
|
+
perf_logger.info(message)
|
|
239
|
+
except (ValueError, OSError):
|
|
240
|
+
pass # Silently ignore I/O errors
|
|
165
241
|
|
|
166
242
|
|
|
167
243
|
def setup_performance_logger() -> logging.Logger:
|
|
@@ -170,7 +246,7 @@ def setup_performance_logger() -> logging.Logger:
|
|
|
170
246
|
|
|
171
247
|
# Add handler if not already configured
|
|
172
248
|
if not perf_logger.handlers:
|
|
173
|
-
handler =
|
|
249
|
+
handler = SafeStreamHandler()
|
|
174
250
|
formatter = logging.Formatter("%(asctime)s - Performance - %(message)s")
|
|
175
251
|
handler.setFormatter(formatter)
|
|
176
252
|
perf_logger.addHandler(handler)
|
|
@@ -1,70 +1,107 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tree-sitter-analyzer
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Extensible multi-language code analyzer framework using Tree-sitter with dynamic plugin architecture
|
|
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
|
|
7
7
|
Project-URL: Repository, https://github.com/aimasteracc/tree-sitter-analyzer.git
|
|
8
8
|
Project-URL: Issues, https://github.com/aimasteracc/tree-sitter-analyzer/issues
|
|
9
9
|
Project-URL: Changelog, https://github.com/aimasteracc/tree-sitter-analyzer/blob/main/CHANGELOG.md
|
|
10
|
+
Project-URL: Bug Reports, https://github.com/aimasteracc/tree-sitter-analyzer/issues
|
|
11
|
+
Project-URL: Source Code, https://github.com/aimasteracc/tree-sitter-analyzer
|
|
10
12
|
Author-email: "aisheng.yu" <aimasteracc@gmail.com>
|
|
11
|
-
|
|
13
|
+
Maintainer-email: "aisheng.yu" <aimasteracc@gmail.com>
|
|
14
|
+
License: MIT
|
|
12
15
|
Keywords: ai-tools,ast,code-analysis,mcp,mcp-server,model-context-protocol,multi-language,parsing,static-analysis,tree-sitter
|
|
13
16
|
Classifier: Development Status :: 4 - Beta
|
|
14
17
|
Classifier: Framework :: AsyncIO
|
|
15
18
|
Classifier: Intended Audience :: Developers
|
|
16
19
|
Classifier: License :: OSI Approved :: MIT License
|
|
20
|
+
Classifier: Operating System :: OS Independent
|
|
17
21
|
Classifier: Programming Language :: Python :: 3
|
|
18
22
|
Classifier: Programming Language :: Python :: 3.10
|
|
19
23
|
Classifier: Programming Language :: Python :: 3.11
|
|
20
24
|
Classifier: Programming Language :: Python :: 3.12
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
26
|
Classifier: Topic :: Communications
|
|
22
27
|
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
23
28
|
Classifier: Topic :: Software Development :: Code Generators
|
|
24
29
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
25
30
|
Classifier: Topic :: Software Development :: Quality Assurance
|
|
26
31
|
Classifier: Topic :: Text Processing :: Linguistic
|
|
32
|
+
Classifier: Typing :: Typed
|
|
27
33
|
Requires-Python: >=3.10
|
|
28
34
|
Requires-Dist: cachetools>=5.0.0
|
|
29
35
|
Requires-Dist: chardet>=5.0.0
|
|
36
|
+
Requires-Dist: tree-sitter-cpp>=0.23.4
|
|
30
37
|
Requires-Dist: tree-sitter-java>=0.23.5
|
|
31
38
|
Requires-Dist: tree-sitter>=0.20.0
|
|
32
|
-
Provides-Extra: all
|
|
33
|
-
Requires-Dist: tree-sitter-c>=0.20.0; extra == 'all'
|
|
34
|
-
Requires-Dist: tree-sitter-cpp>=0.
|
|
35
|
-
Requires-Dist: tree-sitter-go>=0.20.0; extra == 'all'
|
|
36
|
-
Requires-Dist: tree-sitter-java>=0.
|
|
37
|
-
Requires-Dist: tree-sitter-javascript>=0.23.1; extra == 'all'
|
|
38
|
-
Requires-Dist: tree-sitter-python>=0.23.0; extra == 'all'
|
|
39
|
-
Requires-Dist: tree-sitter-rust>=0.20.0; extra == 'all'
|
|
40
|
-
Requires-Dist: tree-sitter-typescript>=0.20.0; extra == 'all'
|
|
39
|
+
Provides-Extra: all-languages
|
|
40
|
+
Requires-Dist: tree-sitter-c>=0.20.0; extra == 'all-languages'
|
|
41
|
+
Requires-Dist: tree-sitter-cpp>=0.23.4; extra == 'all-languages'
|
|
42
|
+
Requires-Dist: tree-sitter-go>=0.20.0; extra == 'all-languages'
|
|
43
|
+
Requires-Dist: tree-sitter-java>=0.23.5; extra == 'all-languages'
|
|
44
|
+
Requires-Dist: tree-sitter-javascript>=0.23.1; extra == 'all-languages'
|
|
45
|
+
Requires-Dist: tree-sitter-python>=0.23.0; extra == 'all-languages'
|
|
46
|
+
Requires-Dist: tree-sitter-rust>=0.20.0; extra == 'all-languages'
|
|
47
|
+
Requires-Dist: tree-sitter-typescript>=0.20.0; extra == 'all-languages'
|
|
41
48
|
Provides-Extra: c
|
|
42
49
|
Requires-Dist: tree-sitter-c>=0.20.0; extra == 'c'
|
|
43
50
|
Provides-Extra: cpp
|
|
44
|
-
Requires-Dist: tree-sitter-cpp>=0.
|
|
51
|
+
Requires-Dist: tree-sitter-cpp>=0.23.4; extra == 'cpp'
|
|
45
52
|
Provides-Extra: dev
|
|
46
|
-
Requires-Dist: black>=
|
|
47
|
-
Requires-Dist: flake8>=
|
|
48
|
-
Requires-Dist: isort>=5.
|
|
53
|
+
Requires-Dist: black>=24.0.0; extra == 'dev'
|
|
54
|
+
Requires-Dist: flake8>=7.0.0; extra == 'dev'
|
|
55
|
+
Requires-Dist: isort>=5.13.0; extra == 'dev'
|
|
49
56
|
Requires-Dist: memory-profiler>=0.61.0; extra == 'dev'
|
|
50
57
|
Requires-Dist: mypy>=1.17.0; extra == 'dev'
|
|
58
|
+
Requires-Dist: pre-commit>=3.0.0; extra == 'dev'
|
|
51
59
|
Requires-Dist: psutil>=7.0.0; extra == 'dev'
|
|
52
60
|
Requires-Dist: pytest-asyncio>=1.1.0; extra == 'dev'
|
|
53
61
|
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
|
|
54
62
|
Requires-Dist: pytest-mock>=3.14.1; extra == 'dev'
|
|
55
|
-
Requires-Dist: pytest>=8.
|
|
63
|
+
Requires-Dist: pytest>=8.4.1; extra == 'dev'
|
|
56
64
|
Requires-Dist: types-psutil>=5.9.0; extra == 'dev'
|
|
65
|
+
Provides-Extra: full
|
|
66
|
+
Requires-Dist: anyio>=4.9.0; extra == 'full'
|
|
67
|
+
Requires-Dist: black>=24.0.0; extra == 'full'
|
|
68
|
+
Requires-Dist: flake8>=7.0.0; extra == 'full'
|
|
69
|
+
Requires-Dist: httpx>=0.28.1; extra == 'full'
|
|
70
|
+
Requires-Dist: isort>=5.13.0; extra == 'full'
|
|
71
|
+
Requires-Dist: mcp>=1.12.2; extra == 'full'
|
|
72
|
+
Requires-Dist: memory-profiler>=0.61.0; extra == 'full'
|
|
73
|
+
Requires-Dist: mypy>=1.17.0; extra == 'full'
|
|
74
|
+
Requires-Dist: pre-commit>=3.0.0; extra == 'full'
|
|
75
|
+
Requires-Dist: psutil>=7.0.0; extra == 'full'
|
|
76
|
+
Requires-Dist: pydantic-settings>=2.10.1; extra == 'full'
|
|
77
|
+
Requires-Dist: pydantic>=2.11.7; extra == 'full'
|
|
78
|
+
Requires-Dist: pytest-asyncio>=1.1.0; extra == 'full'
|
|
79
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == 'full'
|
|
80
|
+
Requires-Dist: pytest-mock>=3.14.1; extra == 'full'
|
|
81
|
+
Requires-Dist: pytest>=8.4.1; extra == 'full'
|
|
82
|
+
Requires-Dist: tree-sitter-c>=0.20.0; extra == 'full'
|
|
83
|
+
Requires-Dist: tree-sitter-cpp>=0.23.4; extra == 'full'
|
|
84
|
+
Requires-Dist: tree-sitter-go>=0.20.0; extra == 'full'
|
|
85
|
+
Requires-Dist: tree-sitter-java>=0.23.5; extra == 'full'
|
|
86
|
+
Requires-Dist: tree-sitter-javascript>=0.23.1; extra == 'full'
|
|
87
|
+
Requires-Dist: tree-sitter-python>=0.23.0; extra == 'full'
|
|
88
|
+
Requires-Dist: tree-sitter-rust>=0.20.0; extra == 'full'
|
|
89
|
+
Requires-Dist: tree-sitter-typescript>=0.20.0; extra == 'full'
|
|
90
|
+
Requires-Dist: types-psutil>=5.9.0; extra == 'full'
|
|
57
91
|
Provides-Extra: go
|
|
58
92
|
Requires-Dist: tree-sitter-go>=0.20.0; extra == 'go'
|
|
59
93
|
Provides-Extra: java
|
|
60
|
-
Requires-Dist: tree-sitter-java>=0.
|
|
94
|
+
Requires-Dist: tree-sitter-java>=0.23.5; extra == 'java'
|
|
61
95
|
Provides-Extra: javascript
|
|
62
96
|
Requires-Dist: tree-sitter-javascript>=0.23.1; extra == 'javascript'
|
|
63
97
|
Provides-Extra: mcp
|
|
64
|
-
Requires-Dist:
|
|
65
|
-
Requires-Dist:
|
|
98
|
+
Requires-Dist: anyio>=4.9.0; extra == 'mcp'
|
|
99
|
+
Requires-Dist: httpx>=0.28.1; extra == 'mcp'
|
|
100
|
+
Requires-Dist: mcp>=1.12.2; extra == 'mcp'
|
|
101
|
+
Requires-Dist: pydantic-settings>=2.10.1; extra == 'mcp'
|
|
102
|
+
Requires-Dist: pydantic>=2.11.7; extra == 'mcp'
|
|
66
103
|
Provides-Extra: popular
|
|
67
|
-
Requires-Dist: tree-sitter-java>=0.
|
|
104
|
+
Requires-Dist: tree-sitter-java>=0.23.5; extra == 'popular'
|
|
68
105
|
Requires-Dist: tree-sitter-javascript>=0.23.1; extra == 'popular'
|
|
69
106
|
Requires-Dist: tree-sitter-python>=0.23.0; extra == 'popular'
|
|
70
107
|
Requires-Dist: tree-sitter-typescript>=0.20.0; extra == 'popular'
|
|
@@ -74,15 +111,16 @@ Provides-Extra: rust
|
|
|
74
111
|
Requires-Dist: tree-sitter-rust>=0.20.0; extra == 'rust'
|
|
75
112
|
Provides-Extra: systems
|
|
76
113
|
Requires-Dist: tree-sitter-c>=0.20.0; extra == 'systems'
|
|
77
|
-
Requires-Dist: tree-sitter-cpp>=0.
|
|
114
|
+
Requires-Dist: tree-sitter-cpp>=0.23.4; extra == 'systems'
|
|
78
115
|
Requires-Dist: tree-sitter-go>=0.20.0; extra == 'systems'
|
|
79
116
|
Requires-Dist: tree-sitter-rust>=0.20.0; extra == 'systems'
|
|
80
117
|
Provides-Extra: test
|
|
81
118
|
Requires-Dist: pytest-asyncio>=1.1.0; extra == 'test'
|
|
82
119
|
Requires-Dist: pytest-cov>=4.0.0; extra == 'test'
|
|
83
120
|
Requires-Dist: pytest-mock>=3.14.1; extra == 'test'
|
|
84
|
-
Requires-Dist: pytest>=8.
|
|
85
|
-
Requires-Dist: tree-sitter-
|
|
121
|
+
Requires-Dist: pytest>=8.4.1; extra == 'test'
|
|
122
|
+
Requires-Dist: tree-sitter-cpp>=0.23.4; extra == 'test'
|
|
123
|
+
Requires-Dist: tree-sitter-java>=0.23.5; extra == 'test'
|
|
86
124
|
Requires-Dist: tree-sitter-javascript>=0.23.1; extra == 'test'
|
|
87
125
|
Requires-Dist: tree-sitter-python>=0.23.0; extra == 'test'
|
|
88
126
|
Provides-Extra: typescript
|
|
@@ -96,7 +134,7 @@ Description-Content-Type: text/markdown
|
|
|
96
134
|
|
|
97
135
|
[](https://python.org)
|
|
98
136
|
[](LICENSE)
|
|
99
|
-
[](#测试)
|
|
100
138
|
|
|
101
139
|
An extensible multi-language code analyzer framework using Tree-sitter with dynamic plugin architecture, designed to solve the problem of large code files exceeding LLM single-pass token limits.
|
|
102
140
|
|
|
@@ -135,7 +173,6 @@ cd tree-sitter-analyzer
|
|
|
135
173
|
|
|
136
174
|
# Install with Java support
|
|
137
175
|
uv sync
|
|
138
|
-
uv add tree-sitter-java
|
|
139
176
|
|
|
140
177
|
# With popular languages (Java, Python, JavaScript, TypeScript)
|
|
141
178
|
uv sync --extra popular
|
|
@@ -147,26 +184,19 @@ uv sync --extra mcp
|
|
|
147
184
|
uv sync --extra all --extra mcp
|
|
148
185
|
```
|
|
149
186
|
|
|
150
|
-
### Alternative: Using pip
|
|
151
|
-
|
|
152
|
-
```bash
|
|
153
|
-
# After the project is published to PyPI
|
|
154
|
-
pip install "tree-sitter-analyzer[java]"
|
|
155
|
-
```
|
|
156
|
-
|
|
157
187
|
## Usage
|
|
158
188
|
|
|
159
189
|
### CLI Commands
|
|
160
190
|
|
|
161
191
|
```bash
|
|
162
192
|
# Code scale analysis
|
|
163
|
-
python -m tree_sitter_analyzer examples/Sample.java --advanced --output-format=text
|
|
193
|
+
uv run python -m tree_sitter_analyzer examples/Sample.java --advanced --output-format=text
|
|
164
194
|
|
|
165
195
|
# Partial code extraction
|
|
166
|
-
python -m tree_sitter_analyzer examples/Sample.java --partial-read --start-line 84 --end-line 86
|
|
196
|
+
uv run python -m tree_sitter_analyzer examples/Sample.java --partial-read --start-line 84 --end-line 86
|
|
167
197
|
|
|
168
198
|
# Position information table
|
|
169
|
-
python -m tree_sitter_analyzer examples/Sample.java --table=full
|
|
199
|
+
uv run python -m tree_sitter_analyzer examples/Sample.java --table=full
|
|
170
200
|
```
|
|
171
201
|
|
|
172
202
|
#### CLI Output Examples
|
|
@@ -174,7 +204,7 @@ python -m tree_sitter_analyzer examples/Sample.java --table=full
|
|
|
174
204
|
**Code Scale Analysis (`--advanced --output-format=text`):**
|
|
175
205
|
|
|
176
206
|
>```
|
|
177
|
-
>PS C:\git-public\tree-sitter-analyzer> python -m tree_sitter_analyzer examples/Sample.java --advanced --output-format=text
|
|
207
|
+
>PS C:\git-public\tree-sitter-analyzer> uv run python -m tree_sitter_analyzer examples/Sample.java --advanced --output-format=text
|
|
178
208
|
>2025-07-30 16:57:47,827 - tree_sitter_analyzer - INFO - Successfully loaded 3 language plugins: java, javascript, python
|
|
179
209
|
>2025-07-30 16:57:47,916 - tree_sitter_analyzer - INFO - CacheService initialized: L1=100, L2=1000, L3=10000, TTL=3600s
|
|
180
210
|
>2025-07-30 16:57:47,917 - tree_sitter_analyzer - INFO - Loading plugins...
|
|
@@ -204,7 +234,7 @@ python -m tree_sitter_analyzer examples/Sample.java --table=full
|
|
|
204
234
|
|
|
205
235
|
**Partial Code Extraction (`--partial-read`):**
|
|
206
236
|
>```
|
|
207
|
-
>PS C:\git-public\tree-sitter-analyzer> python -m tree_sitter_analyzer examples/Sample.java --partial-read --start-line 84 --end-line 86
|
|
237
|
+
>PS C:\git-public\tree-sitter-analyzer> uv run python -m tree_sitter_analyzer examples/Sample.java --partial-read --start-line 84 --end-line 86
|
|
208
238
|
>2025-07-30 16:58:22,948 - tree_sitter_analyzer - INFO - Successfully loaded 3 language plugins: java, javascript, python
|
|
209
239
|
>2025-07-30 16:58:23,056 - tree_sitter_analyzer - INFO - Successfully read partial file examples/Sample.java: lines 84-86
|
|
210
240
|
>{
|
|
@@ -284,14 +314,8 @@ The `--table=full` command produces detailed analysis tables:
|
|
|
284
314
|
|
|
285
315
|
The Tree-sitter Analyzer provides an MCP (Model Context Protocol) server that enables AI assistants to analyze code files directly.
|
|
286
316
|
|
|
287
|
-
```bash
|
|
288
|
-
# Start MCP server
|
|
289
|
-
python -m tree_sitter_analyzer.mcp.server
|
|
290
|
-
```
|
|
291
317
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
### MCP Configuration
|
|
318
|
+
#### MCP Configuration
|
|
295
319
|
|
|
296
320
|
Add to your Claude Desktop config file:
|
|
297
321
|
|
|
@@ -318,8 +342,7 @@ Add to your Claude Desktop config file:
|
|
|
318
342
|
1. **analyze_code_scale** - Get code scale and complexity metrics
|
|
319
343
|
2. **format_table** - Generate table-formatted analysis (equivalent to CLI `--table=full`)
|
|
320
344
|
3. **read_code_partial** - Extract specific line ranges from files
|
|
321
|
-
4. **
|
|
322
|
-
5. **analyze_code_universal** - Universal code analysis with automatic language detection
|
|
345
|
+
4. **analyze_code_universal** - Universal code analysis with automatic language detection
|
|
323
346
|
|
|
324
347
|
#### MCP Usage Examples
|
|
325
348
|
|
|
@@ -398,168 +421,8 @@ Add to your Claude Desktop config file:
|
|
|
398
421
|
>{
|
|
399
422
|
> "partial_content_result": "--- 部分読み込み結果 ---\nファイル: examples/Sample.java\n範囲: 行 84-86\n読み込み文字数: 117\n{\n \"file_path\": >\"examples/Sample.java\",\n \"range\": {\n \"start_line\": 84,\n \"end_line\": 86,\n \"start_column\": null,\n \"end_column\": >null\n },\n \"content\": \" public void innerMethod() {\\n System.out.println(\\\"Inner class method, value: \\\" + >value);\\n }\\n\",\n \"content_length\": 117\n}"
|
|
400
423
|
>}
|
|
401
|
-
>```
|
|
402
424
|
|
|
403
425
|
|
|
404
|
-
**Get Code Positions:**
|
|
405
|
-
```json
|
|
406
|
-
{
|
|
407
|
-
"tool": "get_code_positions",
|
|
408
|
-
"arguments": {
|
|
409
|
-
"file_path": "examples/Sample.java",
|
|
410
|
-
"element_types": ["methods", "classes"],
|
|
411
|
-
"include_details": true
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
```
|
|
415
|
-
>```json
|
|
416
|
-
>{
|
|
417
|
-
> "file_path": "examples/Sample.java",
|
|
418
|
-
> "language": "java",
|
|
419
|
-
> "element_types": [
|
|
420
|
-
> "methods",
|
|
421
|
-
> "classes"
|
|
422
|
-
> ],
|
|
423
|
-
> "include_details": true,
|
|
424
|
-
> "format": "json",
|
|
425
|
-
> "total_elements": 32,
|
|
426
|
-
> "positions": {
|
|
427
|
-
> "methods": [
|
|
428
|
-
> {
|
|
429
|
-
> "name": "abstractMethod",
|
|
430
|
-
> "start_line": 9,
|
|
431
|
-
> "end_line": 9,
|
|
432
|
-
> "start_column": 0,
|
|
433
|
-
> "end_column": 0,
|
|
434
|
-
> "signature": "abstractMethod()",
|
|
435
|
-
> "return_type": "void",
|
|
436
|
-
> "visibility": "package",
|
|
437
|
-
> "is_static": false,
|
|
438
|
-
> "is_constructor": false,
|
|
439
|
-
> "complexity": 1,
|
|
440
|
-
> "annotations": []
|
|
441
|
-
> },
|
|
442
|
-
> ...
|
|
443
|
-
> {
|
|
444
|
-
> "name": "createList",
|
|
445
|
-
> "start_line": 154,
|
|
446
|
-
> "end_line": 158,
|
|
447
|
-
> "start_column": 0,
|
|
448
|
-
> "end_column": 0,
|
|
449
|
-
> "signature": "createList(T item)",
|
|
450
|
-
> "return_type": "List<T>",
|
|
451
|
-
> "visibility": "public",
|
|
452
|
-
> "is_static": false,
|
|
453
|
-
> "is_constructor": false,
|
|
454
|
-
> "complexity": 1,
|
|
455
|
-
> "annotations": []
|
|
456
|
-
> }
|
|
457
|
-
> ],
|
|
458
|
-
> "classes": [
|
|
459
|
-
> {
|
|
460
|
-
> "name": "AbstractParentClass",
|
|
461
|
-
> "start_line": 7,
|
|
462
|
-
> "end_line": 15,
|
|
463
|
-
> "start_column": 0,
|
|
464
|
-
> "end_column": 0,
|
|
465
|
-
> "type": "class",
|
|
466
|
-
> "visibility": "package",
|
|
467
|
-
> "extends": null,
|
|
468
|
-
> "implements": [],
|
|
469
|
-
> "annotations": []
|
|
470
|
-
> },
|
|
471
|
-
> {
|
|
472
|
-
> "name": "ParentClass",
|
|
473
|
-
> "start_line": 18,
|
|
474
|
-
> "end_line": 45,
|
|
475
|
-
> "start_column": 0,
|
|
476
|
-
> "end_column": 0,
|
|
477
|
-
> "type": "class",
|
|
478
|
-
> "visibility": "package",
|
|
479
|
-
> "extends": "AbstractParentClass",
|
|
480
|
-
> "implements": [],
|
|
481
|
-
> "annotations": []
|
|
482
|
-
> },
|
|
483
|
-
> {
|
|
484
|
-
> "name": "TestInterface",
|
|
485
|
-
> "start_line": 48,
|
|
486
|
-
> "end_line": 64,
|
|
487
|
-
> "start_column": 0,
|
|
488
|
-
> "end_column": 0,
|
|
489
|
-
> "type": "interface",
|
|
490
|
-
> "visibility": "package",
|
|
491
|
-
> "extends": null,
|
|
492
|
-
> "implements": [],
|
|
493
|
-
> "annotations": []
|
|
494
|
-
> },
|
|
495
|
-
> {
|
|
496
|
-
> "name": "AnotherInterface",
|
|
497
|
-
> "start_line": 67,
|
|
498
|
-
> "end_line": 69,
|
|
499
|
-
> "start_column": 0,
|
|
500
|
-
> "end_column": 0,
|
|
501
|
-
> "type": "interface",
|
|
502
|
-
> "visibility": "package",
|
|
503
|
-
> "extends": null,
|
|
504
|
-
> "implements": [],
|
|
505
|
-
> "annotations": []
|
|
506
|
-
> },
|
|
507
|
-
> {
|
|
508
|
-
> "name": "Test",
|
|
509
|
-
> "start_line": 72,
|
|
510
|
-
> "end_line": 159,
|
|
511
|
-
> "start_column": 0,
|
|
512
|
-
> "end_column": 0,
|
|
513
|
-
> "type": "class",
|
|
514
|
-
> "visibility": "public",
|
|
515
|
-
> "extends": "ParentClass",
|
|
516
|
-
> "implements": [
|
|
517
|
-
> "TestInterface",
|
|
518
|
-
> "AnotherInterface"
|
|
519
|
-
> ],
|
|
520
|
-
> "annotations": []
|
|
521
|
-
> },
|
|
522
|
-
> {
|
|
523
|
-
> "name": "InnerClass",
|
|
524
|
-
> "start_line": 83,
|
|
525
|
-
> "end_line": 87,
|
|
526
|
-
> "start_column": 0,
|
|
527
|
-
> "end_column": 0,
|
|
528
|
-
> "type": "class",
|
|
529
|
-
> "visibility": "public",
|
|
530
|
-
> "extends": null,
|
|
531
|
-
> "implements": [],
|
|
532
|
-
> "annotations": []
|
|
533
|
-
> },
|
|
534
|
-
> {
|
|
535
|
-
> "name": "StaticNestedClass",
|
|
536
|
-
> "start_line": 90,
|
|
537
|
-
> "end_line": 94,
|
|
538
|
-
> "start_column": 0,
|
|
539
|
-
> "end_column": 0,
|
|
540
|
-
> "type": "class",
|
|
541
|
-
> "visibility": "public",
|
|
542
|
-
> "extends": null,
|
|
543
|
-
> "implements": [],
|
|
544
|
-
> "annotations": []
|
|
545
|
-
> },
|
|
546
|
-
> {
|
|
547
|
-
> "name": "TestEnum",
|
|
548
|
-
> "start_line": 162,
|
|
549
|
-
> "end_line": 178,
|
|
550
|
-
> "start_column": 0,
|
|
551
|
-
> "end_column": 0,
|
|
552
|
-
> "type": "enum",
|
|
553
|
-
> "visibility": "package",
|
|
554
|
-
> "extends": null,
|
|
555
|
-
> "implements": [],
|
|
556
|
-
> "annotations": []
|
|
557
|
-
> }
|
|
558
|
-
> ]
|
|
559
|
-
> }
|
|
560
|
-
> }
|
|
561
|
-
> ```
|
|
562
|
-
|
|
563
426
|
## Development
|
|
564
427
|
|
|
565
428
|
For developers and contributors:
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
tree_sitter_analyzer/__init__.py,sha256=
|
|
1
|
+
tree_sitter_analyzer/__init__.py,sha256=cA9bBIShO4xoQxwSKWBt--EN4G4OCfDSBlkE0Kms6zc,3003
|
|
2
2
|
tree_sitter_analyzer/__main__.py,sha256=25E8WFUzTFAYqwT5Pdlq6cn8Aa25ogHP3w_5ybbHbNc,317
|
|
3
3
|
tree_sitter_analyzer/api.py,sha256=-Np6khuxbzBA_T2FN-Z8WDEXz7260OcwKIMP3iz2Kaw,17870
|
|
4
4
|
tree_sitter_analyzer/cli_main.py,sha256=G75GblQnD-k_hJTOhMV31bUB_yApEfpBgAhO-67BLbU,9748
|
|
@@ -12,7 +12,7 @@ tree_sitter_analyzer/models.py,sha256=2JZAQXM4nJVu7rfnsZFwpvPpv8fpk0POVHKCKeOMLM
|
|
|
12
12
|
tree_sitter_analyzer/output_manager.py,sha256=dh_yfAmvn-XuF7RP5DM5vnqHGRzBUDOsuiVvTjcaOwg,8769
|
|
13
13
|
tree_sitter_analyzer/query_loader.py,sha256=KrpNnf-plrtymDAfUF6ukw8ELtGWnqhikwPLW_z9vY8,10225
|
|
14
14
|
tree_sitter_analyzer/table_formatter.py,sha256=FpYywpJOkXv3FfHEDFSWjfP5ZFa1WJZ6QqN_H0YtUC4,18274
|
|
15
|
-
tree_sitter_analyzer/utils.py,sha256=
|
|
15
|
+
tree_sitter_analyzer/utils.py,sha256=mL-TexPDTmapE3x7UErVQEJjXWn613KibPbZwgTpkd0,8332
|
|
16
16
|
tree_sitter_analyzer/cli/__init__.py,sha256=zCYwQW0hKFfZ4w-qoSOnqVKZGtdZ-ziH60Ax0QBE2iQ,886
|
|
17
17
|
tree_sitter_analyzer/cli/__main__.py,sha256=Sa02Ye57FhkDVTlGrb6U3m9V6II_TIuyzoQIwZtBkZ0,254
|
|
18
18
|
tree_sitter_analyzer/cli/info_commands.py,sha256=B9fBryAJ2Ctt-wo8Tko86BKOfFCCBPhAWz9vz_3r1fs,4521
|
|
@@ -37,7 +37,7 @@ tree_sitter_analyzer/formatters/formatter_factory.py,sha256=_jw9Emd7t0vM3DroJwBx
|
|
|
37
37
|
tree_sitter_analyzer/formatters/java_formatter.py,sha256=HmbQJgYsswg3whZ61p-M_CuHxg72yY-EtszOBVnjsw8,11285
|
|
38
38
|
tree_sitter_analyzer/formatters/python_formatter.py,sha256=Fz84SHDExP2nSx3Iq43XbbY8Z9dWYQj5zJS9cmPLysA,9898
|
|
39
39
|
tree_sitter_analyzer/interfaces/__init__.py,sha256=YrVFjBhhOkcJ4bRGmQnRBHwOSyPUsBLVy77Bc9eUYC8,303
|
|
40
|
-
tree_sitter_analyzer/interfaces/cli.py,sha256=
|
|
40
|
+
tree_sitter_analyzer/interfaces/cli.py,sha256=hTAIFew7yq9a9ejWnyGnwFHqadzckWXT-EaX-Q-La7I,17832
|
|
41
41
|
tree_sitter_analyzer/interfaces/cli_adapter.py,sha256=0lxm8dQuzTohlXptFq2bZEjnL7YAmOnli2iN3C8V0TA,11461
|
|
42
42
|
tree_sitter_analyzer/interfaces/mcp_adapter.py,sha256=vZcZy5FRYrSjJkRvdyu28OtqoESwiXkTqH9Nv7irRqM,6515
|
|
43
43
|
tree_sitter_analyzer/interfaces/mcp_server.py,sha256=3zj02Ur00ceJvKSG5bkuxlU2bHLaiCWjW2367dNPlLM,16907
|
|
@@ -45,15 +45,14 @@ tree_sitter_analyzer/languages/__init__.py,sha256=MAZEb-ifvdttqAQts_n3Cj9jtMd1cy
|
|
|
45
45
|
tree_sitter_analyzer/languages/java_plugin.py,sha256=2VdS2ZoNhd8q-Dqlc08vpfhoGqpN-vqEkRkFF4uuczE,46174
|
|
46
46
|
tree_sitter_analyzer/languages/python_plugin.py,sha256=to_mg-x4nJZO27i7geP5sTmHCLXiv2_gjFCCPB0ELZU,28839
|
|
47
47
|
tree_sitter_analyzer/mcp/__init__.py,sha256=QX4WA9HrxASLW1q-aVKhmXyONBy__2X9jOj9YctEj9Q,783
|
|
48
|
-
tree_sitter_analyzer/mcp/server.py,sha256=
|
|
48
|
+
tree_sitter_analyzer/mcp/server.py,sha256=37dnVBM3Qm0k6jXh1DP7FgAOraJDo5MuDe-8s88qPYM,13086
|
|
49
49
|
tree_sitter_analyzer/mcp/resources/__init__.py,sha256=caWz1n3l22IaxBZ1plSjIUfroassWNNDRWEwEp1vaMw,1490
|
|
50
50
|
tree_sitter_analyzer/mcp/resources/code_file_resource.py,sha256=p3XrTAHPasl92f7mdiWnRv2nl338GPeKlYdCIzLyYqg,6541
|
|
51
51
|
tree_sitter_analyzer/mcp/resources/project_stats_resource.py,sha256=CkvfOSr7Bk6mJlJt-MkXw3kmUC0VAAsw8w1-AcGO0ek,19854
|
|
52
|
-
tree_sitter_analyzer/mcp/tools/__init__.py,sha256=
|
|
53
|
-
tree_sitter_analyzer/mcp/tools/analyze_scale_tool.py,sha256=
|
|
52
|
+
tree_sitter_analyzer/mcp/tools/__init__.py,sha256=MBX4-SX8gfUyEGs_BlsOD4toRosvw-rJt2ezD1HrSME,829
|
|
53
|
+
tree_sitter_analyzer/mcp/tools/analyze_scale_tool.py,sha256=Bya1dsy4a-aTzyYSI32NDUgMbIVCFWpYXMtloGHx1V0,23448
|
|
54
54
|
tree_sitter_analyzer/mcp/tools/analyze_scale_tool_cli_compatible.py,sha256=xwXuy72FEfoY2TW6URddfdS9Ha_lq8_ZgG0UxC26mLM,8954
|
|
55
55
|
tree_sitter_analyzer/mcp/tools/base_tool.py,sha256=LpY_QPWbpm8ZGe3SPK7TIBFZMiwkUMpHa8zcswld2ag,1295
|
|
56
|
-
tree_sitter_analyzer/mcp/tools/get_positions_tool.py,sha256=wjRU26w1F5ta-uZ8IrU6Re3zeGmNAHhz8uAMkuQpoxs,16914
|
|
57
56
|
tree_sitter_analyzer/mcp/tools/read_partial_tool.py,sha256=Xkk90JVFpZfW3cPyHLo1OpU8Fq671RPOO_zGbTmcrdM,11116
|
|
58
57
|
tree_sitter_analyzer/mcp/tools/table_format_tool.py,sha256=IUF7N5Je_rV88RkEVz5wet37PZLaDdzXoAC5j1xI3EI,14428
|
|
59
58
|
tree_sitter_analyzer/mcp/tools/universal_analyze_tool.py,sha256=asH_2BLzT-ACLLampyHF61WFn5nSVKL94wE0mU-uui8,19635
|
|
@@ -65,14 +64,14 @@ tree_sitter_analyzer/plugins/java_plugin.py,sha256=9wAjLoj6uEsLupUz7l7xp5VppLG5T
|
|
|
65
64
|
tree_sitter_analyzer/plugins/javascript_plugin.py,sha256=7LfNfuA-ygl_M5PbJz-QPMf7mnmGYRfSqrFwujiVhuo,16031
|
|
66
65
|
tree_sitter_analyzer/plugins/manager.py,sha256=BjhdgNhS8ev2YtrG_awusNxmRXJSn6p5PraH5cLRhMk,12521
|
|
67
66
|
tree_sitter_analyzer/plugins/plugin_loader.py,sha256=KZYEJCUo1w3w83YWRIh2lI1TRoS0CDQAtXWhdKrrVjM,2478
|
|
68
|
-
tree_sitter_analyzer/plugins/python_plugin.py,sha256=
|
|
67
|
+
tree_sitter_analyzer/plugins/python_plugin.py,sha256=hssiKuoRWefUwnaGBJNsfkplvMSfYm_VIfeWfBZ3bho,24055
|
|
69
68
|
tree_sitter_analyzer/plugins/registry.py,sha256=ifKlvD4IFcwcvKcAoIJRVlLel-pg6ey97i1Nx_uic7s,12048
|
|
70
69
|
tree_sitter_analyzer/queries/__init__.py,sha256=HavpqPqK5M4j8PjRWgkUm_9fTHqftDCHuz2zcG63Cc4,747
|
|
71
70
|
tree_sitter_analyzer/queries/java.py,sha256=hmaj7jKQ_m9nmOAnyiWQhzH-6g41xIi3fwt5ZTUTrQQ,12979
|
|
72
71
|
tree_sitter_analyzer/queries/javascript.py,sha256=TSe6uSHhBuQU0r2B8YBqpEYkU4q9CYRuTUqRK0WfM5o,4183
|
|
73
72
|
tree_sitter_analyzer/queries/python.py,sha256=V5MsKmI9A_FqAT2PKkrSL_Xp9bGKBUSpyVPoBmLxxWg,8018
|
|
74
73
|
tree_sitter_analyzer/queries/typescript.py,sha256=T8a9PwqqGkwLr8clVsAfu0IUIrLKH8u4sBqlU1Cz-FE,7138
|
|
75
|
-
tree_sitter_analyzer-0.1.
|
|
76
|
-
tree_sitter_analyzer-0.1.
|
|
77
|
-
tree_sitter_analyzer-0.1.
|
|
78
|
-
tree_sitter_analyzer-0.1.
|
|
74
|
+
tree_sitter_analyzer-0.1.2.dist-info/METADATA,sha256=4-E88N1Heaj0njiSxzLbhoQf8DxmQKeFxoOgfLyZ2p0,18438
|
|
75
|
+
tree_sitter_analyzer-0.1.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
76
|
+
tree_sitter_analyzer-0.1.2.dist-info/entry_points.txt,sha256=-XEh1racqnCT30mhKWMv5-bgX0iqd_J6b08lZS9J4eg,336
|
|
77
|
+
tree_sitter_analyzer-0.1.2.dist-info/RECORD,,
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
[console_scripts]
|
|
2
|
+
code-analyzer = tree_sitter_analyzer.cli_main:main
|
|
3
|
+
java-analyzer = tree_sitter_analyzer.cli_main:main
|
|
4
|
+
tree-sitter-analyzer = tree_sitter_analyzer.cli_main:main
|
|
5
|
+
|
|
6
|
+
[tree_sitter_analyzer.plugins]
|
|
7
|
+
java = tree_sitter_analyzer.languages.java_plugin:JavaPlugin
|
|
8
|
+
python = tree_sitter_analyzer.plugins.python_plugin:PythonPlugin
|