internal/lsp: handle $GOROOT in file paths
This happens whenever we load standard library information from export data, and prevents the editor from understanding the file names Change-Id: If5c04176a3e669ba396f322275993616e51ec097 Reviewed-on: https://go-review.googlesource.com/c/149612 Run-TryBot: Ian Cottrell <iancottrell@google.com> Reviewed-by: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
6778892796
commit
2a3f5192be
|
@ -8,6 +8,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -36,5 +37,11 @@ func (uri URI) Filename() (string, error) {
|
||||||
// ToURI returns a protocol URI for the supplied path.
|
// ToURI returns a protocol URI for the supplied path.
|
||||||
// It will always have the file scheme.
|
// It will always have the file scheme.
|
||||||
func ToURI(path string) URI {
|
func ToURI(path string) URI {
|
||||||
|
const prefix = "$GOROOT"
|
||||||
|
if strings.EqualFold(prefix, path[:len(prefix)]) {
|
||||||
|
suffix := path[len(prefix):]
|
||||||
|
//TODO: we need a better way to get the GOROOT that uses the packages api
|
||||||
|
path = runtime.GOROOT() + suffix
|
||||||
|
}
|
||||||
return URI(fileSchemePrefix + filepath.ToSlash(path))
|
return URI(fileSchemePrefix + filepath.ToSlash(path))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue