mirror of
https://github.com/golang/go.git
synced 2025-05-05 23:53:05 +00:00
This moves the fileset down to the base cache, the overlays down to the session and stores the environment on the view. packages.Config is no longer part of any public API, and the config is build on demand by combining all the layers of cache. Also added some documentation to the main source pacakge interfaces. Change-Id: I058092ad2275d433864d1f58576fc55e194607a6 Reviewed-on: https://go-review.googlesource.com/c/tools/+/178017 Run-TryBot: Ian Cottrell <iancottrell@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
74 lines
1.6 KiB
Go
74 lines
1.6 KiB
Go
// Copyright 2019 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package lsp
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"os/exec"
|
|
|
|
"golang.org/x/tools/internal/lsp/protocol"
|
|
"golang.org/x/tools/internal/lsp/source"
|
|
"golang.org/x/tools/internal/span"
|
|
)
|
|
|
|
// This writes the version and environment information to a writer.
|
|
func PrintVersionInfo(w io.Writer, verbose bool, markdown bool) {
|
|
if !verbose {
|
|
printBuildInfo(w, false)
|
|
return
|
|
}
|
|
fmt.Fprint(w, "#### Build info\n\n")
|
|
if markdown {
|
|
fmt.Fprint(w, "```\n")
|
|
}
|
|
printBuildInfo(w, true)
|
|
fmt.Fprint(w, "\n")
|
|
if markdown {
|
|
fmt.Fprint(w, "```\n")
|
|
}
|
|
fmt.Fprint(w, "\n#### Go info\n\n")
|
|
if markdown {
|
|
fmt.Fprint(w, "```\n")
|
|
}
|
|
cmd := exec.Command("go", "version")
|
|
cmd.Stdout = w
|
|
cmd.Run()
|
|
fmt.Fprint(w, "\n")
|
|
cmd = exec.Command("go", "env")
|
|
cmd.Stdout = w
|
|
cmd.Run()
|
|
if markdown {
|
|
fmt.Fprint(w, "```\n")
|
|
}
|
|
}
|
|
|
|
func getSourceFile(ctx context.Context, v source.View, uri span.URI) (source.File, *protocol.ColumnMapper, error) {
|
|
f, err := v.GetFile(ctx, uri)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
filename, err := f.URI().Filename()
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
m := protocol.NewColumnMapper(f.URI(), filename, f.FileSet(), f.GetToken(ctx), f.GetContent(ctx))
|
|
|
|
return f, m, nil
|
|
}
|
|
|
|
func getGoFile(ctx context.Context, v source.View, uri span.URI) (source.GoFile, *protocol.ColumnMapper, error) {
|
|
f, m, err := getSourceFile(ctx, v, uri)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
gof, ok := f.(source.GoFile)
|
|
if !ok {
|
|
return nil, nil, fmt.Errorf("not a go file %v", f.URI())
|
|
}
|
|
return gof, m, nil
|
|
}
|