vcode-analysis 0.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.
- analyzers/__init__.py +24 -0
- analyzers/architecture.py +510 -0
- analyzers/code_review.py +150 -0
- analyzers/directory.py +867 -0
- analyzers/documentation.py +209 -0
- analyzers/security.py +671 -0
- core/__init__.py +17 -0
- core/analyzer.py +207 -0
- core/config.py +166 -0
- core/git_handler.py +718 -0
- core/llm_client.py +186 -0
- parsers/__init__.py +209 -0
- parsers/c/__init__.py +57 -0
- parsers/c/ast_parser.py +424 -0
- parsers/c/models.py +211 -0
- parsers/c/patterns.py +143 -0
- parsers/c/regex_parser.py +594 -0
- parsers/c_parser.py +275 -0
- parsers/java_parser.py +430 -0
- parsers/javascript_parser.py +587 -0
- parsers/kotlin/__init__.py +61 -0
- parsers/kotlin/ast_parser.py +591 -0
- parsers/kotlin/models.py +274 -0
- parsers/kotlin/patterns.py +146 -0
- parsers/kotlin/regex_parser.py +906 -0
- parsers/kotlin_parser.py +279 -0
- parsers/python_parser.py +429 -0
- parsers/typescript_parser.py +381 -0
- vcode_analysis-0.1.0.dist-info/METADATA +246 -0
- vcode_analysis-0.1.0.dist-info/RECORD +34 -0
- vcode_analysis-0.1.0.dist-info/WHEEL +5 -0
- vcode_analysis-0.1.0.dist-info/entry_points.txt +2 -0
- vcode_analysis-0.1.0.dist-info/licenses/LICENSE +21 -0
- vcode_analysis-0.1.0.dist-info/top_level.txt +3 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"""文档生成分析器"""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Optional
|
|
5
|
+
from core.analyzer import Analyzer, FileInfo, AnalysisResult
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@dataclass
|
|
9
|
+
class DocumentationResult:
|
|
10
|
+
"""文档生成结果"""
|
|
11
|
+
file_path: str
|
|
12
|
+
doc_type: str
|
|
13
|
+
content: str
|
|
14
|
+
success: bool
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# 文档生成提示词模板
|
|
18
|
+
MODULE_DOC_PROMPT = """你是一位技术文档专家。请为以下 {language} 模块生成详细的文档。
|
|
19
|
+
|
|
20
|
+
文件: {file_path}
|
|
21
|
+
|
|
22
|
+
```{language}
|
|
23
|
+
{content}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
请生成以下内容:
|
|
27
|
+
|
|
28
|
+
## 模块概述
|
|
29
|
+
简要描述模块的用途和功能。
|
|
30
|
+
|
|
31
|
+
## 主要组件
|
|
32
|
+
列出主要的类、函数、常量及其用途。
|
|
33
|
+
|
|
34
|
+
## 使用示例
|
|
35
|
+
提供典型的使用示例代码。
|
|
36
|
+
|
|
37
|
+
## 依赖关系
|
|
38
|
+
列出该模块依赖的其他模块或库。
|
|
39
|
+
|
|
40
|
+
## 注意事项
|
|
41
|
+
使用时需要注意的事项或限制。
|
|
42
|
+
|
|
43
|
+
请以 Markdown 格式输出。"""
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
API_DOC_PROMPT = """你是一位 API 文档专家。请为以下代码生成 API 文档。
|
|
47
|
+
|
|
48
|
+
文件: {file_path}
|
|
49
|
+
语言: {language}
|
|
50
|
+
|
|
51
|
+
```{language}
|
|
52
|
+
{content}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
请生成 OpenAPI/Swagger 风格的 API 文档,包括:
|
|
56
|
+
|
|
57
|
+
## 接口列表
|
|
58
|
+
对于每个公开的接口/函数/方法:
|
|
59
|
+
|
|
60
|
+
### {函数名}
|
|
61
|
+
- **描述**: 功能说明
|
|
62
|
+
- **参数**: 参数名、类型、描述、是否必填
|
|
63
|
+
- **返回值**: 类型、描述
|
|
64
|
+
- **示例**: 调用示例
|
|
65
|
+
|
|
66
|
+
请以 Markdown 格式输出。"""
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
README_PROMPT = """你是一位技术写作专家。请根据项目结构生成 README.md 文档。
|
|
70
|
+
|
|
71
|
+
项目信息:
|
|
72
|
+
- 名称: {project_name}
|
|
73
|
+
- 描述: {project_description}
|
|
74
|
+
|
|
75
|
+
主要文件:
|
|
76
|
+
{file_summaries}
|
|
77
|
+
|
|
78
|
+
请生成完整的 README.md,包括:
|
|
79
|
+
|
|
80
|
+
# {项目名称}
|
|
81
|
+
|
|
82
|
+
## 简介
|
|
83
|
+
项目简介和主要功能。
|
|
84
|
+
|
|
85
|
+
## 特性
|
|
86
|
+
主要特性和亮点。
|
|
87
|
+
|
|
88
|
+
## 安装
|
|
89
|
+
安装步骤和依赖要求。
|
|
90
|
+
|
|
91
|
+
## 快速开始
|
|
92
|
+
基本使用示例。
|
|
93
|
+
|
|
94
|
+
## 项目结构
|
|
95
|
+
目录结构说明。
|
|
96
|
+
|
|
97
|
+
## 贡献指南
|
|
98
|
+
如何参与项目开发。
|
|
99
|
+
|
|
100
|
+
## 许可证
|
|
101
|
+
开源许可证信息。
|
|
102
|
+
|
|
103
|
+
请以 Markdown 格式输出。"""
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
class DocumentationAnalyzer:
|
|
107
|
+
"""文档生成分析器"""
|
|
108
|
+
|
|
109
|
+
def __init__(self, analyzer: Analyzer):
|
|
110
|
+
self.analyzer = analyzer
|
|
111
|
+
|
|
112
|
+
def generate_module_doc(
|
|
113
|
+
self,
|
|
114
|
+
file_info: FileInfo,
|
|
115
|
+
doc_type: str = "module"
|
|
116
|
+
) -> DocumentationResult:
|
|
117
|
+
"""生成模块文档"""
|
|
118
|
+
try:
|
|
119
|
+
result = self.analyzer.analyze_file(
|
|
120
|
+
file_info,
|
|
121
|
+
MODULE_DOC_PROMPT,
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
return DocumentationResult(
|
|
125
|
+
file_path=file_info.relative_path,
|
|
126
|
+
doc_type=doc_type,
|
|
127
|
+
content=result.content,
|
|
128
|
+
success=result.success,
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
except Exception as e:
|
|
132
|
+
return DocumentationResult(
|
|
133
|
+
file_path=file_info.relative_path,
|
|
134
|
+
doc_type=doc_type,
|
|
135
|
+
content="",
|
|
136
|
+
success=False,
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
def generate_api_doc(self, file_info: FileInfo) -> DocumentationResult:
|
|
140
|
+
"""生成 API 文档"""
|
|
141
|
+
try:
|
|
142
|
+
result = self.analyzer.analyze_file(
|
|
143
|
+
file_info,
|
|
144
|
+
API_DOC_PROMPT,
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
return DocumentationResult(
|
|
148
|
+
file_path=file_info.relative_path,
|
|
149
|
+
doc_type="api",
|
|
150
|
+
content=result.content,
|
|
151
|
+
success=result.success,
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
except Exception as e:
|
|
155
|
+
return DocumentationResult(
|
|
156
|
+
file_path=file_info.relative_path,
|
|
157
|
+
doc_type="api",
|
|
158
|
+
content="",
|
|
159
|
+
success=False,
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
def generate_readme(
|
|
163
|
+
self,
|
|
164
|
+
project_name: str,
|
|
165
|
+
project_description: str,
|
|
166
|
+
file_summaries: list[dict],
|
|
167
|
+
) -> DocumentationResult:
|
|
168
|
+
"""生成 README 文档"""
|
|
169
|
+
# 构建文件摘要
|
|
170
|
+
summaries_text = ""
|
|
171
|
+
for summary in file_summaries:
|
|
172
|
+
summaries_text += f"- **{summary['path']}**: {summary['description']}\n"
|
|
173
|
+
|
|
174
|
+
prompt = README_PROMPT.format(
|
|
175
|
+
project_name=project_name,
|
|
176
|
+
project_description=project_description,
|
|
177
|
+
file_summaries=summaries_text,
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
response = self.analyzer.llm.simple_chat(prompt)
|
|
181
|
+
|
|
182
|
+
return DocumentationResult(
|
|
183
|
+
file_path="README.md",
|
|
184
|
+
doc_type="readme",
|
|
185
|
+
content=response,
|
|
186
|
+
success=True,
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
def generate_docs_for_project(
|
|
190
|
+
self,
|
|
191
|
+
target_path: str,
|
|
192
|
+
doc_types: Optional[list[str]] = None,
|
|
193
|
+
) -> list[DocumentationResult]:
|
|
194
|
+
"""为整个项目生成文档"""
|
|
195
|
+
doc_types = doc_types or ["module"]
|
|
196
|
+
|
|
197
|
+
results = []
|
|
198
|
+
file_infos = list(self.analyzer.scan_files(target_path))
|
|
199
|
+
|
|
200
|
+
for file_info in file_infos:
|
|
201
|
+
if "module" in doc_types:
|
|
202
|
+
result = self.generate_module_doc(file_info)
|
|
203
|
+
results.append(result)
|
|
204
|
+
|
|
205
|
+
if "api" in doc_types:
|
|
206
|
+
result = self.generate_api_doc(file_info)
|
|
207
|
+
results.append(result)
|
|
208
|
+
|
|
209
|
+
return results
|