Skip to content

Commit a6e2bcd

Browse files
committed
Fixes File/Line history loading on intial show
1 parent b410b34 commit a6e2bcd

File tree

8 files changed

+186
-176
lines changed

8 files changed

+186
-176
lines changed

src/views/nodes/abstract/cacheableChildrenViewNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export abstract class CacheableChildrenViewNode<
2727
}
2828

2929
@debug()
30-
override refresh(reset: boolean = false): void {
30+
override refresh(reset: boolean = false): void | { cancel: boolean } | Promise<void | { cancel: boolean }> {
3131
if (reset) {
3232
this.children = undefined;
3333
}

src/views/nodes/abstract/repositoryFolderNode.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,8 @@ export abstract class RepositoryFolderNode<
172172
@gate()
173173
@debug()
174174
override async refresh(reset: boolean = false): Promise<void> {
175-
super.refresh(reset);
175+
await super.refresh(reset);
176176
await this.child?.triggerChange(reset, false, this);
177-
178177
await this.ensureSubscription();
179178
}
180179

src/views/nodes/abstract/subscribeableViewNode.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ export abstract class SubscribeableViewNode<
3434
}
3535

3636
const getTreeItem = this.getTreeItem;
37-
this.getTreeItem = function (this: SubscribeableViewNode<Type, TView>) {
37+
this.getTreeItem = async function (this: SubscribeableViewNode<Type, TView>) {
3838
this.loaded = true;
39-
void this.ensureSubscription();
39+
await this.ensureSubscription();
4040
return getTreeItem.apply(this);
4141
};
4242

4343
const getChildren = this.getChildren;
44-
this.getChildren = function (this: SubscribeableViewNode<Type, TView>) {
44+
this.getChildren = async function (this: SubscribeableViewNode<Type, TView>) {
4545
this.loaded = true;
46-
void this.ensureSubscription();
46+
await this.ensureSubscription();
4747
return getChildren.apply(this);
4848
};
4949

src/views/nodes/abstract/viewNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ export abstract class ViewNode<
307307
return undefined;
308308
}
309309

310-
refresh?(reset?: boolean): boolean | void | Promise<void> | Promise<boolean>;
310+
refresh?(reset?: boolean): void | { cancel: boolean } | Promise<void | { cancel: boolean }>;
311311

312312
@gate()
313313
@debug()

src/views/nodes/fileHistoryTrackerNode.ts

Lines changed: 89 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ export class FileHistoryTrackerNode extends SubscribeableViewNode<'file-history-
4747
this._child = value;
4848
}
4949

50+
protected override etag(): number {
51+
return 0;
52+
}
53+
54+
get followingEditor(): boolean {
55+
return this.canSubscribe;
56+
}
57+
58+
get hasUri(): boolean {
59+
return this._uri !== unknownGitUri && this._uri.repoPath != null;
60+
}
61+
5062
async getChildren(): Promise<ViewNode[]> {
5163
if (this.child == null) {
5264
this.view.groupedLabel ??= this.view.name.toLocaleLowerCase();
@@ -96,12 +108,50 @@ export class FileHistoryTrackerNode extends SubscribeableViewNode<'file-history-
96108
return item;
97109
}
98110

99-
get followingEditor(): boolean {
100-
return this.canSubscribe;
111+
@gate()
112+
@debug({ exit: true })
113+
override async refresh(reset: boolean = false): Promise<{ cancel: boolean }> {
114+
const scope = getLogScope();
115+
116+
if (!this.canSubscribe) return { cancel: false };
117+
118+
if (reset) {
119+
if (this._uri != null && this._uri !== unknownGitUri) {
120+
await this.view.container.documentTracker.resetCache(this._uri, 'log');
121+
}
122+
123+
this.reset();
124+
}
125+
126+
const updated = await this.updateUri();
127+
setLogScopeExit(scope, `, uri=${Logger.toLoggable(this._uri)}`);
128+
return { cancel: !updated };
101129
}
102130

103-
get hasUri(): boolean {
104-
return this._uri !== unknownGitUri && this._uri.repoPath != null;
131+
@debug()
132+
protected async subscribe(): Promise<Disposable> {
133+
await this.updateUri();
134+
135+
return Disposable.from(
136+
weakEvent(window.onDidChangeActiveTextEditor, debounce(this.onActiveEditorChanged, 250), this),
137+
);
138+
}
139+
140+
private _triggerChangeDebounced: Deferrable<() => Promise<void>> | undefined;
141+
@debug({ args: false })
142+
private onActiveEditorChanged(editor: TextEditor | undefined) {
143+
// If we are losing the active editor, give more time before assuming its really gone
144+
// For virtual repositories the active editor event takes a while to fire
145+
// Ultimately we need to be using the upcoming Tabs api to avoid this
146+
if (editor == null && isVirtualUri(this._uri)) {
147+
if (this._triggerChangeDebounced == null) {
148+
this._triggerChangeDebounced = debounce(() => this.triggerChange(), 1500);
149+
}
150+
151+
void this._triggerChangeDebounced();
152+
return;
153+
}
154+
void this.triggerChange();
105155
}
106156

107157
@gate()
@@ -131,40 +181,53 @@ export class FileHistoryTrackerNode extends SubscribeableViewNode<'file-history-
131181
await this.triggerChange();
132182
}
133183

134-
@gate()
135-
@debug({ exit: true })
136-
override async refresh(reset: boolean = false): Promise<boolean> {
137-
const scope = getLogScope();
184+
@log()
185+
setEditorFollowing(enabled: boolean): void {
186+
if (enabled) {
187+
this.setUri();
188+
// Don't need to call triggerChange here, since canSubscribe will do it
189+
}
138190

139-
if (!this.canSubscribe) return false;
191+
this.canSubscribe = enabled;
192+
if (!enabled) {
193+
void this.triggerChange();
194+
}
195+
}
140196

141-
if (reset) {
142-
if (this._uri != null && this._uri !== unknownGitUri) {
143-
await this.view.container.documentTracker.resetCache(this._uri, 'log');
144-
}
197+
@debug()
198+
setUri(uri?: GitUri): void {
199+
this._uri = uri ?? unknownGitUri;
200+
void setContext('gitlens:views:fileHistory:canPin', this.hasUri);
201+
}
145202

146-
this.reset();
147-
}
203+
@log()
204+
async showHistoryForUri(uri: GitUri): Promise<void> {
205+
this.setUri(uri);
206+
await this.triggerChange();
207+
}
148208

209+
private reset() {
210+
this.setUri();
211+
this.child = undefined;
212+
}
213+
214+
private async updateUri(): Promise<boolean> {
149215
const editor = window.activeTextEditor;
150216
if (editor == null || !this.view.container.git.isTrackable(editor.document.uri)) {
151217
if (
152218
!this.hasUri ||
153219
(this.view.container.git.isTrackable(this.uri) &&
154220
window.visibleTextEditors.some(e => e.document?.uri.path === this.uri.path))
155221
) {
156-
return true;
222+
return false;
157223
}
158224

159225
this.reset();
160-
161-
setLogScopeExit(scope, `, uri=${Logger.toLoggable(this._uri)}`);
162-
return false;
226+
return true;
163227
}
164228

165229
if (editor.document.uri.path === this.uri.path) {
166-
setLogScopeExit(scope, `, uri=${Logger.toLoggable(this._uri)}`);
167-
return true;
230+
return false;
168231
}
169232

170233
let gitUri = await GitUri.fromUri(editor.document.uri);
@@ -173,79 +236,22 @@ export class FileHistoryTrackerNode extends SubscribeableViewNode<'file-history-
173236
const uri = await ensureWorkingUri(this.view.container, gitUri);
174237

175238
if (this.hasUri && uriEquals(uri ?? gitUri, this.uri)) {
176-
return true;
239+
return false;
177240
}
178241

179242
if (uri != null) {
180243
gitUri = await GitUri.fromUri(uri);
181244
}
182245

183246
// If we have no repoPath then don't attempt to use the Uri
184-
if (gitUri.repoPath == null) {
247+
if (!gitUri.repoPath) {
185248
this.reset();
186-
} else {
187-
this.setUri(gitUri);
188-
this.child = undefined;
249+
return true;
189250
}
190251

191-
setLogScopeExit(scope, `, uri=${Logger.toLoggable(this._uri)}`);
192-
return false;
193-
}
194-
195-
private reset() {
196-
this.setUri();
252+
this.setUri(gitUri);
197253
this.child = undefined;
198-
}
199254

200-
@log()
201-
setEditorFollowing(enabled: boolean): void {
202-
if (enabled) {
203-
this.setUri();
204-
// Don't need to call triggerChange here, since canSubscribe will do it
205-
}
206-
207-
this.canSubscribe = enabled;
208-
if (!enabled) {
209-
void this.triggerChange();
210-
}
211-
}
212-
213-
@log()
214-
async showHistoryForUri(uri: GitUri): Promise<void> {
215-
this.setUri(uri);
216-
await this.triggerChange();
217-
}
218-
219-
@debug()
220-
protected subscribe(): Disposable {
221-
return Disposable.from(
222-
weakEvent(window.onDidChangeActiveTextEditor, debounce(this.onActiveEditorChanged, 250), this),
223-
);
224-
}
225-
226-
protected override etag(): number {
227-
return 0;
228-
}
229-
230-
private _triggerChangeDebounced: Deferrable<() => Promise<void>> | undefined;
231-
@debug({ args: false })
232-
private onActiveEditorChanged(editor: TextEditor | undefined) {
233-
// If we are losing the active editor, give more time before assuming its really gone
234-
// For virtual repositories the active editor event takes a while to fire
235-
// Ultimately we need to be using the upcoming Tabs api to avoid this
236-
if (editor == null && isVirtualUri(this._uri)) {
237-
if (this._triggerChangeDebounced == null) {
238-
this._triggerChangeDebounced = debounce(() => this.triggerChange(), 1500);
239-
}
240-
241-
void this._triggerChangeDebounced();
242-
return;
243-
}
244-
void this.triggerChange();
245-
}
246-
247-
setUri(uri?: GitUri): void {
248-
this._uri = uri ?? unknownGitUri;
249-
void setContext('gitlens:views:fileHistory:canPin', this.hasUri);
255+
return true;
250256
}
251257
}

0 commit comments

Comments
 (0)