Skip to content

Commit

Permalink
back to simple getDiagnostics-function, #30075
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Mar 14, 2018
1 parent f2bb105 commit f4c997a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 41 deletions.
11 changes: 4 additions & 7 deletions src/vs/vscode.proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ declare module 'vscode' {

//#region "read diagnostics"

export interface DiagnosticInformation {
has(uri: Uri): boolean;
get(uri: Uri): Diagnostic[] | undefined;
all(): [Uri, Diagnostic[]][];
}

export interface DiagnosticChangeEvent {
uris: Uri[];
}
Expand All @@ -26,7 +20,10 @@ declare module 'vscode' {
*/
export const onDidChangeDiagnostics: Event<DiagnosticChangeEvent>;

export const diagnostics: DiagnosticInformation;
/**
*
*/
export function getDiagnostics(resource?: Uri): Diagnostic[];
}

//#endregion
Expand Down
8 changes: 3 additions & 5 deletions src/vs/workbench/api/node/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,9 @@ export function createApiFactory(
checkProposedApiEnabled(extension);
return extHostDiagnostics.onDidChangeDiagnostics;
},
diagnostics: {
has: proposedApiFunction(extension, uri => extHostDiagnostics.hasDiagnostics(uri)),
get: proposedApiFunction(extension, uri => extHostDiagnostics.getDiagnostics(uri)),
all: proposedApiFunction(extension, () => extHostDiagnostics.getAllDiagnostics())
},
getDiagnostics: proposedApiFunction(extension, resource => {
return extHostDiagnostics.getDiagnostics(resource);
}),
getLanguages(): TPromise<string[]> {
return extHostLanguages.getLanguages();
},
Expand Down
38 changes: 9 additions & 29 deletions src/vs/workbench/api/node/extHostDiagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,38 +287,18 @@ export class ExtHostDiagnostics implements ExtHostDiagnosticsShape {
return result;
}

hasDiagnostics(resource: vscode.Uri): boolean {
for (const collection of this._collections) {
if (collection.has(resource)) {
return true;
}
}
return false;
}

getDiagnostics(resource: vscode.Uri): vscode.Diagnostic[] {
getDiagnostics(resource?: vscode.Uri): vscode.Diagnostic[] {
let res: vscode.Diagnostic[] = [];
for (const collection of this._collections) {
if (collection.has(resource)) {
res = res.concat(collection.get(resource));
}
}
return res;
}

getAllDiagnostics(): [vscode.Uri, vscode.Diagnostic[]][] {
let map = new Map<string, number>();
let res: [vscode.Uri, vscode.Diagnostic[]][] = [];
for (const collection of this._collections) {
collection.forEach((resource: vscode.Uri, diagnostics: vscode.Diagnostic[]) => {
let index = map.get(resource.toString());
if (typeof index === 'undefined') {
index = res.length;
res.push([resource, []]);
map.set(resource.toString(), index);
if (resource) {
// filtered
if (collection.has(resource)) {
res = res.concat(collection.get(resource));
}
res[index][1] = res[index][1].concat(diagnostics);
});
} else {
// all
collection.forEach((uri, diag) => res = res.concat(diag));
}
}
return res;
}
Expand Down

0 comments on commit f4c997a

Please sign in to comment.