Skip to content

Commit cf0c2c5

Browse files
authored
Include full diagnostic chains in LSP diagnostics (#1105)
1 parent fdd1de5 commit cf0c2c5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

internal/ls/diagnostics.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package ls
22

33
import (
44
"context"
5+
"strings"
56

67
"github.com/microsoft/typescript-go/internal/ast"
78
"github.com/microsoft/typescript-go/internal/diagnostics"
9+
"github.com/microsoft/typescript-go/internal/diagnosticwriter"
810
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
911
)
1012

@@ -88,13 +90,22 @@ func toLSPDiagnostic(converters *Converters, diagnostic *ast.Diagnostic) *lsprot
8890
Integer: ptrTo(diagnostic.Code()),
8991
},
9092
Severity: &severity,
91-
Message: diagnostic.Message(),
93+
Message: messageChainToString(diagnostic),
9294
Source: ptrTo("ts"),
9395
RelatedInformation: ptrToSliceIfNonEmpty(relatedInformation),
9496
Tags: ptrToSliceIfNonEmpty(tags),
9597
}
9698
}
9799

100+
func messageChainToString(diagnostic *ast.Diagnostic) string {
101+
if len(diagnostic.MessageChain()) == 0 {
102+
return diagnostic.Message()
103+
}
104+
var b strings.Builder
105+
diagnosticwriter.WriteFlattenedDiagnosticMessage(&b, diagnostic, "\n")
106+
return b.String()
107+
}
108+
98109
func ptrToSliceIfNonEmpty[T any](s []T) *[]T {
99110
if len(s) == 0 {
100111
return nil

0 commit comments

Comments
 (0)