2019-04-17 13:37:20 -06:00
|
|
|
// 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"
|
2019-05-03 12:31:03 -06:00
|
|
|
"io"
|
|
|
|
"os/exec"
|
2019-04-17 13:37:20 -06:00
|
|
|
|
|
|
|
"golang.org/x/tools/internal/lsp/protocol"
|
|
|
|
"golang.org/x/tools/internal/lsp/source"
|
|
|
|
"golang.org/x/tools/internal/span"
|
|
|
|
)
|
|
|
|
|
2019-05-03 12:31:03 -06:00
|
|
|
// 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")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-03 22:04:18 -06:00
|
|
|
func getSourceFile(ctx context.Context, v source.View, uri span.URI) (source.File, *protocol.ColumnMapper, error) {
|
2019-04-17 13:37:20 -06:00
|
|
|
f, err := v.GetFile(ctx, uri)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
2019-05-17 11:45:50 -06:00
|
|
|
|
|
|
|
fname, err := f.URI().Filename()
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
2019-04-17 13:37:20 -06:00
|
|
|
}
|
2019-05-17 11:45:50 -06:00
|
|
|
|
|
|
|
m := protocol.NewColumnMapper(f.URI(), fname, f.GetFileSet(ctx), f.GetToken(ctx), f.GetContent(ctx))
|
|
|
|
|
2019-04-17 13:37:20 -06:00
|
|
|
return f, m, nil
|
|
|
|
}
|
2019-05-03 22:04:18 -06:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|