From dfb08d9bd29b869a4ee0d55fa7911ce9b40b7a69 Mon Sep 17 00:00:00 2001 From: NotZippy Date: Thu, 1 Nov 2018 09:05:31 -0700 Subject: [PATCH] Amended importPathFromPath to detect vendor folder from basePath, not just the word vendor in the path --- parser/imports.go | 7 ++++--- parser/reflect.go | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/parser/imports.go b/parser/imports.go index d0edd15..d337117 100644 --- a/parser/imports.go +++ b/parser/imports.go @@ -60,9 +60,10 @@ func addImports(imports map[string]string, decl ast.Decl, srcDir string) { // Returns a valid import string from the path // using the build.Defaul.GOPATH to determine the root -func importPathFromPath(root string) string { - if vendorIdx := strings.Index(root, "/vendor/"); vendorIdx != -1 { - return filepath.ToSlash(root[vendorIdx+8:]) +func importPathFromPath(root, basePath string) string { + vendorTest := filepath.Join(basePath, "vendor") + if len(root) > len(vendorTest) && root[:len(vendorTest)] == vendorTest { + return filepath.ToSlash(root[len(vendorTest)+1:]) } for _, gopath := range filepath.SplitList(build.Default.GOPATH) { srcPath := filepath.Join(gopath, "src") diff --git a/parser/reflect.go b/parser/reflect.go index 0822610..b4390f2 100644 --- a/parser/reflect.go +++ b/parser/reflect.go @@ -37,7 +37,7 @@ type methodMap map[string][]*model.MethodSpec func ProcessSource(paths *model.RevelContainer) (_ *model.SourceInfo, compileError error) { pc := &processContainer{paths: paths} for _, root := range paths.CodePaths { - rootImportPath := importPathFromPath(root) + rootImportPath := importPathFromPath(root, paths.BasePath) if rootImportPath == "" { utils.Logger.Info("Skipping empty code path", "path", root) continue