Browse Source

Fixes state getting lost w/ search/compare nodes

Removes ViewNode.instanceId
Better persists search/compare tree ids
main
Eric Amodio 5 years ago
parent
commit
578f103b09
25 changed files with 68 additions and 79 deletions
  1. +4
    -6
      src/views/nodes/branchNode.ts
  2. +1
    -1
      src/views/nodes/branchOrTagFolderNode.ts
  3. +1
    -1
      src/views/nodes/branchTrackingStatusNode.ts
  4. +1
    -1
      src/views/nodes/branchesNode.ts
  5. +1
    -1
      src/views/nodes/compareBranchNode.ts
  6. +1
    -1
      src/views/nodes/compareNode.ts
  7. +8
    -0
      src/views/nodes/compareResultsNode.ts
  8. +1
    -1
      src/views/nodes/contributorNode.ts
  9. +1
    -1
      src/views/nodes/contributorsNode.ts
  10. +1
    -1
      src/views/nodes/reflogNode.ts
  11. +3
    -3
      src/views/nodes/reflogRecordNode.ts
  12. +1
    -1
      src/views/nodes/remoteNode.ts
  13. +1
    -1
      src/views/nodes/remotesNode.ts
  14. +1
    -1
      src/views/nodes/repositoryNode.ts
  15. +2
    -2
      src/views/nodes/resultsCommitsNode.ts
  16. +2
    -5
      src/views/nodes/resultsFilesNode.ts
  17. +1
    -1
      src/views/nodes/searchNode.ts
  18. +10
    -1
      src/views/nodes/searchResultsCommitsNode.ts
  19. +1
    -1
      src/views/nodes/stashNode.ts
  20. +1
    -1
      src/views/nodes/stashesNode.ts
  21. +1
    -1
      src/views/nodes/statusFilesNode.ts
  22. +1
    -1
      src/views/nodes/tagNode.ts
  23. +1
    -1
      src/views/nodes/tagsNode.ts
  24. +9
    -44
      src/views/nodes/viewNode.ts
  25. +13
    -1
      src/views/viewBase.ts

+ 4
- 6
src/views/nodes/branchNode.ts View File

