mirror of
https://github.com/golang/go
synced 2024-11-18 18:04:46 -07:00
internal/lsp: delay the running of gofmt until the test is running
Change-Id: I222c83313a6366367fbeb7ce7d08058968d3a08e Reviewed-on: https://go-review.googlesource.com/c/tools/+/173340 Run-TryBot: Ian Cottrell <iancottrell@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
2acd0f4c51
commit
18110c573c
@ -9,6 +9,8 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"go/token"
|
||||
"os"
|
||||
"os/exec"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
@ -226,8 +228,24 @@ func summarizeCompletionItems(i int, want []source.CompletionItem, got []protoco
|
||||
|
||||
func (r *runner) Format(t *testing.T, data tests.Formats) {
|
||||
ctx := context.Background()
|
||||
for filename, gofmted := range data {
|
||||
uri := span.FileURI(filename)
|
||||
for _, spn := range data {
|
||||
uri := spn.URI()
|
||||
filename, err := uri.Filename()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
gofmted := string(r.data.Golden("gofmt", filename, func(golden string) error {
|
||||
cmd := exec.Command("gofmt", filename)
|
||||
stdout, err := os.Create(golden)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer stdout.Close()
|
||||
cmd.Stdout = stdout
|
||||
cmd.Run() // ignore error, sometimes we have intentionally ungofmt-able files
|
||||
return nil
|
||||
}))
|
||||
|
||||
edits, err := r.server.Formatting(context.Background(), &protocol.DocumentFormattingParams{
|
||||
TextDocument: protocol.TextDocumentIdentifier{
|
||||
URI: protocol.NewURI(uri),
|
||||
|
@ -11,7 +11,6 @@ import (
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
@ -50,7 +49,7 @@ var updateGolden = flag.Bool("golden", false, "Update golden files")
|
||||
type Diagnostics map[span.URI][]source.Diagnostic
|
||||
type CompletionItems map[token.Pos]*source.CompletionItem
|
||||
type Completions map[span.Span][]token.Pos
|
||||
type Formats map[string]string
|
||||
type Formats []span.Span
|
||||
type Definitions map[span.Span]Definition
|
||||
type Highlights map[string][]span.Span
|
||||
type Symbols map[span.URI][]source.Symbol
|
||||
@ -100,7 +99,6 @@ func Load(t testing.TB, exporter packagestest.Exporter, dir string) *Data {
|
||||
Diagnostics: make(Diagnostics),
|
||||
CompletionItems: make(CompletionItems),
|
||||
Completions: make(Completions),
|
||||
Formats: make(Formats),
|
||||
Definitions: make(Definitions),
|
||||
Highlights: make(Highlights),
|
||||
Symbols: make(Symbols),
|
||||
@ -317,18 +315,8 @@ func (data *Data) collectCompletionItems(pos token.Pos, label, detail, kind stri
|
||||
}
|
||||
}
|
||||
|
||||
func (data *Data) collectFormats(pos token.Position) {
|
||||
data.Formats[pos.Filename] = string(data.Golden("gofmt", pos.Filename, func(golden string) error {
|
||||
cmd := exec.Command("gofmt", pos.Filename)
|
||||
stdout, err := os.Create(golden)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer stdout.Close()
|
||||
cmd.Stdout = stdout
|
||||
cmd.Run() // ignore error, sometimes we have intentionally ungofmt-able files
|
||||
return nil
|
||||
}))
|
||||
func (data *Data) collectFormats(spn span.Span) {
|
||||
data.Formats = append(data.Formats, spn)
|
||||
}
|
||||
|
||||
func (data *Data) collectDefinitions(src, target span.Span) {
|
||||
|
Loading…
Reference in New Issue
Block a user