From 2a3f5192be2e07bdd7fb3acc42f44f67f69c9343 Mon Sep 17 00:00:00 2001 From: Ian Cottrell Date: Wed, 14 Nov 2018 20:02:22 -0500 Subject: [PATCH] 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 Reviewed-by: Rebecca Stambler TryBot-Result: Gobot Gobot --- internal/lsp/source/uri.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/lsp/source/uri.go b/internal/lsp/source/uri.go index 2d7049f6..59429292 100644 --- a/internal/lsp/source/uri.go +++ b/internal/lsp/source/uri.go @@ -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)) }