@ -30,11 +30,9 @@ export class BranchNode extends ViewRefNode implements Pageabl
}
get id(): string {
return `${this._instanceId}:gitlens:repository(${this.branch.repoPath})${this._root ? ':root:' : ''}:branch(${
this.branch.name
})${this.branch.current ? '+current:' : ''}${this.branch.remote ? '+remote' : ''}${
this.branch.starred ? '+starred:' : ''
}`;
return `gitlens:repository(${this.branch.repoPath})${this._root ? ':root' : ''}:branch(${this.branch.name})${
this.branch.current ? '+current' : ''
}${this.branch.remote ? '+remote' : ''}${this.branch.starred ? '+starred' : ''}`;
}
get current(): boolean {
@ -206,7 +204,7 @@ export class BranchNode extends ViewRefNode implements Pageabl
@gate()
@debug()
refresh() {
refresh(reset: boolean = false) {
this._children = undefined;
}
}

+ 1
- 1
src/views/nodes/branchOrTagFolderNode.ts View File

@ -23,7 +23,7 @@ export class BranchOrTagFolderNode extends ViewNode {
}
get id(): string {
return `${this._instanceId}:gitlens:repository(${this.repoPath})${
return `gitlens:repository(${this.repoPath})${
this._key === undefined ? '' : `:${this._key}`
}:${this.type}-folder(${this.relativePath})`;
}

+ 1
- 1
src/views/nodes/branchTrackingStatusNode.ts View File

@ -32,7 +32,7 @@ export class BranchTrackingStatusNode extends ViewNode implements
}
get id(): string {
return `${this._instanceId}:gitlens:repository(${this.status.repoPath}):${this._root ? 'root:' : ''}branch(${
return `gitlens:repository(${this.status.repoPath}):${this._root ? 'root:' : ''}branch(${
this.status.ref
}):status:upstream:(${this.status.upstream}):${this.direction}`;
}

+ 1
- 1
src/views/nodes/branchesNode.ts View File

@ -17,7 +17,7 @@ export class BranchesNode extends ViewNode {
}
get id(): string {
return `${this._instanceId}:gitlens:repository(${this.repo.path}):branches`;
return `gitlens:repository(${this.repo.path}):branches`;
}
async getChildren(): Promise<ViewNode[]> {

+ 1
- 1
src/views/nodes/compareBranchNode.ts View File

@ -22,7 +22,7 @@ export class CompareBranchNode extends ViewNode {
}
get id(): string {
return `${this._instanceId}:gitlens:repository(${this.branch.repoPath}):branch(${this.branch.name}):compareWith`;
return `gitlens:repository(${this.branch.repoPath}):branch(${this.branch.name}):compareWith`;
}
getChildren(): ViewNode[] {

+ 1
- 1
src/views/nodes/compareNode.ts View File

@ -119,7 +119,7 @@ export class CompareNode extends ViewNode {
const promises: Promise<any>[] = [
...Iterables.filterMap(this._children, c => {
const result = c.refresh();
const result = c.refresh === undefined ? false : c.refresh();
return Functions.isPromise<boolean | void>(result) ? result : undefined;
})
];

+ 8
- 0
src/views/nodes/compareResultsNode.ts View File

@ -9,8 +9,11 @@ import { CommitsQueryResults, ResultsCommitsNode } from './resultsCommitsNode';
import { ResultsFilesNode } from './resultsFilesNode';
import { ResourceType, SubscribeableViewNode, ViewNode } from './viewNode';
let instanceId = 0;
export class CompareResultsNode extends SubscribeableViewNode<CompareView> {
private _children: ViewNode[] | undefined;
private _instanceId: number;
constructor(
view: CompareView,
@ -20,6 +23,11 @@ export class CompareResultsNode extends SubscribeableViewNode {
private _pinned: boolean = false
) {
super(GitUri.fromRepoPath(repoPath), view);
this._instanceId = instanceId++;
}
get id(): string {
return `gitlens:repository(${this.repoPath}):compare(${this._ref1.ref}:${this._ref2.ref})|${this._instanceId}`;
}
get label() {

+ 1
- 1
src/views/nodes/contributorNode.ts View File

@ -19,7 +19,7 @@ export class ContributorNode extends ViewNode implements Pagea
}
get id(): string {
return `${this._instanceId}:gitlens:repository(${this.contributor.repoPath}):contributor(${this.contributor.name}|${this.contributor.email}}`;
return `gitlens:repository(${this.contributor.repoPath}):contributor(${this.contributor.name}|${this.contributor.email}}`;
}
async getChildren(): Promise<ViewNode[]> {

+ 1
- 1
src/views/nodes/contributorsNode.ts View File

@ -13,7 +13,7 @@ export class ContributorsNode extends ViewNode {
}
get id(): string {
return `${this._instanceId}:gitlens:repository(${this.repo.path}):contributors`;
return `gitlens:repository(${this.repo.path}):contributors`;
}
async getChildren(): Promise<ViewNode[]> {

+ 1
- 1
src/views/nodes/reflogNode.ts View File

@ -19,7 +19,7 @@ export class ReflogNode extends ViewNode implements PageableVi
}
get id(): string {
return `${this._instanceId}:gitlens:repository(${this.repo.path}):reflog`;
return `gitlens:repository(${this.repo.path}):reflog`;
}
async getChildren(): Promise<ViewNode[]> {

+ 3
- 3
src/views/nodes/reflogRecordNode.ts View File

@ -18,9 +18,9 @@ export class ReflogRecordNode extends ViewNode implements Pageabl
}
get id(): string {
return `${this._instanceId}:gitlens:repository(${this.uri.repoPath}):reflog-record(${this.record.sha}|${
this.record.selector
}|${this.record.command}|${this.record.commandArgs || ''}|${this.record.date.getTime()})`;
return `gitlens:repository(${this.uri.repoPath}):reflog-record(${this.record.sha}|${this.record.selector}|${
this.record.command
}|${this.record.commandArgs || ''}|${this.record.date.getTime()})`;
}
async getChildren(): Promise<ViewNode[]> {

+ 1
- 1
src/views/nodes/remoteNode.ts View File

@ -22,7 +22,7 @@ export class RemoteNode extends ViewNode {
}
get id(): string {
return `${this._instanceId}:gitlens:repository(${this.remote.repoPath}):remote(${this.remote.name}:${this.remote.id})`;
return `gitlens:repository(${this.remote.repoPath}):remote(${this.remote.name}:${this.remote.id})`;
}
async getChildren(): Promise<ViewNode[]> {

+ 1
- 1
src/views/nodes/remotesNode.ts View File

@ -14,7 +14,7 @@ export class RemotesNode extends ViewNode {
}
get id(): string {
return `${this._instanceId}:gitlens:repository(${this.repo.path}):remotes`;
return `gitlens:repository(${this.repo.path}):remotes`;
}
async getChildren(): Promise<ViewNode[]> {

+ 1
- 1
src/views/nodes/repositoryNode.ts View File

@ -40,7 +40,7 @@ export class RepositoryNode extends SubscribeableViewNode {
}
get id(): string {
return `${this._instanceId}:gitlens:repository(${this.repo.path})${this.repo.starred ? '+starred:' : ''}`;
return `gitlens:repository(${this.repo.path})${this.repo.starred ? '+starred' : ''}`;
}
async getChildren(): Promise<ViewNode[]> {

+ 2
- 2
src/views/nodes/resultsCommitsNode.ts View File

@ -7,7 +7,7 @@ import { ViewWithFiles } from '../viewBase';
import { CommitNode } from './commitNode';
import { ShowMoreNode } from './common';
import { getBranchesAndTagTipsFn, insertDateMarkers } from './helpers';
import { getNextId, PageableViewNode, ResourceType, ViewNode } from './viewNode';
import { PageableViewNode, ResourceType, ViewNode } from './viewNode';
export interface CommitsQueryResults {
label: string;
@ -35,7 +35,7 @@ export class ResultsCommitsNode extends ViewNode implements Pagea
}
get id(): string {
return `${this._uniqueId}|${this._instanceId}:${this.type}(${this.repoPath})`;
return `${this.parent!.id}:results:commits`;
}
get type(): ResourceType {

+ 2
- 5
src/views/nodes/resultsFilesNode.ts View File

@ -8,7 +8,7 @@ import { Arrays, debug, gate, Iterables, Strings } from '../../system';
import { ViewWithFiles } from '../viewBase';
import { FileNode, FolderNode } from './folderNode';
import { ResultsFileNode } from './resultsFileNode';
import { getNextId, ResourceType, ViewNode } from './viewNode';
import { ResourceType, ViewNode } from './viewNode';
export interface FilesQueryResults {
label: string;
@ -16,9 +16,6 @@ export interface FilesQueryResults {
}
export class ResultsFilesNode extends ViewNode<ViewWithFiles> {
// Generate a unique id so the node order is preserved, since we update the label when the query completes
private readonly _uniqueId: number = getNextId('ResultsFilesNode');
constructor(
view: ViewWithFiles,
parent: ViewNode,
@ -30,7 +27,7 @@ export class ResultsFilesNode extends ViewNode {
}
get id(): string {
return `${this._uniqueId}|${this._instanceId}:gitlens:results:files(${this.repoPath})`;
return `${this.parent!.id}:results:files`;
}
async getChildren(): Promise<ViewNode[]> {

+ 1
- 1
src/views/nodes/searchNode.ts View File

@ -138,7 +138,7 @@ export class SearchNode extends ViewNode {
const promises: Promise<any>[] = [
...Iterables.filterMap(this._children, c => {
const result = c.refresh();
const result = c.refresh === undefined ? false : c.refresh();
return Functions.isPromise<boolean | void>(result) ? result : undefined;
})
];

+ 10
- 1
src/views/nodes/searchResultsCommitsNode.ts View File

@ -7,7 +7,11 @@ import { ViewWithFiles } from '../viewBase';
import { CommitsQueryResults, ResultsCommitsNode } from './resultsCommitsNode';
import { ResourceType, ViewNode } from './viewNode';
let instanceId = 0;
export class SearchResultsCommitsNode extends ResultsCommitsNode {
private _instanceId: number;
constructor(
view: ViewWithFiles,
parent: ViewNode,
@ -23,6 +27,12 @@ export class SearchResultsCommitsNode extends ResultsCommitsNode {
includeDescription: true,
querying: _querying
});
this._instanceId = instanceId++;
}
get id(): string {
return `gitlens:repository(${this.repoPath}):search(${this.searchBy}:${this.search}):commits|${this._instanceId}`;
}
get type(): ResourceType {
@ -44,7 +54,6 @@ export class SearchResultsCommitsNode extends ResultsCommitsNode {
arguments: [args]
};
}
item.id = undefined;
return item;
}

+ 1
- 1
src/views/nodes/stashNode.ts View File

@ -13,7 +13,7 @@ export class StashNode extends ViewRefNode {
}
get id(): string {
return `${this._instanceId}:gitlens:repository(${this.commit.repoPath}):stash(${this.commit.sha})`;
return `gitlens:repository(${this.commit.repoPath}):stash(${this.commit.sha})`;
}
get ref(): string {

+ 1
- 1
src/views/nodes/stashesNode.ts View File

@ -14,7 +14,7 @@ export class StashesNode extends ViewNode {
}
get id(): string {
return `${this._instanceId}:gitlens:repository(${this.repo.path}):stashes`;
return `gitlens:repository(${this.repo.path}):stashes`;
}
async getChildren(): Promise<ViewNode[]> {

+ 1
- 1
src/views/nodes/statusFilesNode.ts View File

@ -33,7 +33,7 @@ export class StatusFilesNode extends ViewNode {
}
get id(): string {
return `${this._instanceId}:gitlens:repository(${this.status.repoPath}):status:files`;
return `gitlens:repository(${this.status.repoPath}):status:files`;
}
async getChildren(): Promise<ViewNode[]> {

+ 1
- 1
src/views/nodes/tagNode.ts View File

@ -19,7 +19,7 @@ export class TagNode extends ViewRefNode implements PageableVi
}
get id(): string {
return `${this._instanceId}:gitlens:repository(${this.tag.repoPath}):tag(${this.tag.name})`;
return `gitlens:repository(${this.tag.repoPath}):tag(${this.tag.name})`;
}
get label(): string {

+ 1
- 1
src/views/nodes/tagsNode.ts View File

@ -16,7 +16,7 @@ export class TagsNode extends ViewNode {
}
get id(): string {
return `${this._instanceId}:gitlens:repository(${this.repo.path}):tags`;
return `gitlens:repository(${this.repo.path}):tags`;
}
async getChildren(): Promise<ViewNode[]> {

+ 9
- 44
src/views/nodes/viewNode.ts View File

@ -56,41 +56,10 @@ export interface ViewNode {
readonly id?: string;
}
const counters: { [key: string]: number } = {
instanceId: 0
};
export function getNextId(key?: string) {
if (key === undefined) {
key = 'instanceId';
}
let counter = counters[key] || 0;
if (counter === Number.MAX_SAFE_INTEGER) {
counter = 0;
}
counter++;
counters[key] = counter;
return counter;
}
@logName<ViewNode>((c, name) => `${name}(${c.id || c._instanceId})`)
@logName<ViewNode>((c, name) => `${name}${c.id != null ? `(${c.id})` : ''}`)
export abstract class ViewNode<TView extends View = View> {
protected readonly _instanceId: number;
constructor(uri: GitUri, public readonly view: TView, protected readonly parent?: ViewNode) {
this._instanceId = 0; //getNextId();
this._uri = uri;
if (Logger.isDebugging) {
const fn = this.getTreeItem;
this.getTreeItem = async function(this: ViewNode<TView>) {
const item = await fn.apply(this);
item.tooltip = `${item.tooltip || item.label}\n\nDBG: ${this.toString()}`;
return item;
};
}
}
toString() {
@ -114,11 +83,7 @@ export abstract class ViewNode {
return undefined;
}
@gate()
@debug()
refresh(reset: boolean = false): void | boolean | Promise<void> | Promise<boolean> {
// virtual
}
refresh?(reset?: boolean): void | boolean | Promise<void> | Promise<boolean>;
@gate()
@debug()
@ -135,7 +100,7 @@ export abstract class ViewRefNode extends ViewNode
}
toString() {
return `${super.toString()}: ${this.ref}`;
return `${super.toString()}:${this.ref}`;
}
}
@ -227,23 +192,23 @@ export abstract class SubscribeableViewNode extends V
this.onVisibilityChanged({ visible: this.view.visible });
}
protected onParentStateChanged(state: TreeItemCollapsibleState) {
// virtual
}
protected onStateChanged(state: TreeItemCollapsibleState) {
// virtual
}
protected onParentStateChanged?(state: TreeItemCollapsibleState): void;
protected onStateChanged?(state: TreeItemCollapsibleState): void;
protected _state: TreeItemCollapsibleState | undefined;
protected onNodeStateChanged(e: TreeViewNodeStateChangeEvent<ViewNode>) {
if (e.element === this) {
this._state = e.state;
if (this.onStateChanged !== undefined) {
this.onStateChanged(e.state);
}
}
else if (e.element === this.parent) {
if (this.onParentStateChanged !== undefined) {
this.onParentStateChanged(e.state);
}
}
}
@debug()
protected onVisibilityChanged(e: TreeViewVisibilityChangeEvent) {

+ 13
- 1
src/views/viewBase.ts View File

@ -56,6 +56,16 @@ export abstract class ViewBase> implements TreeData
protected _tree: TreeView<ViewNode> | undefined;
constructor(public readonly id: string, public readonly name: string) {
if (Logger.isDebugging) {
const fn = this.getTreeItem;
this.getTreeItem = async function(this: ViewBase<TRoot>, node: ViewNode) {
const item = await fn.apply(this, [node]);
item.tooltip = `${item.tooltip || item.label}\n\nDBG: ${node.toString()}`;
return item;
};
}
this.registerCommands();
Container.context.subscriptions.push(configuration.onDidChange(this.onConfigurationChanged, this));
@ -141,7 +151,7 @@ export abstract class ViewBase> implements TreeData
@debug()
async refresh(reset: boolean = false) {
if (this._root !== undefined) {
if (this._root !== undefined && this._root.refresh !== undefined) {
await this._root.refresh(reset);
}
@ -167,8 +177,10 @@ export abstract class ViewBase> implements TreeData
}
}
if (node.refresh !== undefined) {
const cancel = await node.refresh(reset);
if (cancel === true) return;
}
this.triggerNodeChange(node);
}

Loading…
Cancel
Save