Skip to content

Commit 5bdf01d

Browse files
committed
feat: add code snippet search functionality and handler implementation
1 parent 7ab1b49 commit 5bdf01d

File tree

8 files changed

+612
-61
lines changed

8 files changed

+612
-61
lines changed

backend/cmd/server/wire.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/chaitin/MonkeyCode/backend/db"
1515
"github.com/chaitin/MonkeyCode/backend/domain"
1616
billingv1 "github.com/chaitin/MonkeyCode/backend/internal/billing/handler/http/v1"
17+
codesnippetv1 "github.com/chaitin/MonkeyCode/backend/internal/codesnippet/handler/http/v1"
1718
dashv1 "github.com/chaitin/MonkeyCode/backend/internal/dashboard/handler/v1"
1819
v1 "github.com/chaitin/MonkeyCode/backend/internal/model/handler/http/v1"
1920
openaiV1 "github.com/chaitin/MonkeyCode/backend/internal/openai/handler/v1"
@@ -24,20 +25,21 @@ import (
2425
)
2526

2627
type Server struct {
27-
config *config.Config
28-
web *web.Web
29-
ent *db.Client
30-
logger *slog.Logger
31-
openaiV1 *openaiV1.V1Handler
32-
modelV1 *v1.ModelHandler
33-
userV1 *userV1.UserHandler
34-
dashboardV1 *dashv1.DashboardHandler
35-
billingV1 *billingv1.BillingHandler
36-
socketH *sockethandler.SocketHandler
37-
version *version.VersionInfo
38-
report *report.Reporter
39-
reportuse domain.ReportUsecase
40-
euse domain.ExtensionUsecase
28+
config *config.Config
29+
web *web.Web
30+
ent *db.Client
31+
logger *slog.Logger
32+
openaiV1 *openaiV1.V1Handler
33+
modelV1 *v1.ModelHandler
34+
userV1 *userV1.UserHandler
35+
dashboardV1 *dashv1.DashboardHandler
36+
billingV1 *billingv1.BillingHandler
37+
socketH *sockethandler.SocketHandler
38+
version *version.VersionInfo
39+
report *report.Reporter
40+
reportuse domain.ReportUsecase
41+
euse domain.ExtensionUsecase
42+
codeSnippetV1 *codesnippetv1.CodeSnippetHandler
4143
}
4244

