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:
Ian Cottrell 2018-11-14 20:02:22 -05:00
parent 6778892796
commit 2a3f5192be
1 changed files with 7 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import (
"fmt"
"net/url"
"path/filepath"
"runtime"
"strings"
)
@ -36,5 +37,11 @@ func (uri URI) Filename() (string, error) {
// ToURI returns a protocol URI for the supplied path.
// It will always have the file scheme.
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))
}