tree-sitter-analyzer 0.9.4__py3-none-any.whl → 0.9.6__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/cli/commands/query_command.py +50 -35
- tree_sitter_analyzer/cli_main.py +21 -0
- tree_sitter_analyzer/core/query_filter.py +200 -0
- tree_sitter_analyzer/core/query_service.py +162 -0
- tree_sitter_analyzer/encoding_utils.py +7 -4
- tree_sitter_analyzer/mcp/resources/code_file_resource.py +1 -2
- tree_sitter_analyzer/mcp/server.py +7 -1
- tree_sitter_analyzer/mcp/tools/query_tool.py +238 -0
- tree_sitter_analyzer/queries/java.py +5 -0
- tree_sitter_analyzer/security/boundary_manager.py +10 -2
- tree_sitter_analyzer/table_formatter.py +6 -1
- tree_sitter_analyzer/utils.py +51 -40
- tree_sitter_analyzer-0.9.6.dist-info/METADATA +631 -0
- {tree_sitter_analyzer-0.9.4.dist-info → tree_sitter_analyzer-0.9.6.dist-info}/RECORD +17 -14
- tree_sitter_analyzer-0.9.4.dist-info/METADATA +0 -409
- {tree_sitter_analyzer-0.9.4.dist-info → tree_sitter_analyzer-0.9.6.dist-info}/WHEEL +0 -0
- {tree_sitter_analyzer-0.9.4.dist-info → tree_sitter_analyzer-0.9.6.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,631 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tree-sitter-analyzer
|
|
3
|
+
Version: 0.9.6
|
|
4
|
+
Summary: Extensible multi-language code analyzer framework using Tree-sitter with dynamic plugin architecture
|
|
5
|
+
Project-URL: Homepage, https://github.com/aimasteracc/tree-sitter-analyzer
|
|
6
|
+
Project-URL: Documentation, https://github.com/aimasteracc/tree-sitter-analyzer#readme
|
|
7
|
+
Project-URL: Repository, https://github.com/aimasteracc/tree-sitter-analyzer.git
|
|
8
|
+
Project-URL: Issues, https://github.com/aimasteracc/tree-sitter-analyzer/issues
|
|
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
|
|
12
|
+
Author-email: "aisheng.yu" <aimasteracc@gmail.com>
|
|
13
|
+
Maintainer-email: "aisheng.yu" <aimasteracc@gmail.com>
|
|
14
|
+
License: MIT
|
|
15
|
+
Keywords: ai-tools,ast,code-analysis,mcp,mcp-server,model-context-protocol,multi-language,parsing,static-analysis,tree-sitter
|
|
16
|
+
Classifier: Development Status :: 4 - Beta
|
|
17
|
+
Classifier: Framework :: AsyncIO
|
|
18
|
+
Classifier: Intended Audience :: Developers
|
|
19
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
20
|
+
Classifier: Operating System :: OS Independent
|
|
21
|
+
Classifier: Programming Language :: Python :: 3
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
26
|
+
Classifier: Topic :: Communications
|
|
27
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
28
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
29
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
30
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
31
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
32
|
+
Classifier: Typing :: Typed
|
|
33
|
+
Requires-Python: >=3.10
|
|
34
|
+
Requires-Dist: cachetools>=5.0.0
|
|
35
|
+
Requires-Dist: chardet>=5.0.0
|
|
36
|
+
Requires-Dist: mcp>=1.12.3
|
|
37
|
+
Requires-Dist: tree-sitter-cpp>=0.23.4
|
|
38
|
+
Requires-Dist: tree-sitter-java>=0.23.5
|
|
39
|
+
Requires-Dist: tree-sitter-javascript>=0.23.1
|
|
40
|
+
Requires-Dist: tree-sitter-python>=0.23.6
|
|
41
|
+
Requires-Dist: tree-sitter==0.24.0
|
|
42
|
+
Provides-Extra: all-languages
|
|
43
|
+
Requires-Dist: tree-sitter-c>=0.20.0; extra == 'all-languages'
|
|
44
|
+
Requires-Dist: tree-sitter-cpp>=0.23.4; extra == 'all-languages'
|
|
45
|
+
Requires-Dist: tree-sitter-go>=0.20.0; extra == 'all-languages'
|
|
46
|
+
Requires-Dist: tree-sitter-java>=0.23.5; extra == 'all-languages'
|
|
47
|
+
Requires-Dist: tree-sitter-javascript>=0.23.1; extra == 'all-languages'
|
|
48
|
+
Requires-Dist: tree-sitter-python>=0.23.0; extra == 'all-languages'
|
|
49
|
+
Requires-Dist: tree-sitter-rust>=0.20.0; extra == 'all-languages'
|
|
50
|
+
Requires-Dist: tree-sitter-typescript>=0.20.0; extra == 'all-languages'
|
|
51
|
+
Provides-Extra: c
|
|
52
|
+
Requires-Dist: tree-sitter-c>=0.20.0; extra == 'c'
|
|
53
|
+
Provides-Extra: cpp
|
|
54
|
+
Requires-Dist: tree-sitter-cpp>=0.23.4; extra == 'cpp'
|
|
55
|
+
Provides-Extra: dev
|
|
56
|
+
Requires-Dist: black>=24.0.0; extra == 'dev'
|
|
57
|
+
Requires-Dist: isort>=5.13.0; extra == 'dev'
|
|
58
|
+
Requires-Dist: memory-profiler>=0.61.0; extra == 'dev'
|
|
59
|
+
Requires-Dist: mypy>=1.17.0; extra == 'dev'
|
|
60
|
+
Requires-Dist: pre-commit>=3.0.0; extra == 'dev'
|
|
61
|
+
Requires-Dist: psutil<6,>=5.9.6; extra == 'dev'
|
|
62
|
+
Requires-Dist: pytest-asyncio>=1.1.0; extra == 'dev'
|
|
63
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
|
|
64
|
+
Requires-Dist: pytest-mock>=3.14.1; extra == 'dev'
|
|
65
|
+
Requires-Dist: pytest>=8.4.1; extra == 'dev'
|
|
66
|
+
Requires-Dist: ruff>=0.5.0; extra == 'dev'
|
|
67
|
+
Requires-Dist: types-psutil>=5.9.0; extra == 'dev'
|
|
68
|
+
Provides-Extra: full
|
|
69
|
+
Requires-Dist: anyio>=4.0.0; extra == 'full'
|
|
70
|
+
Requires-Dist: black>=24.0.0; extra == 'full'
|
|
71
|
+
Requires-Dist: httpx<1.0.0,>=0.27.0; extra == 'full'
|
|
72
|
+
Requires-Dist: isort>=5.13.0; extra == 'full'
|
|
73
|
+
Requires-Dist: mcp>=1.12.2; extra == 'full'
|
|
74
|
+
Requires-Dist: memory-profiler>=0.61.0; extra == 'full'
|
|
75
|
+
Requires-Dist: mypy>=1.17.0; extra == 'full'
|
|
76
|
+
Requires-Dist: pre-commit>=3.0.0; extra == 'full'
|
|
77
|
+
Requires-Dist: psutil<6,>=5.9.6; extra == 'full'
|
|
78
|
+
Requires-Dist: pydantic-settings>=2.2.1; extra == 'full'
|
|
79
|
+
Requires-Dist: pydantic>=2.5.0; extra == 'full'
|
|
80
|
+
Requires-Dist: pytest-asyncio>=1.1.0; extra == 'full'
|
|
81
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == 'full'
|
|
82
|
+
Requires-Dist: pytest-mock>=3.14.1; extra == 'full'
|
|
83
|
+
Requires-Dist: pytest>=8.4.1; extra == 'full'
|
|
84
|
+
Requires-Dist: ruff>=0.5.0; extra == 'full'
|
|
85
|
+
Requires-Dist: tree-sitter-c>=0.20.0; extra == 'full'
|
|
86
|
+
Requires-Dist: tree-sitter-cpp>=0.23.4; extra == 'full'
|
|
87
|
+
Requires-Dist: tree-sitter-go>=0.20.0; extra == 'full'
|
|
88
|
+
Requires-Dist: tree-sitter-java>=0.23.5; extra == 'full'
|
|
89
|
+
Requires-Dist: tree-sitter-javascript>=0.23.1; extra == 'full'
|
|
90
|
+
Requires-Dist: tree-sitter-python>=0.23.0; extra == 'full'
|
|
91
|
+
Requires-Dist: tree-sitter-rust>=0.20.0; extra == 'full'
|
|
92
|
+
Requires-Dist: tree-sitter-typescript>=0.20.0; extra == 'full'
|
|
93
|
+
Requires-Dist: types-psutil>=5.9.0; extra == 'full'
|
|
94
|
+
Provides-Extra: go
|
|
95
|
+
Requires-Dist: tree-sitter-go>=0.20.0; extra == 'go'
|
|
96
|
+
Provides-Extra: java
|
|
97
|
+
Requires-Dist: tree-sitter-java>=0.23.5; extra == 'java'
|
|
98
|
+
Provides-Extra: javascript
|
|
99
|
+
Requires-Dist: tree-sitter-javascript>=0.23.1; extra == 'javascript'
|
|
100
|
+
Provides-Extra: mcp
|
|
101
|
+
Requires-Dist: anyio>=4.0.0; extra == 'mcp'
|
|
102
|
+
Requires-Dist: httpx<1.0.0,>=0.27.0; extra == 'mcp'
|
|
103
|
+
Requires-Dist: mcp>=1.12.2; extra == 'mcp'
|
|
104
|
+
Requires-Dist: pydantic-settings>=2.2.1; extra == 'mcp'
|
|
105
|
+
Requires-Dist: pydantic>=2.5.0; extra == 'mcp'
|
|
106
|
+
Provides-Extra: popular
|
|
107
|
+
Requires-Dist: tree-sitter-java>=0.23.5; extra == 'popular'
|
|
108
|
+
Requires-Dist: tree-sitter-javascript>=0.23.1; extra == 'popular'
|
|
109
|
+
Requires-Dist: tree-sitter-python>=0.23.0; extra == 'popular'
|
|
110
|
+
Requires-Dist: tree-sitter-typescript>=0.20.0; extra == 'popular'
|
|
111
|
+
Provides-Extra: python
|
|
112
|
+
Requires-Dist: tree-sitter-python>=0.23.0; extra == 'python'
|
|
113
|
+
Provides-Extra: rust
|
|
114
|
+
Requires-Dist: tree-sitter-rust>=0.20.0; extra == 'rust'
|
|
115
|
+
Provides-Extra: systems
|
|
116
|
+
Requires-Dist: tree-sitter-c>=0.20.0; extra == 'systems'
|
|
117
|
+
Requires-Dist: tree-sitter-cpp>=0.23.4; extra == 'systems'
|
|
118
|
+
Requires-Dist: tree-sitter-go>=0.20.0; extra == 'systems'
|
|
119
|
+
Requires-Dist: tree-sitter-rust>=0.20.0; extra == 'systems'
|
|
120
|
+
Provides-Extra: test
|
|
121
|
+
Requires-Dist: pytest-asyncio>=1.1.0; extra == 'test'
|
|
122
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == 'test'
|
|
123
|
+
Requires-Dist: pytest-mock>=3.14.1; extra == 'test'
|
|
124
|
+
Requires-Dist: pytest>=8.4.1; extra == 'test'
|
|
125
|
+
Requires-Dist: tree-sitter-cpp>=0.23.4; extra == 'test'
|
|
126
|
+
Requires-Dist: tree-sitter-java>=0.23.5; extra == 'test'
|
|
127
|
+
Requires-Dist: tree-sitter-javascript>=0.23.1; extra == 'test'
|
|
128
|
+
Requires-Dist: tree-sitter-python>=0.23.0; extra == 'test'
|
|
129
|
+
Provides-Extra: typescript
|
|
130
|
+
Requires-Dist: tree-sitter-typescript>=0.20.0; extra == 'typescript'
|
|
131
|
+
Provides-Extra: web
|
|
132
|
+
Requires-Dist: tree-sitter-javascript>=0.23.1; extra == 'web'
|
|
133
|
+
Requires-Dist: tree-sitter-typescript>=0.20.0; extra == 'web'
|
|
134
|
+
Description-Content-Type: text/markdown
|
|
135
|
+
|
|
136
|
+
# Tree-sitter Analyzer
|
|
137
|
+
|
|
138
|
+
[](https://python.org)
|
|
139
|
+
[](LICENSE)
|
|
140
|
+
[](#quality-assurance)
|
|
141
|
+
[](#quality-assurance)
|
|
142
|
+
[](#quality-assurance)
|
|
143
|
+
[](https://pypi.org/project/tree-sitter-analyzer/)
|
|
144
|
+
[](https://github.com/aimasteracc/tree-sitter-analyzer)
|
|
145
|
+
|
|
146
|
+
## 🚀 Break Through LLM Token Limits, Let AI Understand Code Files of Any Size
|
|
147
|
+
|
|
148
|
+
> **A revolutionary code analysis tool designed for the AI era**
|
|
149
|
+
|
|
150
|
+
## 📋 Table of Contents
|
|
151
|
+
|
|
152
|
+
- [🚀 Break Through LLM Token Limits](#-break-through-llm-token-limits-let-ai-understand-code-files-of-any-size)
|
|
153
|
+
- [📋 Table of Contents](#-table-of-contents)
|
|
154
|
+
- [💡 What Makes This Special](#-what-makes-this-special)
|
|
155
|
+
- [📊 Live Demo & Results](#-live-demo--results)
|
|
156
|
+
- [🚀 30-Second Quick Start](#-30-second-quick-start)
|
|
157
|
+
- [🤖 For AI Users (Claude Desktop, Cursor, etc.)](#-for-ai-users-claude-desktop-cursor-etc)
|
|
158
|
+
- [💻 For Developers (CLI)](#-for-developers-cli)
|
|
159
|
+
- [❓ Why Choose Tree-sitter Analyzer](#-why-choose-tree-sitter-analyzer)
|
|
160
|
+
- [📖 Practical Usage Examples](#-practical-usage-examples)
|
|
161
|
+
- [🛠️ Core Features](#️-core-features)
|
|
162
|
+
- [📦 Installation Guide](#-installation-guide)
|
|
163
|
+
- [🔒 Security & Configuration](#-security--configuration)
|
|
164
|
+
- [🏆 Quality Assurance](#-quality-assurance)
|
|
165
|
+
- [🤖 AI Collaboration Support](#-ai-collaboration-support)
|
|
166
|
+
- [📚 Documentation](#-documentation)
|
|
167
|
+
- [🤝 Contributing](#-contributing)
|
|
168
|
+
- [📄 License](#-license)
|
|
169
|
+
|
|
170
|
+
## 💡 What Makes This Special
|
|
171
|
+
|
|
172
|
+
Imagine: You have a 1,400+ line Java service class that Claude or ChatGPT can't analyze due to token limits. Now, Tree-sitter Analyzer enables AI assistants to:
|
|
173
|
+
|
|
174
|
+
- ⚡ **Get complete code structure overview in 3 seconds**
|
|
175
|
+
- 🎯 **Precisely extract** any line range of code snippets
|
|
176
|
+
- 📍 **Smart positioning** exact locations of classes, methods, fields
|
|
177
|
+
- 🔗 **Seamless integration** with Claude Desktop, Cursor, Roo Code and other AI IDEs
|
|
178
|
+
|
|
179
|
+
**No more AI helplessness due to large files!**
|
|
180
|
+
|
|
181
|
+
## 📊 Live Demo & Results
|
|
182
|
+
|
|
183
|
+
### ⚡ **Lightning-Fast Analysis Speed**
|
|
184
|
+
```bash
|
|
185
|
+
# 1419-line large Java service class analysis result (< 1 second)
|
|
186
|
+
Lines: 1419 | Classes: 1 | Methods: 66 | Fields: 9 | Imports: 8
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### 📊 **Precise Structure Tables**
|
|
190
|
+
| Class Name | Type | Visibility | Line Range | Methods | Fields |
|
|
191
|
+
|------------|------|------------|------------|---------|--------|
|
|
192
|
+
| BigService | class | public | 17-1419 | 66 | 9 |
|
|
193
|
+
|
|
194
|
+
### 🔄 **AI Assistant Three-Step Workflow**
|
|
195
|
+
- **Step 1**: `check_code_scale` - Check file scale and complexity
|
|
196
|
+
- **Step 2**: `analyze_code_structure` - Generate detailed structure tables
|
|
197
|
+
- **Step 3**: `extract_code_section` - Extract code snippets on demand
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## 🚀 30-Second Quick Start
|
|
202
|
+
|
|
203
|
+
### 🤖 For AI Users (Claude Desktop, Cursor, etc.)
|
|
204
|
+
|
|
205
|
+
**📦 1. One-Click Installation**
|
|
206
|
+
```bash
|
|
207
|
+
# macOS/Linux
|
|
208
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
209
|
+
|
|
210
|
+
# Windows PowerShell
|
|
211
|
+
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
**⚙️ 2. Configure AI Client**
|
|
215
|
+
|
|
216
|
+
**Claude Desktop Configuration:**
|
|
217
|
+
|
|
218
|
+
Add the following to your config file:
|
|
219
|
+
- **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
|
|
220
|
+
- **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
221
|
+
- **Linux**: `~/.config/claude/claude_desktop_config.json`
|
|
222
|
+
|
|
223
|
+
**Basic Configuration (Recommended):**
|
|
224
|
+
```json
|
|
225
|
+
{
|
|
226
|
+
"mcpServers": {
|
|
227
|
+
"tree-sitter-analyzer": {
|
|
228
|
+
"command": "uv",
|
|
229
|
+
"args": [
|
|
230
|
+
"run", "--with", "tree-sitter-analyzer[mcp]",
|
|
231
|
+
"python", "-m", "tree_sitter_analyzer.mcp.server"
|
|
232
|
+
]
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
**Advanced Configuration (Specify Project Root):**
|
|
239
|
+
```json
|
|
240
|
+
{
|
|
241
|
+
"mcpServers": {
|
|
242
|
+
"tree-sitter-analyzer": {
|
|
243
|
+
"command": "uv",
|
|
244
|
+
"args": [
|
|
245
|
+
"run", "--with", "tree-sitter-analyzer[mcp]",
|
|
246
|
+
"python", "-m", "tree_sitter_analyzer.mcp.server"
|
|
247
|
+
],
|
|
248
|
+
"env": {
|
|
249
|
+
"TREE_SITTER_PROJECT_ROOT": "/absolute/path/to/your/project"
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
**Other AI Clients:**
|
|
257
|
+
- **Cursor**: Built-in MCP support, refer to Cursor documentation for configuration
|
|
258
|
+
- **Roo Code**: Supports MCP protocol, check respective configuration guides
|
|
259
|
+
- **Other MCP-compatible clients**: Use the same server configuration
|
|
260
|
+
|
|
261
|
+
**⚠️ Configuration Notes:**
|
|
262
|
+
- **Basic Configuration**: Tool will auto-detect project root (recommended)
|
|
263
|
+
- **Advanced Configuration**: If you need to specify a particular directory, use absolute path to replace `/absolute/path/to/your/project`
|
|
264
|
+
- **Avoid using**: Variables like `${workspaceFolder}` may not be supported in some clients
|
|
265
|
+
|
|
266
|
+
**🎉 3. Restart AI client and start analyzing massive code files!**
|
|
267
|
+
|
|
268
|
+
### 💻 For Developers (CLI)
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
# Install
|
|
272
|
+
uv add "tree-sitter-analyzer[popular]"
|
|
273
|
+
|
|
274
|
+
# Check file scale (1419-line large service class, instant completion)
|
|
275
|
+
uv run python -m tree_sitter_analyzer examples/BigService.java --advanced --output-format=text
|
|
276
|
+
|
|
277
|
+
# Generate structure table (1 class, 66 methods, clearly displayed)
|
|
278
|
+
uv run python -m tree_sitter_analyzer examples/BigService.java --table=full
|
|
279
|
+
|
|
280
|
+
# Precise code extraction
|
|
281
|
+
uv run python -m tree_sitter_analyzer examples/BigService.java --partial-read --start-line 100 --end-line 105
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
## ❓ Why Choose Tree-sitter Analyzer
|
|
287
|
+
|
|
288
|
+
### 🎯 Solving Real Pain Points
|
|
289
|
+
|
|
290
|
+
**Traditional Approach Dilemmas:**
|
|
291
|
+
- ❌ Large files exceed LLM token limits
|
|
292
|
+
- ❌ AI cannot understand code structure
|
|
293
|
+
- ❌ Manual file splitting required
|
|
294
|
+
- ❌ Context loss leads to inaccurate analysis
|
|
295
|
+
|
|
296
|
+
**Tree-sitter Analyzer's Breakthrough:**
|
|
297
|
+
- ✅ **Smart Analysis**: Understand structure without reading complete files
|
|
298
|
+
- ✅ **Precise Positioning**: Accurate line-by-line code extraction
|
|
299
|
+
- ✅ **AI Native**: Optimized for LLM workflows
|
|
300
|
+
- ✅ **Multi-language Support**: Java, Python, JavaScript/TypeScript, etc.
|
|
301
|
+
|
|
302
|
+
## 📖 Practical Usage Examples
|
|
303
|
+
|
|
304
|
+
### 💬 AI IDE Prompts (Copy and Use)
|
|
305
|
+
|
|
306
|
+
#### 🔍 **Step 1: Check File Scale**
|
|
307
|
+
|
|
308
|
+
**Prompt:**
|
|
309
|
+
```
|
|
310
|
+
Use MCP tool check_code_scale to analyze file scale
|
|
311
|
+
Parameters: {"file_path": "examples/BigService.java"}
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
**Return Format:**
|
|
315
|
+
```json
|
|
316
|
+
{
|
|
317
|
+
"file_path": "examples/BigService.java",
|
|
318
|
+
"language": "java",
|
|
319
|
+
"metrics": {
|
|
320
|
+
"lines_total": 1419,
|
|
321
|
+
"lines_code": 1419,
|
|
322
|
+
"elements": {
|
|
323
|
+
"classes": 1,
|
|
324
|
+
"methods": 66,
|
|
325
|
+
"fields": 9
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
#### 📊 **Step 2: Generate Structure Table**
|
|
332
|
+
|
|
333
|
+
**Prompt:**
|
|
334
|
+
```
|
|
335
|
+
Use MCP tool analyze_code_structure to generate detailed structure
|
|
336
|
+
Parameters: {"file_path": "examples/BigService.java"}
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
**Return Format:**
|
|
340
|
+
- Complete Markdown table
|
|
341
|
+
- Including class info, method list (with line numbers), field list
|
|
342
|
+
- Method signatures, visibility, line ranges, complexity and other detailed information
|
|
343
|
+
|
|
344
|
+
#### ✂️ **Step 3: Extract Code Snippets**
|
|
345
|
+
|
|
346
|
+
**Prompt:**
|
|
347
|
+
```
|
|
348
|
+
Use MCP tool extract_code_section to extract specified code section
|
|
349
|
+
Parameters: {"file_path": "examples/BigService.java", "start_line": 100, "end_line": 105}
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
**Return Format:**
|
|
353
|
+
```json
|
|
354
|
+
{
|
|
355
|
+
"file_path": "examples/BigService.java",
|
|
356
|
+
"range": {"start_line": 100, "end_line": 105},
|
|
357
|
+
"content": "Actual code content...",
|
|
358
|
+
"content_length": 245
|
|
359
|
+
}
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
#### 🔍 **Step 4: Smart Query Filtering (NEW!)**
|
|
363
|
+
|
|
364
|
+
**Find specific methods:**
|
|
365
|
+
```
|
|
366
|
+
Use MCP tool query_code to precisely find code elements
|
|
367
|
+
Parameters: {"file_path": "examples/BigService.java", "query_key": "methods", "filter": "name=main"}
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
**Find authentication-related methods:**
|
|
371
|
+
```
|
|
372
|
+
Use MCP tool query_code to find authentication methods
|
|
373
|
+
Parameters: {"file_path": "examples/BigService.java", "query_key": "methods", "filter": "name=~auth*"}
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
**Find parameterless public methods:**
|
|
377
|
+
```
|
|
378
|
+
Use MCP tool query_code to find getter methods
|
|
379
|
+
Parameters: {"file_path": "examples/BigService.java", "query_key": "methods", "filter": "params=0,public=true"}
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
**Return Format:**
|
|
383
|
+
```json
|
|
384
|
+
{
|
|
385
|
+
"success": true,
|
|
386
|
+
"results": [
|
|
387
|
+
{
|
|
388
|
+
"capture_name": "method",
|
|
389
|
+
"node_type": "method_declaration",
|
|
390
|
+
"start_line": 1385,
|
|
391
|
+
"end_line": 1418,
|
|
392
|
+
"content": "public static void main(String[] args) { ... }"
|
|
393
|
+
}
|
|
394
|
+
],
|
|
395
|
+
"count": 1
|
|
396
|
+
}
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
#### 💡 **Important Notes**
|
|
400
|
+
- **Parameter Format**: Use snake_case (`file_path`, `start_line`, `end_line`)
|
|
401
|
+
- **Path Handling**: Relative paths auto-resolve to project root
|
|
402
|
+
- **Security Protection**: Tool automatically performs project boundary checks
|
|
403
|
+
- **Workflow**: Recommended to use in order: Step 1 → 2 → 4 (Query Filtering) → 3 (Precise Extraction)
|
|
404
|
+
- **Filter Syntax**: Supports `name=value`, `name=~pattern*`, `params=number`, `static/public/private=true/false`
|
|
405
|
+
|
|
406
|
+
### 🛠️ CLI Command Examples
|
|
407
|
+
|
|
408
|
+
```bash
|
|
409
|
+
# Quick analysis (1419-line large file, instant completion)
|
|
410
|
+
uv run python -m tree_sitter_analyzer examples/BigService.java --advanced --output-format=text
|
|
411
|
+
|
|
412
|
+
# Detailed structure table (66 methods clearly displayed)
|
|
413
|
+
uv run python -m tree_sitter_analyzer examples/BigService.java --table=full
|
|
414
|
+
|
|
415
|
+
# Precise code extraction (memory usage monitoring code snippet)
|
|
416
|
+
uv run python -m tree_sitter_analyzer examples/BigService.java --partial-read --start-line 100 --end-line 105
|
|
417
|
+
|
|
418
|
+
# Silent mode (display results only)
|
|
419
|
+
uv run python -m tree_sitter_analyzer examples/BigService.java --table=full --quiet
|
|
420
|
+
|
|
421
|
+
# 🔍 Query filtering examples (NEW!)
|
|
422
|
+
# Find specific methods
|
|
423
|
+
uv run python -m tree_sitter_analyzer examples/BigService.java --query-key methods --filter "name=main"
|
|
424
|
+
|
|
425
|
+
# Find authentication-related methods
|
|
426
|
+
uv run python -m tree_sitter_analyzer examples/BigService.java --query-key methods --filter "name=~auth*"
|
|
427
|
+
|
|
428
|
+
# Find parameterless public methods
|
|
429
|
+
uv run python -m tree_sitter_analyzer examples/BigService.java --query-key methods --filter "params=0,public=true"
|
|
430
|
+
|
|
431
|
+
# Find static methods
|
|
432
|
+
uv run python -m tree_sitter_analyzer examples/BigService.java --query-key methods --filter "static=true"
|
|
433
|
+
|
|
434
|
+
# View filter syntax help
|
|
435
|
+
uv run python -m tree_sitter_analyzer --filter-help
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
---
|
|
439
|
+
|
|
440
|
+
## 🛠️ Core Features
|
|
441
|
+
|
|
442
|
+
### 📊 **Code Structure Analysis**
|
|
443
|
+
Get insights without reading complete files:
|
|
444
|
+
- Class, method, field statistics
|
|
445
|
+
- Package information and import dependencies
|
|
446
|
+
- Complexity metrics
|
|
447
|
+
- Precise line number positioning
|
|
448
|
+
|
|
449
|
+
### ✂️ **Smart Code Extraction**
|
|
450
|
+
- Extract by line range precisely
|
|
451
|
+
- Maintain original formatting and indentation
|
|
452
|
+
- Include position metadata
|
|
453
|
+
- Support efficient processing of large files
|
|
454
|
+
|
|
455
|
+
### 🔍 **Advanced Query Filtering**
|
|
456
|
+
Powerful code element querying and filtering system:
|
|
457
|
+
- **Exact matching**: `--filter "name=main"` Find specific methods
|
|
458
|
+
- **Pattern matching**: `--filter "name=~auth*"` Find authentication-related methods
|
|
459
|
+
- **Parameter filtering**: `--filter "params=2"` Find methods with specific parameter counts
|
|
460
|
+
- **Modifier filtering**: `--filter "static=true,public=true"` Find static public methods
|
|
461
|
+
- **Compound conditions**: `--filter "name=~get*,params=0,public=true"` Combine multiple conditions
|
|
462
|
+
- **CLI/MCP consistency**: Same filtering syntax in command line and AI assistants
|
|
463
|
+
|
|
464
|
+
### 🔗 **AI Assistant Integration**
|
|
465
|
+
Deep integration via MCP protocol:
|
|
466
|
+
- Claude Desktop
|
|
467
|
+
- Cursor IDE
|
|
468
|
+
- Roo Code
|
|
469
|
+
- Other MCP-supporting AI tools
|
|
470
|
+
|
|
471
|
+
### 🌍 **Multi-Language Support**
|
|
472
|
+
- **Java** - Full support, including Spring, JPA frameworks
|
|
473
|
+
- **Python** - Complete support, including type annotations, decorators
|
|
474
|
+
- **JavaScript/TypeScript** - Full support, including ES6+ features
|
|
475
|
+
- **C/C++, Rust, Go** - Basic support
|
|
476
|
+
|
|
477
|
+
---
|
|
478
|
+
|
|
479
|
+
## 📦 Installation Guide
|
|
480
|
+
|
|
481
|
+
### 👤 **End Users**
|
|
482
|
+
```bash
|
|
483
|
+
# Basic installation
|
|
484
|
+
uv add tree-sitter-analyzer
|
|
485
|
+
|
|
486
|
+
# Popular languages package (recommended)
|
|
487
|
+
uv add "tree-sitter-analyzer[popular]"
|
|
488
|
+
|
|
489
|
+
# MCP server support
|
|
490
|
+
uv add "tree-sitter-analyzer[mcp]"
|
|
491
|
+
|
|
492
|
+
# Full installation
|
|
493
|
+
uv add "tree-sitter-analyzer[all,mcp]"
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
### 👨💻 **Developers**
|
|
497
|
+
```bash
|
|
498
|
+
git clone https://github.com/aimasteracc/tree-sitter-analyzer.git
|
|
499
|
+
cd tree-sitter-analyzer
|
|
500
|
+
uv sync --extra all --extra mcp
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
---
|
|
504
|
+
|
|
505
|
+
## 🔒 Security & Configuration
|
|
506
|
+
|
|
507
|
+
### 🛡️ **Project Boundary Protection**
|
|
508
|
+
|
|
509
|
+
Tree-sitter Analyzer automatically detects and protects project boundaries:
|
|
510
|
+
|
|
511
|
+
- **Auto-detection**: Based on `.git`, `pyproject.toml`, `package.json`, etc.
|
|
512
|
+
- **CLI Control**: `--project-root /path/to/project`
|
|
513
|
+
- **MCP Integration**: `TREE_SITTER_PROJECT_ROOT=/path/to/project` or use auto-detection
|
|
514
|
+
- **Security Guarantee**: Only analyze files within project boundaries
|
|
515
|
+
|
|
516
|
+
**Recommended MCP Configuration:**
|
|
517
|
+
|
|
518
|
+
**Option 1: Auto-detection (Recommended)**
|
|
519
|
+
```json
|
|
520
|
+
{
|
|
521
|
+
"mcpServers": {
|
|
522
|
+
"tree-sitter-analyzer": {
|
|
523
|
+
"command": "uv",
|
|
524
|
+
"args": ["run", "--with", "tree-sitter-analyzer[mcp]", "python", "-m", "tree_sitter_analyzer.mcp.server"]
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
**Option 2: Manual Project Root Specification**
|
|
531
|
+
```json
|
|
532
|
+
{
|
|
533
|
+
"mcpServers": {
|
|
534
|
+
"tree-sitter-analyzer": {
|
|
535
|
+
"command": "uv",
|
|
536
|
+
"args": ["run", "--with", "tree-sitter-analyzer[mcp]", "python", "-m", "tree_sitter_analyzer.mcp.server"],
|
|
537
|
+
"env": {"TREE_SITTER_PROJECT_ROOT": "/path/to/your/project"}
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
---
|
|
544
|
+
|
|
545
|
+
## 🏆 Quality Assurance
|
|
546
|
+
|
|
547
|
+
### 📊 **Quality Metrics**
|
|
548
|
+
- **1,420 Tests** - 100% pass rate ✅
|
|
549
|
+
- **74.36% Code Coverage** - Industry-leading level
|
|
550
|
+
- **Zero Test Failures** - Complete CI/CD ready
|
|
551
|
+
- **Cross-platform Compatible** - Windows, macOS, Linux
|
|
552
|
+
|
|
553
|
+
### ⚡ **Latest Quality Achievements (v0.9.6)**
|
|
554
|
+
- ✅ **Smart Query Filtering System** - 62 new tests all passed
|
|
555
|
+
- ✅ **Unified Architecture Design** - QueryService eliminates code duplication
|
|
556
|
+
- ✅ **CI Test Fixes** - All platforms test stable
|
|
557
|
+
- ✅ **Multi-language Documentation** - Complete updates in EN/ZH/JA
|
|
558
|
+
|
|
559
|
+
### ⚙️ **Running Tests**
|
|
560
|
+
```bash
|
|
561
|
+
# Run all tests
|
|
562
|
+
uv run pytest tests/ -v
|
|
563
|
+
|
|
564
|
+
# Generate coverage report
|
|
565
|
+
uv run pytest tests/ --cov=tree_sitter_analyzer --cov-report=html
|
|
566
|
+
|
|
567
|
+
# Run specific tests
|
|
568
|
+
uv run pytest tests/test_mcp_server_initialization.py -v
|
|
569
|
+
```
|
|
570
|
+
|
|
571
|
+
### 📈 **Coverage Highlights**
|
|
572
|
+
- **Language Detector**: 98.41% (Excellent)
|
|
573
|
+
- **CLI Main Entry**: 94.36% (Excellent)
|
|
574
|
+
- **Query Filtering System**: 96.06% (Excellent)
|
|
575
|
+
- **Query Service**: 86.25% (Good)
|
|
576
|
+
- **Error Handling**: 82.76% (Good)
|
|
577
|
+
|
|
578
|
+
---
|
|
579
|
+
|
|
580
|
+
## 🤖 AI Collaboration Support
|
|
581
|
+
|
|
582
|
+
### ⚡ **Optimized for AI Development**
|
|
583
|
+
|
|
584
|
+
This project supports AI-assisted development with specialized quality controls:
|
|
585
|
+
|
|
586
|
+
```bash
|
|
587
|
+
# AI system pre-code generation checks
|
|
588
|
+
uv run python check_quality.py --new-code-only
|
|
589
|
+
uv run python llm_code_checker.py --check-all
|
|
590
|
+
|
|
591
|
+
# AI-generated code review
|
|
592
|
+
uv run python llm_code_checker.py path/to/new_file.py
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
📖 **Detailed Guides**:
|
|
596
|
+
- [AI Collaboration Guide](AI_COLLABORATION_GUIDE.md)
|
|
597
|
+
- [LLM Coding Guidelines](LLM_CODING_GUIDELINES.md)
|
|
598
|
+
|
|
599
|
+
---
|
|
600
|
+
|
|
601
|
+
## 📚 Documentation
|
|
602
|
+
|
|
603
|
+
- **[User MCP Setup Guide](MCP_SETUP_USERS.md)** - Simple configuration guide
|
|
604
|
+
- **[Developer MCP Setup Guide](MCP_SETUP_DEVELOPERS.md)** - Local development configuration
|
|
605
|
+
- **[Project Root Configuration](PROJECT_ROOT_CONFIG.md)** - Complete configuration reference
|
|
606
|
+
- **[API Documentation](docs/api.md)** - Detailed API reference
|
|
607
|
+
- **[Contributing Guide](CONTRIBUTING.md)** - How to contribute
|
|
608
|
+
|
|
609
|
+
---
|
|
610
|
+
|
|
611
|
+
## 🤝 Contributing
|
|
612
|
+
|
|
613
|
+
We welcome all forms of contributions! Please check the [Contributing Guide](CONTRIBUTING.md) for details.
|
|
614
|
+
|
|
615
|
+
### ⭐ **Give Us a Star!**
|
|
616
|
+
|
|
617
|
+
If this project helps you, please give us a ⭐ on GitHub - it's the greatest support for us!
|
|
618
|
+
|
|
619
|
+
---
|
|
620
|
+
|
|
621
|
+
## 📄 License
|
|
622
|
+
|
|
623
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|
|
624
|
+
|
|
625
|
+
---
|
|
626
|
+
|
|
627
|
+
**🎯 Built for developers dealing with large codebases and AI assistants**
|
|
628
|
+
|
|
629
|
+
*Let every line of code be understood by AI, let every project break through token limits*
|
|
630
|
+
|
|
631
|
+
**🚀 Start Now** → [30-Second Quick Start](#-30-second-quick-start)
|