Skip to content

Commit

Permalink
fix issue #1662: find definitions from external packages first (#1666)
Browse files Browse the repository at this point in the history
Signed-off-by: sdghchj <[email protected]>
  • Loading branch information
sdghchj committed Nov 24, 2023
1 parent 0ade78c commit 6cdaaf5
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,13 +506,6 @@ func (pkgDefs *PackagesDefinitions) findPackagePathFromImports(pkg string, file
}

func (pkgDefs *PackagesDefinitions) findTypeSpecFromPackagePaths(matchedPkgPaths, externalPkgPaths []string, name string) (typeDef *TypeSpecDef) {
for _, pkgPath := range matchedPkgPaths {
typeDef = pkgDefs.findTypeSpec(pkgPath, name)
if typeDef != nil {
return typeDef
}
}

if pkgDefs.parseDependency > 0 {
for _, pkgPath := range externalPkgPaths {
if err := pkgDefs.loadExternalPackage(pkgPath); err == nil {
Expand All @@ -524,6 +517,13 @@ func (pkgDefs *PackagesDefinitions) findTypeSpecFromPackagePaths(matchedPkgPaths
}
}

for _, pkgPath := range matchedPkgPaths {
typeDef = pkgDefs.findTypeSpec(pkgPath, name)
if typeDef != nil {
return typeDef
}
}

return typeDef
}

Expand All @@ -542,13 +542,14 @@ func (pkgDefs *PackagesDefinitions) FindTypeSpec(typeName string, file *ast.File

parts := strings.Split(strings.Split(typeName, "[")[0], ".")
if len(parts) > 1 {
typeDef, ok := pkgDefs.uniqueDefinitions[typeName]
if ok {
return typeDef
}

pkgPaths, externalPkgPaths := pkgDefs.findPackagePathFromImports(parts[0], file)
typeDef = pkgDefs.findTypeSpecFromPackagePaths(pkgPaths, externalPkgPaths, parts[1])
if len(externalPkgPaths) == 0 || pkgDefs.parseDependency == ParseNone {
typeDef, ok := pkgDefs.uniqueDefinitions[typeName]
if ok {
return typeDef
}
}
typeDef := pkgDefs.findTypeSpecFromPackagePaths(pkgPaths, externalPkgPaths, parts[1])
return pkgDefs.parametrizeGenericType(file, typeDef, typeName)
}

Expand Down

0 comments on commit 6cdaaf5

Please sign in to comment.