Skip to content

Commit c50bec8

Browse files
committed
Adds reset support to view & node refresh
1 parent a5d5700 commit c50bec8

12 files changed

+66
-53
lines changed

src/views/compareView.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { CompareViewConfig, configuration, ViewFilesLayout, ViewsConfig } from '
44
import { CommandContext, setCommandContext, WorkspaceState } from '../constants';
55
import { Container } from '../container';
66
import { CompareNode, CompareResultsNode, NamedRef, ViewNode } from './nodes';
7-
import { RefreshReason, ViewBase } from './viewBase';
7+
import { ViewBase } from './viewBase';
88

99
export class CompareView extends ViewBase<CompareNode> {
1010
constructor() {
@@ -24,7 +24,7 @@ export class CompareView extends ViewBase<CompareNode> {
2424
protected registerCommands() {
2525
void Container.viewCommands;
2626
commands.registerCommand(this.getQualifiedCommand('clear'), () => this.clear(), this);
27-
commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(), this);
27+
commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this);
2828
commands.registerCommand(
2929
this.getQualifiedCommand('setFilesLayoutToAuto'),
3030
() => this.setFilesLayout(ViewFilesLayout.Auto),
@@ -66,7 +66,7 @@ export class CompareView extends ViewBase<CompareNode> {
6666
}
6767

6868
if (!configuration.initializing(e) && this._root !== undefined) {
69-
void this.refresh(RefreshReason.ConfigurationChanged);
69+
void this.refresh(true);
7070
}
7171
}
7272

src/views/fileHistoryView.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { CommandContext, setCommandContext } from '../constants';
55
import { Container } from '../container';
66
import { GitUri } from '../git/gitUri';
77
import { FileHistoryTrackerNode } from './nodes';
8-
import { RefreshReason, ViewBase } from './viewBase';
8+
import { ViewBase } from './viewBase';
99

1010
export class FileHistoryView extends ViewBase<FileHistoryTrackerNode> {
1111
constructor() {
@@ -22,7 +22,7 @@ export class FileHistoryView extends ViewBase<FileHistoryTrackerNode> {
2222

2323
protected registerCommands() {
2424
void Container.viewCommands;
25-
commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(), this);
25+
commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this);
2626
commands.registerCommand(this.getQualifiedCommand('changeBase'), () => this.changeBase(), this);
2727
commands.registerCommand(
2828
this.getQualifiedCommand('setEditorFollowingOn'),
@@ -65,7 +65,7 @@ export class FileHistoryView extends ViewBase<FileHistoryTrackerNode> {
6565
}
6666

6767
if (!configuration.initializing(e) && this._root !== undefined) {
68-
void this.refresh(RefreshReason.ConfigurationChanged);
68+
void this.refresh(true);
6969
}
7070
}
7171

src/views/lineHistoryView.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { configuration, LineHistoryViewConfig, ViewsConfig } from '../configurat
44
import { CommandContext, setCommandContext } from '../constants';
55
import { Container } from '../container';
66
import { LineHistoryTrackerNode } from './nodes';
7-
import { RefreshReason, ViewBase } from './viewBase';
7+
import { ViewBase } from './viewBase';
88

99
export class LineHistoryView extends ViewBase<LineHistoryTrackerNode> {
1010
constructor() {
@@ -21,7 +21,7 @@ export class LineHistoryView extends ViewBase<LineHistoryTrackerNode> {
2121

2222
protected registerCommands() {
2323
void Container.viewCommands;
24-
commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(), this);
24+
commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this);
2525
commands.registerCommand(this.getQualifiedCommand('changeBase'), () => this.changeBase(), this);
2626
commands.registerCommand(
2727
this.getQualifiedCommand('setEditorFollowingOn'),
@@ -64,7 +64,7 @@ export class LineHistoryView extends ViewBase<LineHistoryTrackerNode> {
6464
}
6565

6666
if (!configuration.initializing(e) && this._root !== undefined) {
67-
void this.refresh(RefreshReason.ConfigurationChanged);
67+
void this.refresh(true);
6868
}
6969
}
7070

src/views/nodes/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export abstract class PagerNode extends ViewNode {
166166
return {
167167
title: 'Refresh',
168168
command: 'gitlens.views.refreshNode',
169-
arguments: [this.parent, this._args]
169+
arguments: [this.parent, false, this._args]
170170
} as Command;
171171
}
172172
}

src/views/nodes/fileHistoryTrackerNode.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ export class FileHistoryTrackerNode extends SubscribeableViewNode<FileHistoryVie
2727
}
2828

2929
@debug()
30-
resetChild() {
31-
if (this._child !== undefined) {
32-
this._child.dispose();
33-
this._child = undefined;
34-
}
30+
private resetChild() {
31+
if (this._child === undefined) return;
32+
33+
this._child.dispose();
34+
this._child = undefined;
3535
}
3636

3737
async getChildren(): Promise<ViewNode[]> {
@@ -84,7 +84,12 @@ export class FileHistoryTrackerNode extends SubscribeableViewNode<FileHistoryVie
8484

8585
@gate()
8686
@debug()
87-
async refresh() {
87+
async refresh(reset: boolean = false) {
88+
if (reset) {
89+
this._uri = unknownGitUri;
90+
this.resetChild();
91+
}
92+
8893
const editor = window.activeTextEditor;
8994
if (editor == null || !Container.git.isTrackable(editor.document.uri)) {
9095
if (

src/views/nodes/lineHistoryTrackerNode.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ export class LineHistoryTrackerNode extends SubscribeableViewNode<LineHistoryVie
2828
}
2929

3030
@debug()
31-
resetChild() {
32-
if (this._child !== undefined) {
33-
this._child.dispose();
34-
this._child = undefined;
35-
}
31+
private resetChild() {
32+
if (this._child === undefined) return;
33+
34+
this._child.dispose();
35+
this._child = undefined;
3636
}
3737

3838
async getChildren(): Promise<ViewNode[]> {
@@ -84,7 +84,13 @@ export class LineHistoryTrackerNode extends SubscribeableViewNode<LineHistoryVie
8484

8585
@gate()
8686
@debug()
87-
async refresh() {
87+
async refresh(reset: boolean = false) {
88+
if (reset) {
89+
this._uri = unknownGitUri;
90+
this._selection = undefined;
91+
this.resetChild();
92+
}
93+
8894
const editor = window.activeTextEditor;
8995
if (editor == null || !Container.git.isTrackable(editor.document.uri)) {
9096
if (

src/views/nodes/repositoriesNode.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { GitUri } from '../../git/gitService';
55
import { Logger } from '../../logger';
66
import { debug, Functions, gate } from '../../system';
77
import { RepositoriesView } from '../repositoriesView';
8-
import { RefreshReason } from '../viewBase';
98
import { MessageNode } from './common';
109
import { RepositoryNode } from './repositoryNode';
1110
import { ResourceType, SubscribeableViewNode, unknownGitUri, ViewNode } from './viewNode';
@@ -20,14 +19,19 @@ export class RepositoriesNode extends SubscribeableViewNode<RepositoriesView> {
2019
dispose() {
2120
super.dispose();
2221

23-
if (this._children !== undefined) {
24-
for (const child of this._children) {
25-
if (child instanceof RepositoryNode) {
26-
child.dispose();
27-
}
22+
this.resetChildren();
23+
}
24+
25+
@debug()
26+
private resetChildren() {
27+
if (this._children === undefined) return;
28+
29+
for (const child of this._children) {
30+
if (child instanceof RepositoryNode) {
31+
child.dispose();
2832
}
29-
this._children = undefined;
3033
}
34+
this._children = undefined;
3135
}
3236

3337
async getChildren(): Promise<ViewNode[]> {
@@ -59,9 +63,17 @@ export class RepositoriesNode extends SubscribeableViewNode<RepositoriesView> {
5963

6064
@gate()
6165
@debug()
62-
async refresh(reason?: RefreshReason) {
66+
async refresh(reset: boolean = false) {
6367
if (this._children === undefined) return;
6468

69+
if (reset) {
70+
this.resetChildren();
71+
await this.unsubscribe();
72+
void this.ensureSubscription();
73+
74+
return;
75+
}
76+
6577
const repositories = await Container.git.getOrderedRepositories();
6678
if (repositories.length === 0 && (this._children === undefined || this._children.length === 0)) return;
6779

@@ -93,11 +105,6 @@ export class RepositoriesNode extends SubscribeableViewNode<RepositoriesView> {
93105

94106
this._children = children;
95107

96-
// Reset our subscription if the configuration changed
97-
if (reason === RefreshReason.ConfigurationChanged) {
98-
await this.unsubscribe();
99-
}
100-
101108
void this.ensureSubscription();
102109
}
103110

src/views/nodes/viewNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Command, Disposable, Event, TreeItem, TreeItemCollapsibleState, TreeVie
33
import { GitUri } from '../../git/gitService';
44
import { Logger } from '../../logger';
55
import { debug, gate, logName } from '../../system';
6-
import { RefreshReason, TreeViewNodeStateChangeEvent, View } from '../viewBase';
6+
import { TreeViewNodeStateChangeEvent, View } from '../viewBase';
77

88
export enum ResourceType {
99
ActiveFileHistory = 'gitlens:history:active:file',
@@ -97,7 +97,7 @@ export abstract class ViewNode<TView extends View = View> {
9797

9898
@gate()
9999
@debug()
100-
refresh(reason?: RefreshReason): void | boolean | Promise<void> | Promise<boolean> {}
100+
refresh(reset: boolean = false): void | boolean | Promise<void> | Promise<boolean> {}
101101

102102
@gate()
103103
@debug()

src/views/repositoriesView.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { configuration, RepositoriesViewConfig, ViewFilesLayout, ViewsConfig } f
44
import { CommandContext, setCommandContext, WorkspaceState } from '../constants';
55
import { Container } from '../container';
66
import { RepositoriesNode } from './nodes';
7-
import { RefreshReason, ViewBase } from './viewBase';
7+
import { ViewBase } from './viewBase';
88

99
export class RepositoriesView extends ViewBase<RepositoriesNode> {
1010
constructor() {
@@ -27,7 +27,7 @@ export class RepositoriesView extends ViewBase<RepositoriesNode> {
2727
protected registerCommands() {
2828
void Container.viewCommands;
2929

30-
commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(), this);
30+
commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this);
3131
commands.registerCommand(
3232
this.getQualifiedCommand('setFilesLayoutToAuto'),
3333
() => this.setFilesLayout(ViewFilesLayout.Auto),
@@ -74,7 +74,7 @@ export class RepositoriesView extends ViewBase<RepositoriesNode> {
7474
}
7575

7676
if (!configuration.initializing(e) && this._root !== undefined) {
77-
void this.refresh(RefreshReason.ConfigurationChanged);
77+
void this.refresh(true);
7878
}
7979
}
8080

src/views/searchView.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Container } from '../container';
66
import { GitLog, GitRepoSearchBy } from '../git/gitService';
77
import { Functions, Strings } from '../system';
88
import { SearchNode, SearchResultsCommitsNode, ViewNode } from './nodes';
9-
import { RefreshReason, ViewBase } from './viewBase';
9+
import { ViewBase } from './viewBase';
1010

1111
interface SearchQueryResult {
1212
label: string;
@@ -31,7 +31,7 @@ export class SearchView extends ViewBase<SearchNode> {
3131
protected registerCommands() {
3232
void Container.viewCommands;
3333
commands.registerCommand(this.getQualifiedCommand('clear'), () => this.clear(), this);
34-
commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(), this);
34+
commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this);
3535
commands.registerCommand(
3636
this.getQualifiedCommand('setFilesLayoutToAuto'),
3737
() => this.setFilesLayout(ViewFilesLayout.Auto),
@@ -69,7 +69,7 @@ export class SearchView extends ViewBase<SearchNode> {
6969
}
7070

7171
if (!configuration.initializing(e) && this._root !== undefined) {
72-
void this.refresh(RefreshReason.ConfigurationChanged);
72+
void this.refresh(true);
7373
}
7474
}
7575

0 commit comments

Comments
 (0)