Skip to content

Commit

Permalink
fix: diagnostics api iterable fix (#3566)
Browse files Browse the repository at this point in the history
  • Loading branch information
life2015 authored Apr 22, 2024
1 parent f1bef23 commit ab51474
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ export class DiagnosticCollection implements vscode.DiagnosticCollection {
});
}

*[Symbol.iterator](): IterableIterator<[uri: vscode.Uri, diagnostics: readonly vscode.Diagnostic[]]> {
this.ensureNotDisposed();
for (const uri of this.diagnostics.keys()) {
const uri2 = URI.parse(uri);
yield [uri2, this.get(uri2) || []];
}
}

get(uri: URI): vscode.Diagnostic[] | undefined {
this.ensureNotDisposed();
return this.getDiagnosticsByUri(uri);
Expand Down Expand Up @@ -185,7 +193,7 @@ export class DiagnosticCollection implements vscode.DiagnosticCollection {

private getDiagnosticsByUri(uri: URI): vscode.Diagnostic[] | undefined {
const diagnostics = this.diagnostics.get(uri.toString());
return diagnostics instanceof Array ? (Object.freeze(diagnostics) as vscode.Diagnostic[]) : undefined;
return diagnostics instanceof Array ? (Object.freeze(diagnostics) as vscode.Diagnostic[]) : [];
}

private fireDiagnosticChangeEvent(arg: string | string[] | URI | URI[]): void {
Expand Down
2 changes: 1 addition & 1 deletion packages/types/vscode/typings/vscode.language.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2714,7 +2714,7 @@ declare module 'vscode' {
* To get an instance of a `DiagnosticCollection` use
* [createDiagnosticCollection](#languages.createDiagnosticCollection).
*/
export interface DiagnosticCollection {
export interface DiagnosticCollection extends Iterable<[uri: Uri, diagnostics: readonly Diagnostic[]]>{

/**
* The name of this diagnostic collection, for instance `typescript`. Every diagnostic
Expand Down

0 comments on commit ab51474

Please sign in to comment.