Skip to content

Commit 808d126

Browse files
author
徐尚
committed
remove importPath
1 parent 6b97b36 commit 808d126

File tree

2 files changed

+19
-36
lines changed

2 files changed

+19
-36
lines changed

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
13+
14+
# Dependency directories (remove the comment below to include it)
15+
# vendor/
16+
.vscode
117
.idea

importer.go

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"go/token"
88
"os"
99
"path/filepath"
10-
"strings"
1110
)
1211

1312
// Importer Go source type analyzer
@@ -80,47 +79,15 @@ func (i *Importer) FileSet() *token.FileSet {
8079
return i.fset
8180
}
8281

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) {
8484
if !filepath.IsAbs(src) {
8585
abs, err := filepath.Abs(src)
8686
if err != nil {
87-
return "", "", err
87+
return nil, err
8888
}
8989
src = abs
9090
}
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-
12491
k := path + " " + src
12592
if v, ok := i.bufBuild[k]; ok {
12693
return v, nil

0 commit comments

Comments
 (0)