diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index e0f283ecc8e..2de312e716f 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -27,7 +27,12 @@ declare module 'vscode' { /** * */ - export function getDiagnostics(resource?: Uri): Diagnostic[]; + export function getDiagnostics(resource: Uri): Diagnostic[]; + + /** + * + */ + export function getDiagnostics(): [Uri, Diagnostic[]][]; } //#endregion diff --git a/src/vs/workbench/api/node/extHost.api.impl.ts b/src/vs/workbench/api/node/extHost.api.impl.ts index ac851683c8f..95a283b53b4 100644 --- a/src/vs/workbench/api/node/extHost.api.impl.ts +++ b/src/vs/workbench/api/node/extHost.api.impl.ts @@ -236,7 +236,7 @@ export function createApiFactory( checkProposedApiEnabled(extension); return extHostDiagnostics.onDidChangeDiagnostics; }, - getDiagnostics: proposedApiFunction(extension, resource => { + getDiagnostics: proposedApiFunction(extension, (resource?) => { return extHostDiagnostics.getDiagnostics(resource); }), getLanguages(): TPromise { diff --git a/src/vs/workbench/api/node/extHostDiagnostics.ts b/src/vs/workbench/api/node/extHostDiagnostics.ts index 661728303f0..342060762d7 100644 --- a/src/vs/workbench/api/node/extHostDiagnostics.ts +++ b/src/vs/workbench/api/node/extHostDiagnostics.ts @@ -261,17 +261,34 @@ export class ExtHostDiagnostics implements ExtHostDiagnosticsShape { return result; } - getDiagnostics(resource?: vscode.Uri): vscode.Diagnostic[] { + getDiagnostics(resource: vscode.Uri): vscode.Diagnostic[]; + getDiagnostics(): [vscode.Uri, vscode.Diagnostic[]][]; + getDiagnostics(resource?: vscode.Uri): vscode.Diagnostic[] | [vscode.Uri, vscode.Diagnostic[]][] { + if (resource) { + return this._getDiagnostics(resource); + } else { + let index = new Map(); + let res: [vscode.Uri, vscode.Diagnostic[]][] = []; + for (const collection of this._collections) { + collection.forEach((uri, diagnostics) => { + let idx = index.get(uri.toString()); + if (typeof idx === 'undefined') { + idx = res.length; + index.set(uri.toString(), idx); + res.push([uri, []]); + } + res[idx][1] = res[idx][1].concat(...diagnostics); + }); + } + return res; + } + } + + private _getDiagnostics(resource: vscode.Uri): vscode.Diagnostic[] { let res: vscode.Diagnostic[] = []; for (const collection of this._collections) { - if (resource) { - // filtered - if (collection.has(resource)) { - res = res.concat(collection.get(resource)); - } - } else { - // all - collection.forEach((uri, diag) => res = res.concat(diag)); + if (collection.has(resource)) { + res = res.concat(collection.get(resource)); } } return res;