@@ -2,6 +2,7 @@ package ls
22
33import (
44 "context"
5+ "slices"
56 "strings"
67
78 "github.com/microsoft/typescript-go/internal/ast"
@@ -11,7 +12,7 @@ import (
1112 "github.com/microsoft/typescript-go/internal/lsp/lsproto"
1213)
1314
14- func (l * LanguageService ) ProvideDiagnostics (ctx context.Context , uri lsproto.DocumentUri ) (lsproto.DocumentDiagnosticResponse , error ) {
15+ func (l * LanguageService ) ProvideDiagnostics (ctx context.Context , uri lsproto.DocumentUri , clientOptions * lsproto. DiagnosticClientCapabilities ) (lsproto.DocumentDiagnosticResponse , error ) {
1516 program , file := l .getProgramAndFile (uri )
1617
1718 diagnostics := make ([][]* ast.Diagnostic , 0 , 4 )
@@ -26,26 +27,26 @@ func (l *LanguageService) ProvideDiagnostics(ctx context.Context, uri lsproto.Do
2627
2728 return lsproto.RelatedFullDocumentDiagnosticReportOrUnchangedDocumentDiagnosticReport {
2829 FullDocumentDiagnosticReport : & lsproto.RelatedFullDocumentDiagnosticReport {
29- Items : toLSPDiagnostics ( l . converters , diagnostics ... ),
30+ Items : l . toLSPDiagnostics ( clientOptions , diagnostics ... ),
3031 },
3132 }, nil
3233}
3334
34- func toLSPDiagnostics (converters * lsconv. Converters , diagnostics ... []* ast.Diagnostic ) []* lsproto.Diagnostic {
35+ func ( l * LanguageService ) toLSPDiagnostics (clientOptions * lsproto. DiagnosticClientCapabilities , diagnostics ... []* ast.Diagnostic ) []* lsproto.Diagnostic {
3536 size := 0
3637 for _ , diagSlice := range diagnostics {
3738 size += len (diagSlice )
3839 }
3940 lspDiagnostics := make ([]* lsproto.Diagnostic , 0 , size )
4041 for _ , diagSlice := range diagnostics {
4142 for _ , diag := range diagSlice {
42- lspDiagnostics = append (lspDiagnostics , toLSPDiagnostic (converters , diag ))
43+ lspDiagnostics = append (lspDiagnostics , l . toLSPDiagnostic (clientOptions , diag ))
4344 }
4445 }
4546 return lspDiagnostics
4647}
4748
48- func toLSPDiagnostic (converters * lsconv. Converters , diagnostic * ast.Diagnostic ) * lsproto.Diagnostic {
49+ func ( l * LanguageService ) toLSPDiagnostic (clientOptions * lsproto. DiagnosticClientCapabilities , diagnostic * ast.Diagnostic ) * lsproto.Diagnostic {
4950 var severity lsproto.DiagnosticSeverity
5051 switch diagnostic .Category () {
5152 case diagnostics .CategorySuggestion :
@@ -58,30 +59,33 @@ func toLSPDiagnostic(converters *lsconv.Converters, diagnostic *ast.Diagnostic)
5859 severity = lsproto .DiagnosticSeverityError
5960 }
6061
61- relatedInformation := make ([]* lsproto.DiagnosticRelatedInformation , 0 , len (diagnostic .RelatedInformation ()))
62- for _ , related := range diagnostic .RelatedInformation () {
63- relatedInformation = append (relatedInformation , & lsproto.DiagnosticRelatedInformation {
64- Location : lsproto.Location {
65- Uri : lsconv .FileNameToDocumentURI (related .File ().FileName ()),
66- Range : converters .ToLSPRange (related .File (), related .Loc ()),
67- },
68- Message : related .Message (),
69- })
62+ var relatedInformation []* lsproto.DiagnosticRelatedInformation
63+ if clientOptions != nil && ptrIsTrue (clientOptions .RelatedInformation ) {
64+ relatedInformation = make ([]* lsproto.DiagnosticRelatedInformation , 0 , len (diagnostic .RelatedInformation ()))
65+ for _ , related := range diagnostic .RelatedInformation () {
66+ relatedInformation = append (relatedInformation , & lsproto.DiagnosticRelatedInformation {
67+ Location : lsproto.Location {
68+ Uri : lsconv .FileNameToDocumentURI (related .File ().FileName ()),
69+ Range : l .converters .ToLSPRange (related .File (), related .Loc ()),
70+ },
71+ Message : related .Message (),
72+ })
73+ }
7074 }
7175
7276 var tags []lsproto.DiagnosticTag
73- if diagnostic .ReportsUnnecessary () || diagnostic .ReportsDeprecated () {
77+ if clientOptions != nil && clientOptions . TagSupport != nil && ( diagnostic .ReportsUnnecessary () || diagnostic .ReportsDeprecated () ) {
7478 tags = make ([]lsproto.DiagnosticTag , 0 , 2 )
75- if diagnostic .ReportsUnnecessary () {
79+ if diagnostic .ReportsUnnecessary () && slices . Contains ( clientOptions . TagSupport . ValueSet , lsproto . DiagnosticTagUnnecessary ) {
7680 tags = append (tags , lsproto .DiagnosticTagUnnecessary )
7781 }
78- if diagnostic .ReportsDeprecated () {
82+ if diagnostic .ReportsDeprecated () && slices . Contains ( clientOptions . TagSupport . ValueSet , lsproto . DiagnosticTagDeprecated ) {
7983 tags = append (tags , lsproto .DiagnosticTagDeprecated )
8084 }
8185 }
8286
8387 return & lsproto.Diagnostic {
84- Range : converters .ToLSPRange (diagnostic .File (), diagnostic .Loc ()),
88+ Range : l . converters .ToLSPRange (diagnostic .File (), diagnostic .Loc ()),
8589 Code : & lsproto.IntegerOrString {
8690 Integer : ptrTo (diagnostic .Code ()),
8791 },
0 commit comments