Skip to content

Commit 428cb8b

Browse files
author
simuleite
committed
AI: add output field
1 parent a95cc26 commit 428cb8b

3 files changed

Lines changed: 25 additions & 12 deletions

File tree

internal/cmd/cli/get_file_structure.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Returns a list of functions, types, and variables defined in the file.`,
6767
Name string `json:"name"`
6868
Line int `json:"line"`
6969
Signature string `json:"signature,omitempty"`
70+
TypeKind string `json:"typeKind,omitempty"` // class, typedef, struct, enum, interface
7071
}
7172

7273
var nodes []Node
@@ -78,6 +79,10 @@ Returns a list of functions, types, and variables defined in the file.`,
7879
if sig, ok := sym["Signature"].(string); ok {
7980
n.Signature = sig
8081
}
82+
// 添加 TypeKind (class, typedef, struct, enum, interface)
83+
if tk, ok := sym["TypeKind"].(string); ok && tk != "" {
84+
n.TypeKind = tk
85+
}
8186
nodes = append(nodes, n)
8287
}
8388

internal/cmd/cli/get_file_symbol.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ Returns the symbol's code, type, line number, and relationship with other symbol
9393
// 通过 ModPath + PkgPath + Name 反向查找 FilePath
9494
filePath := findSymbolFile(data, r["mod_path"], r["pkg_path"], r["name"])
9595

96-
if r["kind"] == "Dependency" {
96+
// Dependency, Inherit, Implement 都视为依赖关系
97+
if r["kind"] == "Dependency" || r["kind"] == "Inherit" || r["kind"] == "Implement" {
9798
depMap[filePath] = append(depMap[filePath], r["name"])
9899
} else {
99100
refMap[filePath] = append(refMap[filePath], r["name"])

internal/cmd/cli/search_symbol.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,19 @@ abcoder cli search_symbol myrepo "Graph" --path "src/main/java/com/uniast/parser
161161
}
162162
for name := range nameToLocs {
163163
if matchName(name, query) {
164+
// 支持两种格式:
165+
// 1. 数组格式: {"GetUser": ["src/user.rs"]}
166+
// 2. 对象格式: {"GetUser": {"Files": ["src/user.rs"]}}
164167
locVal := nameToLocsVal.Get(name)
168+
var files []interface{}
165169
filesVal := locVal.Get("Files")
166170
if filesVal.Exists() {
167-
files, _ := filesVal.Array()
171+
files, _ = filesVal.Array()
172+
} else {
173+
// 尝试数组格式
174+
files, _ = locVal.Array()
175+
}
176+
if len(files) > 0 {
168177
for _, f := range files {
169178
fileStr, _ := f.(string)
170179
// path 前缀过滤
@@ -184,17 +193,15 @@ abcoder cli search_symbol myrepo "Graph" --path "src/main/java/com/uniast/parser
184193
}
185194
}
186195

187-
// 如果有结果,直接返回
188-
if len(results) > 0 {
189-
output := SearchResult{
190-
RepoName: repoName,
191-
Query: query,
192-
Results: results,
193-
}
194-
b, _ := json.MarshalIndent(output, "", " ")
195-
fmt.Fprintf(os.Stdout, "%s\n", b)
196-
return nil
196+
// 无论是否有结果都直接返回
197+
output := SearchResult{
198+
RepoName: repoName,
199+
Query: query,
200+
Results: results,
197201
}
202+
b, _ := json.MarshalIndent(output, "", " ")
203+
fmt.Fprintf(os.Stdout, "%s\n", b)
204+
return nil
198205
}
199206
}
200207

0 commit comments

Comments
 (0)