Adopt ResourceMap in more places (#151475)

This changes switches to use the new `ResourceMap` type in more places in the markdown extension where we need to have a map/set with uris as the key
This commit is contained in:
Matt Bierner
2022-06-07 23:34:06 -07:00
committed by GitHub
parent 45818d7c31
commit 1327d1eb50
4 changed files with 49 additions and 52 deletions

View File

@@ -5,10 +5,20 @@
import * as vscode from 'vscode';
type ResourceToKey = (uri: vscode.Uri) => string;
const defaultResourceToKey = (resource: vscode.Uri): string => resource.toString();
export class ResourceMap<T> {
private readonly map = new Map<string, { readonly uri: vscode.Uri; readonly value: T }>();
private readonly toKey: ResourceToKey;
constructor(toKey: ResourceToKey = defaultResourceToKey) {
this.toKey = toKey;
}
public set(uri: vscode.Uri, value: T): this {
this.map.set(this.toKey(uri), { uri, value });
return this;
@@ -55,8 +65,4 @@ export class ResourceMap<T> {
public [Symbol.iterator](): IterableIterator<[vscode.Uri, T]> {
return this.entries();
}
private toKey(resource: vscode.Uri) {
return resource.toString();
}
}