feat: Add CodeSnippet entity and related functionality

- Introduced CodeSnippet schema with fields for snippet details and relationships to WorkspaceFile.
- Enhanced WorkspaceFileUpdate and WorkspaceFileUpdateOne to manage snippets, including adding, removing, and clearing snippet relationships.
- Updated Swagger documentation to include new API endpoints for CLI command execution and workspace file management.
- Implemented domain structures for handling code files and AST parsing results.
- Refactored Workspace and WorkspaceFile use cases to support new functionalities.
- Adjusted CLI command execution to handle code file information in JSON format.
- Improved error handling and logging throughout the workspace and file management processes.
This commit is contained in:
Haoxin Li
2025-07-25 19:35:00 +08:00
parent 0d8673a54d
commit 9388e149d6
33 changed files with 8023 additions and 106 deletions

View File

@@ -600,18 +600,32 @@ func (h *SocketHandler) generateAST(filePath, content string) string {
return ""
}
// 创建临时文件来调用ctcode-cli
// 注意:这里是一个简化版本,实际使用时可能需要更复杂的临时文件处理
// 为了验证功能我们直接调用cli假设它能处理内容
results, err := cli.RunParseCLI("parse", "--successOnly", filePath)
// 准备代码文件信息
codeFiles := domain.CodeFiles{
Files: []domain.FileMeta{
{
FilePath: filePath,
FileExtension: ext,
Content: content,
},
},
}
// 调用CLI工具生成AST
results, err := cli.RunCli("parse", "--successOnly", codeFiles)
if err != nil {
h.logger.Error("Failed to generate AST", "filePath", filePath, "error", err)
return ""
}
// 如果解析成功返回第一个结果的definition
if len(results) > 0 && results[0].Success {
return results[0].Definition
if len(results) > 0 {
resultBytes, err := json.Marshal(results[0])
if err != nil {
h.logger.Error("Failed to marshal AST result", "filePath", filePath, "error", err)
return ""
}
return string(resultBytes)
}
return ""