Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit c855987

Browse files
authored
Accept import paths like golang_org/x/* (#357)
1 parent 267fa34 commit c855987

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

gosrc/import_path.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,29 @@ func resolveStaticImportPath(importPath string) (*Directory, error) {
118118
VCS: "git",
119119
}, nil
120120

121+
// The next two cases check for dependencies that actually come from the Go
122+
// standard library. This approach to resolving the import paths could link
123+
// the user to a newer version of a golang/org/x/ package than what is in use
124+
// when go-langserver is released. That's acceptable because we don't support
125+
// multiple Go versions, we don't publish which Go version our language server
126+
// is using anywhere, and these dependencies are very rare in practive (99% of
127+
// users are unlikely to encounter them).
121128
case strings.HasPrefix(importPath, "golang.org/x/"):
122129
d, err := resolveStaticImportPath(strings.Replace(importPath, "golang.org/x/", "github.com/golang/", 1))
123130
if err != nil {
124131
return nil, err
125132
}
126133
d.ProjectRoot = strings.Replace(d.ProjectRoot, "github.com/golang/", "golang.org/x/", 1)
127134
return d, nil
135+
136+
// This is the same as the previous case, except with the `.` replaced with an `_`.
137+
case strings.HasPrefix(importPath, "golang_org/x/"):
138+
d, err := resolveStaticImportPath(strings.Replace(importPath, "golang_org/x/", "github.com/golang/", 1))
139+
if err != nil {
140+
return nil, err
141+
}
142+
d.ProjectRoot = strings.Replace(d.ProjectRoot, "github.com/golang/", "golang_org/x/", 1)
143+
return d, nil
128144
}
129145
return nil, errNoMatch
130146
}

0 commit comments

Comments
 (0)