diff --git a/lsp-sample/server/src/server.ts b/lsp-sample/server/src/server.ts index a86ee66c5..1cbf1ef52 100644 --- a/lsp-sample/server/src/server.ts +++ b/lsp-sample/server/src/server.ts @@ -20,9 +20,13 @@ let documents: TextDocuments = new TextDocuments(); // for open, change and close text document events documents.listen(connection); + +let shouldSendDiagnosticRelatedInformation: boolean = false; + // After the server has started the client sends an initialize request. The server receives // in the passed params the rootPath of the workspace plus the client capabilities. connection.onInitialize((_params): InitializeResult => { + shouldSendDiagnosticRelatedInformation = _params.capabilities && _params.capabilities.textDocument && _params.capabilities.textDocument.publishDiagnostics && _params.capabilities.textDocument.publishDiagnostics.relatedInformation; return { capabilities: { // Tell the client that the server works in FULL text document sync mode @@ -72,7 +76,8 @@ function validateTextDocument(textDocument: TextDocument): void { let index = line.indexOf('typescript'); if (index >= 0) { problems++; - diagnostics.push({ + + let diagnosic: Diagnostic = { severity: DiagnosticSeverity.Warning, range: { start: { line: i, character: index }, @@ -80,7 +85,32 @@ function validateTextDocument(textDocument: TextDocument): void { }, message: `${line.substr(index, 10)} should be spelled TypeScript`, source: 'ex' - }); + }; + if (shouldSendDiagnosticRelatedInformation) { + diagnosic.relatedInformation = [ + { + location: { + uri: textDocument.uri, + range: { + start: { line: i, character: index }, + end: { line: i, character: index + 10 } + } + }, + message: 'Spelling matters' + }, + { + location: { + uri: textDocument.uri, + range: { + start: { line: i, character: index }, + end: { line: i, character: index + 10 } + } + }, + message: 'Particularly for names' + } + ]; + } + diagnostics.push(diagnosic); } } // Send the computed diagnostics to VSCode.