提交 20adb31b 编写于 作者: J Johannes Rieken

only listen after getting data once, #40210

上级 a0b608d9
......@@ -230,30 +230,19 @@ class FileDecorationChangeEvent implements IResourceDecorationChangeEvent {
class DecorationProviderWrapper {
readonly data = TernarySearchTree.forPaths<Thenable<void> | IDecorationData>();
private readonly _dispoable: IDisposable;
private _listener: IDisposable;
constructor(
private readonly _provider: IDecorationsProvider,
private readonly _uriEmitter: Emitter<URI | URI[]>,
private readonly _flushEmitter: Emitter<IResourceDecorationChangeEvent>
) {
this._dispoable = this._provider.onDidChange(uris => {
if (!uris) {
// flush event -> drop all data, can affect everything
this.data.clear();
this._flushEmitter.fire({ affectsResource() { return true; } });
} else {
// selective changes -> drop for resource, fetch again, send event
for (const uri of uris) {
this._fetchData(uri);
}
}
});
//
}
dispose(): void {
this._dispoable.dispose();
this._listener.dispose();
this.data.clear();
}
......@@ -294,7 +283,11 @@ class DecorationProviderWrapper {
}
private _fetchData(uri: URI): IDecorationData {
// listen to provider changes only after
// we have asked it for data...
this._ensureIsListening();
// retrieve data, do the dance
const dataOrThenable = this._provider.provideDecorations(uri);
if (!isThenable(dataOrThenable)) {
// sync -> we have a result now
......@@ -320,6 +313,24 @@ class DecorationProviderWrapper {
}
return deco;
}
private _ensureIsListening(): void {
if (!this._listener) {
this._listener = this._provider.onDidChange(uris => {
if (!uris) {
// flush event -> drop all data, can affect everything
this.data.clear();
this._flushEmitter.fire({ affectsResource() { return true; } });
} else {
// selective changes -> drop for resource, fetch again, send event
for (const uri of uris) {
this._fetchData(uri);
}
}
});
}
}
}
export class FileDecorationsService implements IDecorationsService {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册