Skip to content

Commit 6fa9c69

Browse files
committed
Renames & tweaks the new Map/Set classes
Updates the CHANGELOG
1 parent 22f51ab commit 6fa9c69

File tree

6 files changed

+144
-170
lines changed

6 files changed

+144
-170
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1919
### Fixed
2020

2121
- Fixes [#3592](https://github.com/gitkraken/vscode-gitlens/issues/3592) - Connecting to an integration via Remotes view (but likely others) doesn't work
22+
- Fixes [#3571](https://github.com/gitkraken/vscode-gitlens/issues/3571) - Gitlens fails to register buttons on top-right corner — thanks to [PR #3605](https://github.com/gitkraken/vscode-gitlens/pull/3605) by Jean Pierre ([@jeanp413](https://github.com/jeanp413))
2223
- Fixes an issue where virtual repositories for GitHub PRs from forks wouldn't load properly
2324
- Fixes an issue where deleting a worktree would not always remove the worktree from the view
2425

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ A big thanks to the people that have contributed to this project 🙏❤️:
449449
- may ([@m4rch3n1ng](https://github.com/m4rch3n1ng)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=m4rch3n1ng)
450450
- bm-w ([@bm-w](https://github.com/bm-w)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=bm-w)
451451
- Tyler Johnson ([@TJohnsonSE](https://github.com/TJohnsonSE)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=TJohnsonSE)
452+
- Jean Pierre ([@jeanp413](https://github.com/jeanp413)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=jeanp413)
452453

453454
Also special thanks to the people that have provided support, testing, brainstorming, etc:
454455

src/annotations/fileAnnotationController.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { registerCommand } from '../system/vscode/command';
3333
import { configuration } from '../system/vscode/configuration';
3434
import { setContext } from '../system/vscode/context';
3535
import type { KeyboardScope } from '../system/vscode/keyboard';
36-
import { ResourceSet } from '../system/vscode/map';
36+
import { UriSet } from '../system/vscode/uriMap';
3737
import { isTrackableTextEditor } from '../system/vscode/utils';
3838
import type {
3939
DocumentBlameStateChangeEvent,
@@ -328,8 +328,8 @@ export class FileAnnotationController implements Disposable {
328328
debouncedRestore(editor);
329329
}
330330

331-
private readonly _annotatedUris = new ResourceSet();
332-
private readonly _computingUris = new ResourceSet();
331+
private readonly _annotatedUris = new UriSet();
332+
private readonly _computingUris = new UriSet();
333333

334334
async onProviderEditorStatusChanged(editor: TextEditor | undefined, status: AnnotationStatus | undefined) {
335335
if (editor == null) return;

src/system/vscode/map.ts

Lines changed: 0 additions & 164 deletions
This file was deleted.

src/system/vscode/uriMap.ts

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
import type { Uri } from 'vscode';
2+
3+
type UriMapEntry<T> = {
4+
readonly uri: Uri;
5+
readonly value: T;
6+
};
7+
8+
export class UriMap<T> implements Map<Uri, T> {
9+
private static readonly defaultToKey = (resource: Uri) => resource.toString();
10+
11+
readonly [Symbol.toStringTag] = 'UriMap';
12+
private readonly _map: Map<string, UriMapEntry<T>>;
13+
14+
constructor(entries?: readonly (readonly [Uri, T])[]) {
15+
this._map = new Map();
16+
if (entries?.length) {
17+
for (const [uri, value] of entries) {
18+
this.set(uri, value);
19+
}
20+
}
21+
}
22+
23+
set(uri: Uri, value: T): this {
24+
this._map.set(UriMap.defaultToKey(uri), { uri: uri, value: value });
25+
return this;
26+
}
27+
28+
get(uri: Uri): T | undefined {
29+
return this._map.get(UriMap.defaultToKey(uri))?.value;
30+
}
31+
32+
has(uri: Uri): boolean {
33+
return this._map.has(UriMap.defaultToKey(uri));
34+
}
35+
36+
get size(): number {
37+
return this._map.size;
38+
}
39+
40+
clear(): void {
41+
this._map.clear();
42+
}
43+
44+
delete(uri: Uri): boolean {
45+
return this._map.delete(UriMap.defaultToKey(uri));
46+
}
47+
48+
forEach(callbackfn: (value: T, key: Uri, map: Map<Uri, T>) => void, thisArg?: any): void {
49+
if (typeof thisArg !== 'undefined') {
50+
callbackfn = callbackfn.bind(thisArg);
51+
}
52+
for (const [_, entry] of this._map) {
53+
callbackfn(entry.value, entry.uri, this);
54+
}
55+
}
56+
57+
*values(): MapIterator<T> {
58+
for (const entry of this._map.values()) {
59+
yield entry.value;
60+
}
61+
}
62+
63+
*keys(): MapIterator<Uri> {
64+
for (const entry of this._map.values()) {
65+
yield entry.uri;
66+
}
67+
}
68+
69+
*entries(): MapIterator<[Uri, T]> {
70+
for (const entry of this._map.values()) {
71+
yield [entry.uri, entry.value];
72+
}
73+
}
74+
75+
*[Symbol.iterator](): MapIterator<[Uri, T]> {
76+
for (const [, entry] of this._map) {
77+
yield [entry.uri, entry.value];
78+
}
79+
}
80+
}
81+
82+
export class UriSet implements Set<Uri> {
83+
readonly [Symbol.toStringTag]: string = 'UriSet';
84+
85+
private readonly _map: UriMap<Uri>;
86+
87+
constructor(entries?: readonly Uri[]) {
88+
this._map = new UriMap();
89+
if (entries?.length) {
90+
for (const uri of entries) {
91+
this.add(uri);
92+
}
93+
}
94+
}
95+
96+
get size(): number {
97+
return this._map.size;
98+
}
99+
100+
add(uri: Uri): this {
101+
this._map.set(uri, uri);
102+
return this;
103+
}
104+
105+
clear(): void {
106+
this._map.clear();
107+
}
108+
109+
delete(uri: Uri): boolean {
110+
return this._map.delete(uri);
111+
}
112+
113+
forEach(callbackfn: (value: Uri, value2: Uri, set: Set<Uri>) => void, thisArg?: any): void {
114+
this._map.forEach((_value, key) => callbackfn.call(thisArg, key, key, this));
115+
}
116+
117+
has(uri: Uri): boolean {
118+
return this._map.has(uri);
119+
}
120+
121+
entries(): SetIterator<[Uri, Uri]> {
122+
return this._map.entries();
123+
}
124+
125+
keys(): SetIterator<Uri> {
126+
return this._map.keys();
127+
}
128+
129+
values(): SetIterator<Uri> {
130+
return this._map.keys();
131+
}
132+
133+
[Symbol.iterator](): SetIterator<Uri> {
134+
return this.keys();
135+
}
136+
}

src/trackers/documentTracker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import type { Deferrable } from '../system/function';
2222
import { debounce } from '../system/function';
2323
import { configuration } from '../system/vscode/configuration';
2424
import { setContext } from '../system/vscode/context';
25-
import { ResourceSet } from '../system/vscode/map';
25+
import { UriSet } from '../system/vscode/uriMap';
2626
import { findTextDocument, isVisibleDocument } from '../system/vscode/utils';
2727
import type { TrackedGitDocument } from './trackedDocument';
2828
import { createTrackedGitDocument } from './trackedDocument';
@@ -415,8 +415,8 @@ export class GitDocumentTracker implements Disposable {
415415
(tracked ?? (await docPromise))?.dispose();
416416
}
417417

418-
private readonly _openUrisBlameable = new ResourceSet();
419-
private readonly _openUrisTracked = new ResourceSet();
418+
private readonly _openUrisBlameable = new UriSet();
419+
private readonly _openUrisTracked = new UriSet();
420420
private _updateContextDebounced: Deferrable<() => void> | undefined;
421421

422422
updateContext(uri: Uri, blameable: boolean, tracked: boolean) {

0 commit comments

Comments
 (0)