mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-02 22:41:31 +01:00
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:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user