From 0c4d2e0ecc27f6ca3095be241c72f995bc0edf2f Mon Sep 17 00:00:00 2001 From: kieferrm Date: Wed, 21 Mar 2018 15:54:49 -0700 Subject: [PATCH 1/2] support for multi-location diagnostics --- lsp-sample/server/src/server.ts | 34 +++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/lsp-sample/server/src/server.ts b/lsp-sample/server/src/server.ts index a86ee66c5..0242d812c 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.diagnosticRelatedInformation; 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. From 227d7cb0015735d07a4a1c80827ed913faf2c804 Mon Sep 17 00:00:00 2001 From: kieferrm Date: Wed, 28 Mar 2018 11:16:55 -0700 Subject: [PATCH 2/2] move capabilities to textDocument --- lsp-sample/server/src/server.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lsp-sample/server/src/server.ts b/lsp-sample/server/src/server.ts index 0242d812c..1cbf1ef52 100644 --- a/lsp-sample/server/src/server.ts +++ b/lsp-sample/server/src/server.ts @@ -26,7 +26,7 @@ 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.diagnosticRelatedInformation; + 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