Skip to content

Commit

Permalink
Merge pull request #51 from kieferrm/multi-location-diagnostics
Browse files Browse the repository at this point in the history
Update sample with support for multi-location diagnostics
  • Loading branch information
dbaeumer authored Apr 9, 2018
2 parents 78ecd9b + 227d7cb commit 72df9f9
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions lsp-sample/server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -72,15 +76,41 @@ 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 },
end: { line: i, character: index + 10 }
},
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.
Expand Down

0 comments on commit 72df9f9

Please sign in to comment.