aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/logopt
diff options
context:
space:
mode:
authorDavid Chase <drchase@google.com>2019-10-30 13:36:37 -0400
committerDavid Chase <drchase@google.com>2019-11-12 22:09:05 +0000
commita56d755f41461bd3a1eb700b0095d82f7a812c1a (patch)
tree7b2caf61d82858f7a054d1cd80b66bf19f128dfb /src/cmd/compile/internal/logopt
parent97d0505334c71a8d7a1e7431c1e1515c93b59e2b (diff)
downloadgo-a56d755f41461bd3a1eb700b0095d82f7a812c1a.tar.gz
go-a56d755f41461bd3a1eb700b0095d82f7a812c1a.zip
cmd/compile: expand initial $GOROOT in optimizer logging json/lsp file names
Change-Id: I9596536e04aef034623b51b42f44e4978f07ac47 Reviewed-on: https://go-review.googlesource.com/c/go/+/204339 Run-TryBot: David Chase <drchase@google.com> Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'src/cmd/compile/internal/logopt')
-rw-r--r--src/cmd/compile/internal/logopt/log_opts.go17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/cmd/compile/internal/logopt/log_opts.go b/src/cmd/compile/internal/logopt/log_opts.go
index 2ce4d29ff8..4064054593 100644
--- a/src/cmd/compile/internal/logopt/log_opts.go
+++ b/src/cmd/compile/internal/logopt/log_opts.go
@@ -364,6 +364,15 @@ func uriIfy(f string) DocumentURI {
return DocumentURI(url.String())
}
+// Return filename, replacing a first occurrence of $GOROOT with the
+// actual value of the GOROOT (because LSP does not speak "$GOROOT").
+func uprootedPath(filename string) string {
+ if ! strings.HasPrefix(filename, "$GOROOT/") {
+ return filename
+ }
+ return objabi.GOROOT + filename[len("$GOROOT"):]
+}
+
// FlushLoggedOpts flushes all the accumulated optimization log entries.
func FlushLoggedOpts(ctxt *obj.Link, slashPkgPath string) {
if Format == None {
@@ -399,12 +408,12 @@ func FlushLoggedOpts(ctxt *obj.Link, slashPkgPath string) {
}
p0 := posTmp[0]
-
- if currentFile != p0.Filename() {
+ p0f := uprootedPath(p0.Filename())
+ if currentFile != p0f {
if w != nil {
w.Close()
}
- currentFile = p0.Filename()
+ currentFile = p0f
w = writerForLSP(subdirpath, currentFile)
encoder = json.NewEncoder(w)
encoder.Encode(VersionHeader{Version: 0, Package: slashPkgPath, Goos: objabi.GOOS, Goarch: objabi.GOARCH, GcVersion: objabi.Version, File: currentFile})
@@ -424,7 +433,7 @@ func FlushLoggedOpts(ctxt *obj.Link, slashPkgPath string) {
for i := 1; i < l; i++ {
p := posTmp[i]
- loc := Location{URI: uriIfy(p.Filename()),
+ loc := Location{URI: uriIfy(uprootedPath(p.Filename())),
Range: Range{Start: Position{p.Line(), p.Col()},
End: Position{p.Line(), p.Col()}}}
diagnostic.RelatedInformation = append(diagnostic.RelatedInformation, DiagnosticRelatedInformation{Location: loc, Message: "inlineLoc"})