Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sample with support for multi-location diagnostics #51

Merged
merged 2 commits into from
Apr 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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