Skip to content

Commit ffe1844

Browse files
author
piexlMax(奇淼
committed
fix(mcp): 递归检查包文件夹中是否存在.go文件
1 parent 5be3293 commit ffe1844

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

server/mcp/gva_analyze.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,20 +282,38 @@ func (g *GVAAnalyzer) isPackageFolderEmpty(packageName, template string) (bool,
282282
} else if err != nil {
283283
return false, err // 其他错误
284284
}
285+
// 递归检查是否有.go文件
286+
return g.hasGoFilesRecursive(basePath)
287+
}
285288

286-
// 读取文件夹内容
287-
entries, err := os.ReadDir(basePath)
289+
// hasGoFilesRecursive 递归检查目录及其子目录中是否有.go文件
290+
func (g *GVAAnalyzer) hasGoFilesRecursive(dirPath string) (bool, error) {
291+
entries, err := os.ReadDir(dirPath)
288292
if err != nil {
289-
return false, err
293+
return true, err // 读取失败,返回空
290294
}
291295

292-
// 检查是否有.go文件
296+
// 检查当前目录下的.go文件
293297
for _, entry := range entries {
294298
if !entry.IsDir() && strings.HasSuffix(entry.Name(), ".go") {
295299
return false, nil // 找到.go文件,不为空
296300
}
297301
}
298302

303+
// 递归检查子目录
304+
for _, entry := range entries {
305+
if entry.IsDir() {
306+
subDirPath := filepath.Join(dirPath, entry.Name())
307+
isEmpty, err := g.hasGoFilesRecursive(subDirPath)
308+
if err != nil {
309+
continue // 忽略子目录的错误,继续检查其他目录
310+
}
311+
if !isEmpty {
312+
return false, nil // 子目录中找到.go文件,不为空
313+
}
314+
}
315+
}
316+
299317
return true, nil // 没有找到.go文件,为空
300318
}
301319

0 commit comments

Comments
 (0)