diff --git a/src/vs/workbench/api/common/extHostDiagnostics.ts b/src/vs/workbench/api/common/extHostDiagnostics.ts index 499bbdbb28b..9097e5960ab 100644 --- a/src/vs/workbench/api/common/extHostDiagnostics.ts +++ b/src/vs/workbench/api/common/extHostDiagnostics.ts @@ -13,25 +13,20 @@ import * as converter from './extHostTypeConverters'; import { mergeSort } from 'vs/base/common/arrays'; import { Event, Emitter } from 'vs/base/common/event'; import { ILogService } from 'vs/platform/log/common/log'; +import { ResourceMap } from 'vs/base/common/map'; export class DiagnosticCollection implements vscode.DiagnosticCollection { - private readonly _name: string; - private readonly _owner: string; - private readonly _maxDiagnosticsPerFile: number; - private readonly _onDidChangeDiagnostics: Emitter<(vscode.Uri | string)[]>; - private readonly _proxy: MainThreadDiagnosticsShape | undefined; - private _isDisposed = false; - private _data = new Map(); + private _data = new ResourceMap(); - constructor(name: string, owner: string, maxDiagnosticsPerFile: number, proxy: MainThreadDiagnosticsShape | undefined, onDidChangeDiagnostics: Emitter<(vscode.Uri | string)[]>) { - this._name = name; - this._owner = owner; - this._maxDiagnosticsPerFile = maxDiagnosticsPerFile; - this._proxy = proxy; - this._onDidChangeDiagnostics = onDidChangeDiagnostics; - } + constructor( + private readonly _name: string, + private readonly _owner: string, + private readonly _maxDiagnosticsPerFile: number, + private readonly _proxy: MainThreadDiagnosticsShape | undefined, + private readonly _onDidChangeDiagnostics: Emitter<(vscode.Uri | string)[]> + ) { } dispose(): void { if (!this._isDisposed) { @@ -73,7 +68,7 @@ export class DiagnosticCollection implements vscode.DiagnosticCollection { } // update single row - this._data.set(first.toString(), diagnostics.slice()); + this._data.set(first, diagnostics.slice()); toSync = [first]; } else if (Array.isArray(first)) { @@ -87,8 +82,8 @@ export class DiagnosticCollection implements vscode.DiagnosticCollection { for (const tuple of first) { const [uri, diagnostics] = tuple; if (!lastUri || uri.toString() !== lastUri.toString()) { - if (lastUri && this._data.get(lastUri.toString())!.length === 0) { - this._data.delete(lastUri.toString()); + if (lastUri && this._data.get(lastUri)!.length === 0) { + this._data.delete(lastUri); } lastUri = uri; toSync.push(uri); @@ -120,7 +115,7 @@ export class DiagnosticCollection implements vscode.DiagnosticCollection { const entries: [URI, IMarkerData[]][] = []; for (let uri of toSync) { let marker: IMarkerData[] = []; - const diagnostics = this._data.get(uri.toString()); + const diagnostics = this._data.get(uri); if (diagnostics) { // no more than N diagnostics per file @@ -160,7 +155,7 @@ export class DiagnosticCollection implements vscode.DiagnosticCollection { delete(uri: vscode.Uri): void { this._checkDisposed(); this._onDidChangeDiagnostics.fire([uri]); - this._data.delete(uri.toString()); + this._data.delete(uri); if (this._proxy) { this._proxy.$changeMany(this._owner, [[uri, undefined]]); } @@ -177,15 +172,14 @@ export class DiagnosticCollection implements vscode.DiagnosticCollection { forEach(callback: (uri: URI, diagnostics: ReadonlyArray, collection: DiagnosticCollection) => any, thisArg?: any): void { this._checkDisposed(); - this._data.forEach((value, key) => { - const uri = URI.parse(key); + this._data.forEach((value, uri) => { callback.apply(thisArg, [uri, this.get(uri), this]); }); } get(uri: URI): ReadonlyArray { this._checkDisposed(); - const result = this._data.get(uri.toString()); + const result = this._data.get(uri); if (Array.isArray(result)) { return >Object.freeze(result.slice(0)); } @@ -194,7 +188,7 @@ export class DiagnosticCollection implements vscode.DiagnosticCollection { has(uri: URI): boolean { this._checkDisposed(); - return Array.isArray(this._data.get(uri.toString())); + return Array.isArray(this._data.get(uri)); } private _checkDisposed() {