diff --git a/extensions/typescript-language-features/src/features/bufferSyncSupport.ts b/extensions/typescript-language-features/src/features/bufferSyncSupport.ts index c2faca72c50..e85414f5734 100644 --- a/extensions/typescript-language-features/src/features/bufferSyncSupport.ts +++ b/extensions/typescript-language-features/src/features/bufferSyncSupport.ts @@ -364,7 +364,3 @@ export default class BufferSyncSupport { return this.client.normalizedPath(path); } } - -export function isWindowsPath(path: string): boolean { - return /^[a-zA-Z]:\\/.test(path); -} diff --git a/extensions/typescript-language-features/src/features/diagnostics.ts b/extensions/typescript-language-features/src/features/diagnostics.ts index e2884f74d36..0fe5d8b4e67 100644 --- a/extensions/typescript-language-features/src/features/diagnostics.ts +++ b/extensions/typescript-language-features/src/features/diagnostics.ts @@ -4,27 +4,24 @@ *--------------------------------------------------------------------------------------------*/ import * as vscode from 'vscode'; +import { ResourceMap } from './resourceMap'; export class DiagnosticSet { - private _map: ObjectMap = Object.create(null); + private _map = new ResourceMap(); public set( file: vscode.Uri, diagnostics: vscode.Diagnostic[] ) { - this._map[this.key(file)] = diagnostics; + this._map.set(file, diagnostics); } public get(file: vscode.Uri): vscode.Diagnostic[] { - return this._map[this.key(file)] || []; + return this._map.get(file) || []; } public clear(): void { - this._map = Object.create(null); - } - - private key(file: vscode.Uri): string { - return file.toString(true); + this._map = new ResourceMap(); } } @@ -40,7 +37,7 @@ export class DiagnosticsManager { private readonly _diagnostics = new Map(); private readonly _currentDiagnostics: vscode.DiagnosticCollection; - private readonly _pendingUpdates: { [key: string]: any } = Object.create(null); + private _pendingUpdates = new ResourceMap(); private _validate: boolean = true; private _enableSuggestions: boolean = true; @@ -59,10 +56,10 @@ export class DiagnosticsManager { public dispose() { this._currentDiagnostics.dispose(); - for (const key of Object.keys(this._pendingUpdates)) { - clearTimeout(this._pendingUpdates[key]); - delete this._pendingUpdates[key]; + for (const value of this._pendingUpdates.values) { + clearTimeout(value); } + this._pendingUpdates = new ResourceMap(); } public reInitialize(): void { @@ -131,16 +128,15 @@ export class DiagnosticsManager { } private scheduleDiagnosticsUpdate(file: vscode.Uri) { - const key = file.fsPath; - if (!this._pendingUpdates[key]) { - this._pendingUpdates[key] = setTimeout(() => this.updateCurrentDiagnostics(file), this.updateDelay); + if (!this._pendingUpdates.has(file)) { + this._pendingUpdates.set(file, setTimeout(() => this.updateCurrentDiagnostics(file), this.updateDelay)); } } private updateCurrentDiagnostics(file: vscode.Uri) { - if (this._pendingUpdates[file.fsPath]) { - clearTimeout(this._pendingUpdates[file.fsPath]); - delete this._pendingUpdates[file.fsPath]; + if (this._pendingUpdates.has(file)) { + clearTimeout(this._pendingUpdates.get(file)); + this._pendingUpdates.delete(file); } if (!this._validate) { diff --git a/extensions/typescript-language-features/src/features/resourceMap.ts b/extensions/typescript-language-features/src/features/resourceMap.ts index 22959a08b89..876db56dd0c 100644 --- a/extensions/typescript-language-features/src/features/resourceMap.ts +++ b/extensions/typescript-language-features/src/features/resourceMap.ts @@ -7,7 +7,6 @@ import * as fs from 'fs'; import { Uri } from 'vscode'; import { memoize } from '../utils/memoize'; import { getTempFile } from '../utils/temp'; -import { isWindowsPath } from './bufferSyncSupport'; /** * Maps of file resources @@ -19,7 +18,7 @@ export class ResourceMap { private readonly _map = new Map(); constructor( - private readonly _normalizePath: (resource: Uri) => string | null + private readonly _normalizePath?: (resource: Uri) => string | null ) { } public has(resource: Uri): boolean { @@ -55,7 +54,7 @@ export class ResourceMap { } private toKey(resource: Uri): string | null { - const key = this._normalizePath(resource); + const key = this._normalizePath ? this._normalizePath(resource) : resource.toString(true); if (!key) { return key; } @@ -82,3 +81,7 @@ export class ResourceMap { return fs.existsSync(temp.toUpperCase()); } } + +export function isWindowsPath(path: string): boolean { + return /^[a-zA-Z]:\\/.test(path); +}