4345
func newServer() (*Server, error) {

backend/cmd/server/wire_gen.go

Lines changed: 32 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/docs/swagger.json

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,61 @@
11571157
}
11581158
}
11591159
},
1160+
"/api/v1/ide/codesnippet/context": {
1161+
"post": {
1162+
"security": [
1163+
{
1164+
"ApiKeyAuth": []
1165+
}
1166+
],
1167+
"description": "为IDE端提供代码片段上下文检索功能,使用API Key认证。支持单个查询和批量查询。",
1168+
"consumes": [
1169+
"application/json"
1170+
],
1171+
"produces": [
1172+
"application/json"
1173+
],
1174+
"tags": [
1175+
"CodeSnippet"
1176+
],
1177+
"summary": "IDE端上下文检索",
1178+
"operationId": "get-context",
1179+
"parameters": [
1180+
{
1181+
"description": "检索请求参数",
1182+
"name": "request",
1183+
"in": "body",
1184+
"required": true,
1185+
"schema": {
1186+
"$ref": "#/definitions/internal_codesnippet_handler_http_v1.GetContextReq"
1187+
}
1188+
}
1189+
],
1190+
"responses": {
1191+
"200": {
1192+
"description": "OK",
1193+
"schema": {
1194+
"allOf": [
1195+
{
1196+
"$ref": "#/definitions/web.Resp"
1197+
},
1198+
{
1199+
"type": "object",
1200+
"properties": {
1201+
"data": {
1202+
"type": "array",
1203+
"items": {
1204+
"$ref": "#/definitions/domain.CodeSnippet"
1205+
}
1206+
}
1207+
}
1208+
}
1209+
]
1210+
}
1211+
}
1212+
}
1213+
}
1214+
},
11601215
"/api/v1/model": {
11611216
"get": {
11621217
"description": "获取模型列表",
@@ -3797,6 +3852,98 @@
37973852
"CodeLanguageTypeCpp"
37983853
]
37993854
},
3855+
"domain.CodeSnippet": {
3856+
"type": "object",
3857+
"properties": {
3858+
"container_name": {
3859+
"description": "容器名称",
3860+
"type": "string"
3861+
},
3862+
"content": {
3863+
"description": "代码片段内容",
3864+
"type": "string"
3865+
},
3866+
"definition_text": {
3867+
"description": "定义文本",
3868+
"type": "string"
3869+
},
3870+
"dependencies": {
3871+
"description": "依赖项",
3872+
"type": "array",
3873+
"items": {
3874+
"type": "string"
3875+
}
3876+
},
3877+
"end_column": {
3878+
"description": "结束列号",
3879+
"type": "integer"
3880+
},
3881+
"end_line": {
3882+
"description": "结束行号",
3883+
"type": "integer"
3884+
},
3885+
"hash": {
3886+
"description": "内容哈希",
3887+
"type": "string"
3888+
},
3889+
"id": {
3890+
"description": "代码片段ID",
3891+
"type": "string"
3892+
},
3893+
"language": {
3894+
"description": "编程语言",
3895+
"type": "string"
3896+
},
3897+
"name": {
3898+
"description": "代码片段名称",
3899+
"type": "string"
3900+
},
3901+
"namespace": {
3902+
"description": "命名空间",
3903+
"type": "string"
3904+
},
3905+
"parameters": {
3906+
"description": "参数列表",
3907+
"type": "array",
3908+
"items": {
3909+
"type": "object",
3910+
"additionalProperties": {}
3911+
}
3912+
},
3913+
"scope": {
3914+
"description": "作用域信息",
3915+
"type": "array",
3916+
"items": {
3917+
"type": "string"
3918+
}
3919+
},
3920+
"signature": {
3921+
"description": "函数签名",
3922+
"type": "string"
3923+
},
3924+
"snippet_type": {
3925+
"description": "代码片段类型",
3926+
"type": "string"
3927+
},
3928+
"start_column": {
3929+
"description": "起始列号",
3930+
"type": "integer"
3931+
},
3932+
"start_line": {
3933+
"description": "起始行号",
3934+
"type": "integer"
3935+
},
3936+
"structured_info": {
3937+
"description": "结构化信息",
3938+
"type": "object",
3939+
"additionalProperties": {}
3940+
},
3941+
"workspace_file_id": {
3942+
"description": "关联的workspace file ID",
3943+
"type": "string"
3944+
}
3945+
}
3946+
},
38003947
"domain.CompletionData": {
38013948
"type": "object",
38023949
"properties": {
@@ -5555,6 +5702,51 @@
55555702
}
55565703
}
55575704
},
5705+
"internal_codesnippet_handler_http_v1.GetContextReq": {
5706+
"type": "object",
5707+
"properties": {
5708+
"limit": {
5709+
"description": "返回结果数量限制,默认10",
5710+
"type": "integer"
5711+
},
5712+
"queries": {
5713+
"description": "批量查询参数",
5714+
"type": "array",
5715+
"items": {
5716+
"$ref": "#/definitions/internal_codesnippet_handler_http_v1.Query"
5717+
}
5718+
},
5719+
"query": {
5720+
"description": "单个查询参数",
5721+
"allOf": [
5722+
{
5723+
"$ref": "#/definitions/internal_codesnippet_handler_http_v1.Query"
5724+
}
5725+
]
5726+
},
5727+
"workspace_path": {
5728+
"description": "工作区路径(必填)",
5729+
"type": "string"
5730+
}
5731+
}
5732+
},
5733+
"internal_codesnippet_handler_http_v1.Query": {
5734+
"type": "object",
5735+
"properties": {
5736+
"language": {
5737+
"description": "编程语言(可选)",
5738+
"type": "string"
5739+
},
5740+
"name": {
5741+
"description": "代码片段名称(可选)",
5742+
"type": "string"
5743+
},
5744+
"type": {
5745+
"description": "代码片段类型(可选)",
5746+
"type": "string"
5747+
}
5748+
}
5749+
},
55585750
"web.Resp": {
55595751
"type": "object",
55605752
"properties": {

backend/domain/codesnippet.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ type CodeSnippetUsecase interface {
1212
ListByWorkspaceFile(ctx context.Context, workspaceFileID string) ([]*CodeSnippet, error)
1313
GetByID(ctx context.Context, id string) (*CodeSnippet, error)
1414
Delete(ctx context.Context, id string) error
15+
Search(ctx context.Context, name, snippetType, language string) ([]*CodeSnippet, error)
16+
SearchByWorkspace(ctx context.Context, userID, workspacePath, name, snippetType, language string) ([]*CodeSnippet, error)
1517
}
1618

1719
// CodeSnippetRepo 定义 CodeSnippet 数据访问接口
@@ -20,6 +22,8 @@ type CodeSnippetRepo interface {
2022
ListByWorkspaceFile(ctx context.Context, workspaceFileID string) ([]*db.CodeSnippet, error)
2123
GetByID(ctx context.Context, id string) (*db.CodeSnippet, error)
2224
Delete(ctx context.Context, id string) error
25+
Search(ctx context.Context, name, snippetType, language string) ([]*db.CodeSnippet, error)
26+
SearchByWorkspace(ctx context.Context, userID, workspacePath, name, snippetType, language string) ([]*db.CodeSnippet, error)
2327
}
2428

2529
// 请求结构体

0 commit comments

Comments
 (0)