MCPcopy Create free account
hub / github.com/nsf/gocode / vendorlessImportPath

Function vendorlessImportPath

utils.go:156–174  ·  view source on GitHub ↗

vendorlessImportPath returns the devendorized version of the provided import path. e.g. "foo/bar/vendor/a/b" => "a/b"

(ipath string, currentPackagePath string)

Source from the content-addressed store, hash-verified

154// vendorlessImportPath returns the devendorized version of the provided import path.
155// e.g. "foo/bar/vendor/a/b" => "a/b"
156func vendorlessImportPath(ipath string, currentPackagePath string) (string, bool) {
157 split := strings.Split(ipath, "vendor/")
158 // no vendor in path
159 if len(split) == 1 {
160 return ipath, true
161 }
162 // this import path does not belong to the current package
163 if currentPackagePath != "" && !strings.Contains(currentPackagePath, split[0]) {
164 return "", false
165 }
166 // Devendorize for use in import statement.
167 if i := strings.LastIndex(ipath, "/vendor/"); i >= 0 {
168 return ipath[i+len("/vendor/"):], true
169 }
170 if strings.HasPrefix(ipath, "vendor/") {
171 return ipath[len("vendor/"):], true
172 }
173 return ipath, true
174}
175
176//-------------------------------------------------------------------------
177// print_backtrace

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected