Skip to content

Commit

Permalink
use uri-tst for decorations service, #93368
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Apr 6, 2020
1 parent 80acfa9 commit c6c6969
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/vs/workbench/services/decorations/browser/decorationsService.ts
Original file line number Diff line number Diff line change
@@ -169,10 +169,10 @@ class DecorationStyles {

class FileDecorationChangeEvent implements IResourceDecorationChangeEvent {

private readonly _data = TernarySearchTree.forPaths<boolean>();
private readonly _data = TernarySearchTree.forUris<boolean>();

affectsResource(uri: URI): boolean {
return this._data.get(uri.toString()) || this._data.findSuperstr(uri.toString()) !== undefined;
return this._data.get(uri) || this._data.findSuperstr(uri) !== undefined;
}

static debouncer(last: FileDecorationChangeEvent | undefined, current: URI | URI[]) {
@@ -182,11 +182,11 @@ class FileDecorationChangeEvent implements IResourceDecorationChangeEvent {
if (Array.isArray(current)) {
// many
for (const uri of current) {
last._data.set(uri.toString(), true);
last._data.set(uri, true);
}
} else {
// one
last._data.set(current.toString(), true);
last._data.set(current, true);
}

return last;
@@ -202,7 +202,7 @@ class DecorationDataRequest {

class DecorationProviderWrapper {

readonly data = TernarySearchTree.forPaths<DecorationDataRequest | IDecorationData | null>();
readonly data = TernarySearchTree.forUris<DecorationDataRequest | IDecorationData | null>();
private readonly _dispoable: IDisposable;

constructor(
@@ -234,12 +234,12 @@ class DecorationProviderWrapper {
}

knowsAbout(uri: URI): boolean {
return Boolean(this.data.get(uri.toString())) || Boolean(this.data.findSuperstr(uri.toString()));
return Boolean(this.data.get(uri)) || Boolean(this.data.findSuperstr(uri));
}

getOrRetrieve(uri: URI, includeChildren: boolean, callback: (data: IDecorationData, isChild: boolean) => void): void {
const key = uri.toString();
let item = this.data.get(key);

let item = this.data.get(uri);

if (item === undefined) {
// unknown -> trigger request
@@ -253,7 +253,7 @@ class DecorationProviderWrapper {

if (includeChildren) {
// (resolved) children
const iter = this.data.findSuperstr(key);
const iter = this.data.findSuperstr(uri);
if (iter) {
for (let item = iter.next(); !item.done; item = iter.next()) {
if (item.value && !(item.value instanceof DecorationDataRequest)) {
@@ -267,10 +267,10 @@ class DecorationProviderWrapper {
private _fetchData(uri: URI): IDecorationData | null {

// check for pending request and cancel it
const pendingRequest = this.data.get(uri.toString());
const pendingRequest = this.data.get(uri);
if (pendingRequest instanceof DecorationDataRequest) {
pendingRequest.source.cancel();
this.data.delete(uri.toString());
this.data.delete(uri);
}

const source = new CancellationTokenSource();
@@ -282,23 +282,23 @@ class DecorationProviderWrapper {
} else {
// async -> we have a result soon
const request = new DecorationDataRequest(source, Promise.resolve(dataOrThenable).then(data => {
if (this.data.get(uri.toString()) === request) {
if (this.data.get(uri) === request) {
this._keepItem(uri, data);
}
}).catch(err => {
if (!isPromiseCanceledError(err) && this.data.get(uri.toString()) === request) {
this.data.delete(uri.toString());
if (!isPromiseCanceledError(err) && this.data.get(uri) === request) {
this.data.delete(uri);
}
}));

this.data.set(uri.toString(), request);
this.data.set(uri, request);
return null;
}
}

private _keepItem(uri: URI, data: IDecorationData | undefined): IDecorationData | null {
const deco = data ? data : null;
const old = this.data.set(uri.toString(), deco);
const old = this.data.set(uri, deco);
if (deco || old) {
// only fire event when something changed
this._uriEmitter.fire(uri);

0 comments on commit c6c6969

Please sign in to comment.