Skip to content

Commit

Permalink
try a different variant of getDiagnostics... #30075
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Mar 15, 2018
1 parent 2775e75 commit 5685bcd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
7 changes: 6 additions & 1 deletion src/vs/vscode.proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/node/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export function createApiFactory(
checkProposedApiEnabled(extension);
return extHostDiagnostics.onDidChangeDiagnostics;
},
getDiagnostics: proposedApiFunction(extension, resource => {
getDiagnostics: <any>proposedApiFunction(extension, (resource?) => {
return extHostDiagnostics.getDiagnostics(resource);
}),
getLanguages(): TPromise<string[]> {
Expand Down
35 changes: 26 additions & 9 deletions src/vs/workbench/api/node/extHostDiagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, number>();
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;
Expand Down

0 comments on commit 5685bcd

Please sign in to comment.