@@ -10,37 +10,44 @@ import (
10
10
11
11
func (l * LanguageService ) GetDocumentDiagnostics (ctx context.Context , documentURI lsproto.DocumentUri ) (* lsproto.DocumentDiagnosticReport , error ) {
12
12
program , file := l .getProgramAndFile (documentURI )
13
- syntaxDiagnostics := program .GetSyntacticDiagnostics (ctx , file )
14
- var lspDiagnostics []* lsproto.Diagnostic
15
- if len (syntaxDiagnostics ) != 0 {
16
- lspDiagnostics = make ([]* lsproto.Diagnostic , 0 , len (syntaxDiagnostics ))
17
- for _ , diag := range syntaxDiagnostics {
18
- lspDiagnostics = append (lspDiagnostics , toLSPDiagnostic (diag , l .converters ))
19
- }
20
- } else {
21
- diagnostics := program .GetSemanticDiagnostics (ctx , file )
22
- suggestionDiagnostics := program .GetSuggestionDiagnostics (ctx , file )
23
13
24
- lspDiagnostics = make ([]* lsproto.Diagnostic , 0 , len (diagnostics )+ len (suggestionDiagnostics ))
25
- for _ , diag := range diagnostics {
26
- lspDiagnostics = append (lspDiagnostics , toLSPDiagnostic (diag , l .converters ))
27
- }
28
- for _ , diag := range suggestionDiagnostics {
29
- // !!! user preference for suggestion diagnostics; keep only unnecessary/dprecated?
30
- lspDiagnostics = append (lspDiagnostics , toLSPDiagnostic (diag , l .converters ))
14
+ diagnostics := make ([][]* ast.Diagnostic , 0 , 3 )
15
+ if syntaxDiagnostics := program .GetSyntacticDiagnostics (ctx , file ); len (syntaxDiagnostics ) != 0 {
16
+ diagnostics = append (diagnostics , syntaxDiagnostics )
17
+ } else {
18
+ diagnostics = append (diagnostics , program .GetSemanticDiagnostics (ctx , file ))
19
+ // !!! user preference for suggestion diagnostics; keep only unnecessary/deprecated?
20
+ // See: https://github.com/microsoft/vscode/blob/3dbc74129aaae102e5cb485b958fa5360e8d3e7a/extensions/typescript-language-features/src/languageFeatures/diagnostics.ts#L114
21
+ diagnostics = append (diagnostics , program .GetSuggestionDiagnostics (ctx , file ))
22
+ if program .Options ().GetEmitDeclarations () {
23
+ diagnostics = append (diagnostics , program .GetDeclarationDiagnostics (ctx , file ))
31
24
}
32
25
}
26
+
33
27
return & lsproto.DocumentDiagnosticReport {
34
28
RelatedFullDocumentDiagnosticReport : & lsproto.RelatedFullDocumentDiagnosticReport {
35
29
FullDocumentDiagnosticReport : lsproto.FullDocumentDiagnosticReport {
36
- Kind : lsproto.StringLiteralFull {},
37
- Items : lspDiagnostics ,
30
+ Items : toLSPDiagnostics (l .converters , diagnostics ... ),
38
31
},
39
32
},
40
33
}, nil
41
34
}
42
35
43
- func toLSPDiagnostic (diagnostic * ast.Diagnostic , converters * Converters ) * lsproto.Diagnostic {
36
+ func toLSPDiagnostics (converters * Converters , diagnostics ... []* ast.Diagnostic ) []* lsproto.Diagnostic {
37
+ size := 0
38
+ for _ , diagSlice := range diagnostics {
39
+ size += len (diagSlice )
40
+ }
41
+ lspDiagnostics := make ([]* lsproto.Diagnostic , 0 , size )
42
+ for _ , diagSlice := range diagnostics {
43
+ for _ , diag := range diagSlice {
44
+ lspDiagnostics = append (lspDiagnostics , toLSPDiagnostic (converters , diag ))
45
+ }
46
+ }
47
+ return lspDiagnostics
48
+ }
49
+
50
+ func toLSPDiagnostic (converters * Converters , diagnostic * ast.Diagnostic ) * lsproto.Diagnostic {
44
51
var severity lsproto.DiagnosticSeverity
45
52
switch diagnostic .Category () {
46
53
case diagnostics .CategorySuggestion :
0 commit comments