Skip to content

Commit 6690b4d

Browse files
committed
fix: lose global var function call
1 parent 683a2f7 commit 6690b4d

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

lang/golang/parser/ctx.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,15 @@ func (ctx *fileContext) GetMod(impt string) (string, error) {
146146
if ims == impt {
147147
return ctx.module.Name, nil
148148
}
149+
// fileContext 中的 import 信息只有**当前文件的引用路径**,但是存在一种场景就是实际调用的节点在另外的一个Package,导致漏解析
150+
// 常见于"链式调用"、"另一个 pkg 的全局变量的类型在另外一个 pkg下"
151+
if dep, exist := ctx.deps[ims]; exist {
152+
for pkgName, _ := range dep.Imports {
153+
if pkgName == impt {
154+
return ctx.module.Name, nil
155+
}
156+
}
157+
}
149158
}
150159
for _, ims := range ctx.imports.ThirdPartyImports {
151160
if ims[1] == impt {

0 commit comments

Comments
 (0)