@@ -48,15 +48,15 @@ type GetContextReq struct {
4848 // 单个查询参数
4949 Query Query `json:"query,omitempty"` // 单个查询条件
5050
51- Limit int `json:"limit"` // 返回结果数量限制,默认10
52- WorkspacePath string `json:"workspace_path "` // 工作区路径(必填)
51+ Limit int `json:"limit"` // 返回结果数量限制,默认10
52+ WorkspacePath string `json:"workspacePath "` // 工作区路径(必填)
5353}
5454
5555// Query 批量查询条件
5656type Query struct {
57- Name string `json:"name,omitempty"` // 代码片段名称(可选)
58- Type string `json:"type ,omitempty"` // 代码片段类型(可选)
59- Language string `json:"language,omitempty"` // 编程语言(可选)
57+ Name string `json:"name,omitempty"` // 代码片段名称(可选)
58+ SnippetType string `json:"snippetType ,omitempty"` // 代码片段类型(可选)
59+ Language string `json:"language,omitempty"` // 编程语言(可选)
6060}
6161
6262// GetContext IDE端上下文检索接口
@@ -72,17 +72,23 @@ type Query struct {
7272// @Router /api/v1/ide/codesnippet/context [post]
7373// @Security ApiKeyAuth
7474func (h * CodeSnippetHandler ) GetContext (c * web.Context , req GetContextReq ) error {
75+ h .logger .Info ("GetContext called" , "request" , req )
76+
7577 // 设置默认限制
7678 if req .Limit <= 0 {
7779 req .Limit = 10
7880 }
7981 if req .Limit > 50 {
80- req .Limit = 50 // 最大限制50个结果
82+ req .Limit = 50
8183 }
8284
83- // 如果没有提供workspace_path,则返回空结果
84- if req .WorkspacePath == "" {
85- return c .Success ([]* domain.CodeSnippet {})
85+ // 提取workspacePath变量
86+ workspacePath := req .WorkspacePath
87+
88+ // 如果没有提供workspacePath,则返回错误
89+ if workspacePath == "" {
90+ h .logger .Warn ("Workspace path is required but not provided" )
91+ return fmt .Errorf ("workspacePath is required" )
8692 }
8793
8894 // 获取用户ID,主要使用API Key认证
@@ -100,7 +106,7 @@ func (h *CodeSnippetHandler) GetContext(c *web.Context, req GetContextReq) error
100106 if len (req .Queries ) > 0 {
101107 // 执行批量查询
102108 for _ , query := range req .Queries {
103- snippets , err := h .usecase .SearchByWorkspace (c .Request ().Context (), userID , req . WorkspacePath , query .Name , query .Type , query .Language )
109+ snippets , err := h .usecase .SearchByWorkspace (c .Request ().Context (), userID , workspacePath , query .Name , query .SnippetType , query .Language )
104110 if err != nil {
105111 h .logger .Error ("failed to get context for IDE" , "error" , err )
106112 return err
@@ -109,7 +115,7 @@ func (h *CodeSnippetHandler) GetContext(c *web.Context, req GetContextReq) error
109115 }
110116 } else {
111117 // 执行单个查询
112- snippets , err := h .usecase .SearchByWorkspace (c .Request ().Context (), userID , req . WorkspacePath , req .Query .Name , req .Query .Type , req .Query .Language )
118+ snippets , err := h .usecase .SearchByWorkspace (c .Request ().Context (), userID , workspacePath , req .Query .Name , req .Query .SnippetType , req .Query .Language )
113119 if err != nil {
114120 h .logger .Error ("failed to get context for IDE" , "error" , err )
115121 return err
@@ -121,19 +127,6 @@ func (h *CodeSnippetHandler) GetContext(c *web.Context, req GetContextReq) error
121127 if len (allSnippets ) > req .Limit {
122128 allSnippets = allSnippets [:req .Limit ]
123129 }
124-
125- h .logger .Info ("IDE context retrieval completed" ,
126- "userID" , c .Request ().Context ().Value (logger.UserIDKey {}),
127- "resultCount" , len (allSnippets ),
128- "filters" , map [string ]interface {}{
129- "singleQuery" : map [string ]string {
130- "name" : req .Query .Name ,
131- "type" : req .Query .Type ,
132- "language" : req .Query .Language ,
133- },
134- "batchQueryCount" : len (req .Queries ),
135- "workspace_path" : req .WorkspacePath ,
136- })
137-
130+ h .logger .Info ("Returning context for IDE" , "count" , allSnippets )
138131 return c .Success (allSnippets )
139132}
0 commit comments