提交 fdc48b3f 编写于 作者: J Johannes Rieken

refactor DiagnosticsCollection so that it holds data on ext host side

上级 63c85fb3
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
'use strict'; 'use strict';
import {Remotable, IThreadService} from 'vs/platform/thread/common/thread'; import {Remotable, IThreadService} from 'vs/platform/thread/common/thread';
import {IMarkerService, IResourceMarker, IMarkerData} from 'vs/platform/markers/common/markers'; import {IMarkerService, IMarkerData} from 'vs/platform/markers/common/markers';
import URI from 'vs/base/common/uri'; import URI from 'vs/base/common/uri';
import {TPromise} from 'vs/base/common/winjs.base'; import {TPromise} from 'vs/base/common/winjs.base';
import Severity from 'vs/base/common/severity'; import Severity from 'vs/base/common/severity';
...@@ -17,7 +17,9 @@ class DiagnosticCollection implements vscode.DiagnosticCollection { ...@@ -17,7 +17,9 @@ class DiagnosticCollection implements vscode.DiagnosticCollection {
private _name: string; private _name: string;
private _proxy: MainThreadDiagnostics; private _proxy: MainThreadDiagnostics;
private _isDisposed: boolean;
private _isDisposed = false;
private _data: {[uri:string]: vscode.Diagnostic[]} = Object.create(null);
constructor(name: string, proxy: MainThreadDiagnostics) { constructor(name: string, proxy: MainThreadDiagnostics) {
this._name = name; this._name = name;
...@@ -26,10 +28,10 @@ class DiagnosticCollection implements vscode.DiagnosticCollection { ...@@ -26,10 +28,10 @@ class DiagnosticCollection implements vscode.DiagnosticCollection {
dispose(): void { dispose(): void {
if (!this._isDisposed) { if (!this._isDisposed) {
this._proxy._changeAll(this.name, undefined).then(() => {
this._proxy = undefined;
this._isDisposed = true; this._isDisposed = true;
}); this._proxy.$clear(this.name);
this._proxy = undefined;
this._data = undefined;
} }
} }
...@@ -41,71 +43,64 @@ class DiagnosticCollection implements vscode.DiagnosticCollection { ...@@ -41,71 +43,64 @@ class DiagnosticCollection implements vscode.DiagnosticCollection {
set(uri: vscode.Uri, diagnostics: vscode.Diagnostic[]): void; set(uri: vscode.Uri, diagnostics: vscode.Diagnostic[]): void;
set(entries: [vscode.Uri, vscode.Diagnostic[]][]): void; set(entries: [vscode.Uri, vscode.Diagnostic[]][]): void;
set(first: vscode.Uri | [vscode.Uri, vscode.Diagnostic[]][], diagnostics?: vscode.Diagnostic[]) { set(first: vscode.Uri | [vscode.Uri, vscode.Diagnostic[]][], diagnostics?: vscode.Diagnostic[]) {
this._checkDisposed();
if (first instanceof URI) {
// change markers of resource only (max 500)
let data: IMarkerData[]; if (!first) {
if (diagnostics) { // this set-call is a clear-call
data = []; this.clear();
let len = diagnostics.length; return;
if (len > DiagnosticCollection._maxDiagnosticsPerFile) {
console.warn('diagnostics for %s will be capped to %d (actually is %d)', first.toString(), DiagnosticCollection._maxDiagnosticsPerFile, len);
len = DiagnosticCollection._maxDiagnosticsPerFile;
} }
for (let i = 0; i < len; i++) { // the actual implementation for #set
data.push(DiagnosticCollection._toMarkerData(diagnostics[i]));
}
}
// set or reset for this resource this._checkDisposed();
return this._proxy._changeOne(this.name, first, data); let toSync: vscode.Uri[];
} else { if (first instanceof URI) {
// change all marker of owner // update single row
let entries = <[vscode.Uri, vscode.Diagnostic[]][]>first; this._data[first.toString()] = diagnostics;
let data: IResourceMarker[]; toSync = [first];
if (entries) {
let total = 0; } else if (Array.isArray(first)) {
data = []; // update many rows
for (let entry of entries) { toSync = [];
for (let entry of first) {
let [uri, diagnostics] = entry; let [uri, diagnostics] = entry;
if (diagnostics) { this._data[uri.toString()] = diagnostics;
let len = diagnostics.length; toSync.push(uri);
if (len > DiagnosticCollection._maxDiagnosticsPerFile) {
console.warn('diagnostics for %s will be capped to %d (actually is %d)', uri.toString(), DiagnosticCollection._maxDiagnosticsPerFile, len);
len = DiagnosticCollection._maxDiagnosticsPerFile;
} }
for (let i = 0; i < len; i++) {
data.push({
resource: <URI>uri,
marker: DiagnosticCollection._toMarkerData(diagnostics[i])
});
} }
total += len; // compute change and send to main side
if (total > 10 * DiagnosticCollection._maxDiagnosticsPerFile) { const entries: [URI, IMarkerData[]][] = [];
console.warn('too many diagnostics will cap to %d', 10 * DiagnosticCollection._maxDiagnosticsPerFile); for (let uri of toSync) {
break; let marker: IMarkerData[];
} let diagnostics = this._data[uri.toString()];
} if (diagnostics) {
// no more than 250 diagnostics per file
if (diagnostics.length > DiagnosticCollection._maxDiagnosticsPerFile) {
console.warn('diagnostics for %s will be capped to %d (actually is %d)', uri, DiagnosticCollection._maxDiagnosticsPerFile, diagnostics.length);
diagnostics = diagnostics.slice(0, DiagnosticCollection._maxDiagnosticsPerFile);
} }
marker = diagnostics.map(DiagnosticCollection._toMarkerData);
} }
// set or reset all entries.push([<URI> uri, marker]);
this._proxy._changeAll(this.name, data);
} }
this._proxy.$changeMany(this.name, entries);
} }
delete(uri: vscode.Uri): void { delete(uri: vscode.Uri): void {
return this.set(uri, undefined); this._checkDisposed();
delete this._data[uri.toString()];
this._proxy.$changeMany(this.name, [[<URI> uri, undefined]]);
} }
clear(): void { clear(): void {
return this.set(undefined); this._checkDisposed();
this._data = Object.create(null);
this._proxy.$clear(this.name);
} }
private _checkDisposed() { private _checkDisposed() {
...@@ -167,13 +162,16 @@ export class MainThreadDiagnostics { ...@@ -167,13 +162,16 @@ export class MainThreadDiagnostics {
this._markerService = markerService; this._markerService = markerService;
} }
_changeOne(owner: string, resource: URI, markers: IMarkerData[]): TPromise<any> { $changeMany(owner: string, entries: [URI, IMarkerData[]][]): TPromise<any> {
this._markerService.changeOne(owner, resource, markers); for (let entry of entries) {
let [uri, markers] = entry;
this._markerService.changeOne(owner, uri, markers);
}
return undefined; return undefined;
} }
_changeAll(owner: string, data: IResourceMarker[]): TPromise<any> { $clear(owner: string): TPromise<any> {
this._markerService.changeAll(owner, data); this._markerService.changeAll(owner, undefined);
return undefined; return undefined;
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册