diff --git a/internal/lsp/lsp_test.go b/internal/lsp/lsp_test.go index 418da42298..840966dee2 100644 --- a/internal/lsp/lsp_test.go +++ b/internal/lsp/lsp_test.go @@ -7,6 +7,7 @@ package lsp import ( "bytes" "context" + "fmt" "go/token" "os/exec" "path/filepath" @@ -184,7 +185,16 @@ func testDiagnostics(t *testing.T, v *source.View, pkgs []*packages.Package, wan }) want := wants[filename] if equal := reflect.DeepEqual(want, got); !equal { - t.Errorf("diagnostics failed for %s: (expected: %v), (got: %v)", filepath.Base(filename), want, got) + msg := &bytes.Buffer{} + fmt.Fprintf(msg, "diagnostics failed for %s: expected:\n", filepath.Base(filename)) + for _, d := range want { + fmt.Fprintf(msg, " %v\n", d) + } + fmt.Fprintf(msg, "got:\n") + for _, d := range got { + fmt.Fprintf(msg, " %v\n", d) + } + t.Error(msg.String()) } } } diff --git a/internal/lsp/protocol/printers.go b/internal/lsp/protocol/printers.go index e658af96b0..f4f80db567 100644 --- a/internal/lsp/protocol/printers.go +++ b/internal/lsp/protocol/printers.go @@ -37,3 +37,20 @@ func (r Range) Format(f fmt.State, c rune) { func (l Location) Format(f fmt.State, c rune) { fmt.Fprintf(f, "%s:%v", l.URI, l.Range) } + +func (s DiagnosticSeverity) Format(f fmt.State, c rune) { + switch s { + case SeverityError: + fmt.Fprint(f, "Error") + case SeverityWarning: + fmt.Fprint(f, "Warning") + case SeverityInformation: + fmt.Fprint(f, "Information") + case SeverityHint: + fmt.Fprint(f, "Hint") + } +} + +func (d Diagnostic) Format(f fmt.State, c rune) { + fmt.Fprintf(f, "%v:%v from %v at %v: %v", d.Severity, d.Code, d.Source, d.Range, d.Message) +} diff --git a/internal/lsp/testdata/bad/bad.go b/internal/lsp/testdata/bad/bad.go index 8500d069e2..75f728ece5 100644 --- a/internal/lsp/testdata/bad/bad.go +++ b/internal/lsp/testdata/bad/bad.go @@ -1,5 +1,3 @@ -// +build go1.11 - package bad func stuff() { @@ -14,8 +12,7 @@ type bob struct { } func _() { - var q int _ = &bob{ - f: q, //@diag("f", "unknown field f in struct literal") + f: 0, //@diag("f", "unknown field f in struct literal") } } diff --git a/internal/lsp/testdata/bad/bad_util.go b/internal/lsp/testdata/bad/bad_util.go index f6a0e7d994..9ab8a73efd 100644 --- a/internal/lsp/testdata/bad/bad_util.go +++ b/internal/lsp/testdata/bad/bad_util.go @@ -1,5 +1,3 @@ -// +build go1.11 - package bad func random2(y int) int { diff --git a/internal/lsp/testdata/noparse_format/noparse_format.1_10.go.in b/internal/lsp/testdata/noparse_format/noparse_format.1_10.go.in new file mode 100644 index 0000000000..f450053a63 --- /dev/null +++ b/internal/lsp/testdata/noparse_format/noparse_format.1_10.go.in @@ -0,0 +1,11 @@ +// +build !go1.11 + +// This file does not actually test anything +// on 1.10 the errors are different +package noparse_format + +func what() { + // we need a diagnostic below so we have the same count as the main file + var b int //@diag("b", "b declared but not used") + if true {} +} \ No newline at end of file