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>
diff --git a/internal/lsp/source/uri.go b/internal/lsp/source/uri.go
index 2d7049f..5942929 100644
--- a/internal/lsp/source/uri.go
+++ b/internal/lsp/source/uri.go
@@ -8,6 +8,7 @@
 	"fmt"
 	"net/url"
 	"path/filepath"
+	"runtime"
 	"strings"
 )
 
@@ -36,5 +37,11 @@
 // 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))
 }