提交 7ab45337 编写于 作者: M Matt Bierner

Using resource map for storing diagnostic

上级 29198d7e
......@@ -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);
}
......@@ -4,27 +4,24 @@
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import { ResourceMap } from './resourceMap';
export class DiagnosticSet {
private _map: ObjectMap<vscode.Diagnostic[]> = Object.create(null);
private _map = new ResourceMap<vscode.Diagnostic[]>();
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<vscode.Diagnostic[]>();
}
}
......@@ -40,7 +37,7 @@ export class DiagnosticsManager {
private readonly _diagnostics = new Map<DiagnosticKind, DiagnosticSet>();
private readonly _currentDiagnostics: vscode.DiagnosticCollection;
private readonly _pendingUpdates: { [key: string]: any } = Object.create(null);
private _pendingUpdates = new ResourceMap<any>();
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<any>();
}
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) {
......
......@@ -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<T> {
private readonly _map = new Map<string, T>();
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<T> {
}
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<T> {
return fs.existsSync(temp.toUpperCase());
}
}
export function isWindowsPath(path: string): boolean {
return /^[a-zA-Z]:\\/.test(path);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册