-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsource.go
More file actions
49 lines (42 loc) · 976 Bytes
/
source.go
File metadata and controls
49 lines (42 loc) · 976 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package play
import (
"fmt"
"go/types"
"path"
)
func ImportFromVendor(parent types.Importer, config *Config, p string) (*types.Package, error) {
if !config.HasVendor() {
return nil, nil
}
pkgs, err := ParseDir(config, path.Join("vendor", p), 0)
if err != nil {
return nil, err
}
for name, files := range pkgs {
var firstHardErr error
typesConfig := &types.Config{
IgnoreFuncBodies: true,
Importer: parent,
Error: func(err error) {
if firstHardErr == nil && !err.(types.Error).Soft {
firstHardErr = err
}
},
}
typesPkg, err := typesConfig.Check(name, config.Fset, files, nil)
if err != nil {
if firstHardErr != nil {
typesPkg = nil
err = firstHardErr
}
return typesPkg, fmt.Errorf("type-checking package %q failed: %w", name, err)
}
if firstHardErr != nil {
panic("package is not safe yet no error was returned")
}
if typesPkg != nil {
return typesPkg, nil
}
}
return nil, nil
}