mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-22 11:19:32 +00:00
Use readonly arrays for the vscode.DiagnosticCollection api
## Problem The diagnostic collection object is set up so that it does not mutate the arrays of diagnostics you pass to it. It also does not expect or allow mutation of diagnostics that it returns. However it it currently typed using normal arrays. This means that if an extension (such as JS/TS) wishes to use readonly diagnostics intnernally, it cannot do so without casting. ## Proposed Fix Use `ReadonlyArray` in diagnostic collection. This should be a safe change for the `set` type methods. The changes to `get` and `forEach` have the risk of breaking the typing of some extensions, but `get` already returned a frozen array of diagnostic so trying to mutate the array itself would have resulted in runtime error.
This commit is contained in:
@@ -208,7 +208,7 @@ export class DiagnosticsManager extends Disposable {
|
||||
|
||||
public configFileDiagnosticsReceived(
|
||||
file: vscode.Uri,
|
||||
diagnostics: vscode.Diagnostic[]
|
||||
diagnostics: ReadonlyArray<vscode.Diagnostic>
|
||||
): void {
|
||||
this._currentDiagnostics.set(file, diagnostics);
|
||||
}
|
||||
@@ -218,7 +218,7 @@ export class DiagnosticsManager extends Disposable {
|
||||
this._diagnostics.delete(resource);
|
||||
}
|
||||
|
||||
public getDiagnostics(file: vscode.Uri): vscode.Diagnostic[] {
|
||||
public getDiagnostics(file: vscode.Uri): ReadonlyArray<vscode.Diagnostic> {
|
||||
return this._currentDiagnostics.get(file) || [];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user