mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-06-13 07:10:26 +08:00
Merge pull request #51 from kieferrm/multi-location-diagnostics
Update sample with support for multi-location diagnostics
This commit is contained in:
@ -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.
|
||||
|
||||
Reference in New Issue
Block a user