@@ -20,9 +20,13 @@ let documents: TextDocuments = new TextDocuments();
20
20
// for open, change and close text document events
21
21
documents . listen ( connection ) ;
22
22
23
+
24
+ let shouldSendDiagnosticRelatedInformation : boolean = false ;
25
+
23
26
// After the server has started the client sends an initialize request. The server receives
24
27
// in the passed params the rootPath of the workspace plus the client capabilities.
25
28
connection . onInitialize ( ( _params ) : InitializeResult => {
29
+ shouldSendDiagnosticRelatedInformation = _params . capabilities && _params . capabilities . textDocument && _params . capabilities . textDocument . publishDiagnostics && _params . capabilities . textDocument . publishDiagnostics . relatedInformation ;
26
30
return {
27
31
capabilities : {
28
32
// Tell the client that the server works in FULL text document sync mode
@@ -72,15 +76,41 @@ function validateTextDocument(textDocument: TextDocument): void {
72
76
let index = line . indexOf ( 'typescript' ) ;
73
77
if ( index >= 0 ) {
74
78
problems ++ ;
75
- diagnostics . push ( {
79
+
80
+ let diagnosic : Diagnostic = {
76
81
severity : DiagnosticSeverity . Warning ,
77
82
range : {
78
83
start : { line : i , character : index } ,
79
84
end : { line : i , character : index + 10 }
80
85
} ,
81
86
message : `${ line . substr ( index , 10 ) } should be spelled TypeScript` ,
82
87
source : 'ex'
83
- } ) ;
88
+ } ;
89
+ if ( shouldSendDiagnosticRelatedInformation ) {
90
+ diagnosic . relatedInformation = [
91
+ {
92
+ location : {
93
+ uri : textDocument . uri ,
94
+ range : {
95
+ start : { line : i , character : index } ,
96
+ end : { line : i , character : index + 10 }
97
+ }
98
+ } ,
99
+ message : 'Spelling matters'
100
+ } ,
101
+ {
102
+ location : {
103
+ uri : textDocument . uri ,
104
+ range : {
105
+ start : { line : i , character : index } ,
106
+ end : { line : i , character : index + 10 }
107
+ }
108
+ } ,
109
+ message : 'Particularly for names'
110
+ }
111
+ ] ;
112
+ }
113
+ diagnostics . push ( diagnosic ) ;
84
114
}
85
115
}
86
116
// Send the computed diagnostics to VSCode.
0 commit comments