mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
try a different variant of getDiagnostics... #30075
This commit is contained in:
parent
2775e756eb
commit
5685bcd524
7
src/vs/vscode.proposed.d.ts
vendored
7
src/vs/vscode.proposed.d.ts
vendored
|
@ -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
|
||||
|
|
|
@ -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[]> {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue