|
7 | 7 | "go/token"
|
8 | 8 | "os"
|
9 | 9 | "path/filepath"
|
10 |
| - "strings" |
11 | 10 | )
|
12 | 11 |
|
13 | 12 | // Importer Go source type analyzer
|
@@ -80,47 +79,15 @@ func (i *Importer) FileSet() *token.FileSet {
|
80 | 79 | return i.fset
|
81 | 80 | }
|
82 | 81 |
|
83 |
| -func (i *Importer) importPath(path string, src string) (string, string, error) { |
| 82 | +// ImportBuild returns details about the Go package named by the import path. |
| 83 | +func (i *Importer) ImportBuild(path string, src string) (*build.Package, error) { |
84 | 84 | if !filepath.IsAbs(src) {
|
85 | 85 | abs, err := filepath.Abs(src)
|
86 | 86 | if err != nil {
|
87 |
| - return "", "", err |
| 87 | + return nil, err |
88 | 88 | }
|
89 | 89 | src = abs
|
90 | 90 | }
|
91 |
| - |
92 |
| - // If modules are not enabled, then the in-process code works fine and we should keep using it. |
93 |
| - switch os.Getenv("GO111MODULE") { |
94 |
| - case "off": |
95 |
| - return path, src, nil |
96 |
| - case "on": |
97 |
| - // ok |
98 |
| - default: // "", "auto", anything else |
99 |
| - // Automatic mode: no module use in $GOPATH/src. |
100 |
| - for _, root := range i.gopath { |
101 |
| - if strings.HasPrefix(src, filepath.Join(root, "src")) { |
102 |
| - return path, src, nil |
103 |
| - } |
104 |
| - } |
105 |
| - } |
106 |
| - |
107 |
| - for _, root := range i.gopath { |
108 |
| - if strings.HasPrefix(src, filepath.Join(root, "pkg", "mod")) { |
109 |
| - src, _ = os.Getwd() |
110 |
| - return path, src, nil |
111 |
| - } |
112 |
| - } |
113 |
| - |
114 |
| - return path, src, nil |
115 |
| -} |
116 |
| - |
117 |
| -// ImportBuild returns details about the Go package named by the import path. |
118 |
| -func (i *Importer) ImportBuild(path string, src string) (*build.Package, error) { |
119 |
| - path, src, err := i.importPath(path, src) |
120 |
| - if err != nil { |
121 |
| - return nil, err |
122 |
| - } |
123 |
| - |
124 | 91 | k := path + " " + src
|
125 | 92 | if v, ok := i.bufBuild[k]; ok {
|
126 | 93 | return v, nil
|
|
0 commit comments