mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-14 12:08:33 -05:00
Defers command construction until later
Gets a properly constructed commit to improve performance of opening the diff
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { Command, ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
|
import { ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
|
||||||
import { Commands, DiffWithPreviousCommandArgs } from '../commands';
|
import { Commands, DiffWithPreviousCommandArgs } from '../commands';
|
||||||
import { ExplorerNode, ResourceType } from './explorerNode';
|
import { ExplorerNode, ResourceType } from './explorerNode';
|
||||||
import { GitCommit, GitService, GitUri, IGitStatusFile } from '../gitService';
|
import { GitCommit, GitService, GitUri, IGitStatusFile } from '../gitService';
|
||||||
@@ -7,18 +7,32 @@ import { GitCommit, GitService, GitUri, IGitStatusFile } from '../gitService';
|
|||||||
export class CommitFileNode extends ExplorerNode {
|
export class CommitFileNode extends ExplorerNode {
|
||||||
|
|
||||||
readonly resourceType: ResourceType = 'commit-file';
|
readonly resourceType: ResourceType = 'commit-file';
|
||||||
command: Command;
|
|
||||||
|
|
||||||
constructor(public status: IGitStatusFile, public commit: GitCommit, uri: GitUri, context: ExtensionContext, git: GitService) {
|
constructor(public status: IGitStatusFile, public commit: GitCommit, uri: GitUri, context: ExtensionContext, git: GitService) {
|
||||||
super(uri, context, git);
|
super(uri, context, git);
|
||||||
|
}
|
||||||
|
|
||||||
this.command = {
|
getChildren(): Promise<ExplorerNode[]> {
|
||||||
|
return Promise.resolve([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getTreeItem(): Promise<TreeItem> {
|
||||||
|
if (this.commit.type !== 'file') {
|
||||||
|
const log = await this.git.getLogForFile(this.commit.repoPath, this.status.fileName, this.commit.sha, { maxCount: 2 });
|
||||||
|
if (log !== undefined) {
|
||||||
|
this.commit = log.commits.get(this.commit.sha) || this.commit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const item = new TreeItem(`${GitUri.getFormattedPath(this.status.fileName)}`, TreeItemCollapsibleState.None);
|
||||||
|
item.contextValue = this.resourceType;
|
||||||
|
item.command = {
|
||||||
title: 'Compare File with Previous',
|
title: 'Compare File with Previous',
|
||||||
command: Commands.DiffWithPrevious,
|
command: Commands.DiffWithPrevious,
|
||||||
arguments: [
|
arguments: [
|
||||||
GitUri.fromFileStatus(this.status, this.commit.repoPath),
|
GitUri.fromFileStatus(this.status, this.commit.repoPath),
|
||||||
{
|
{
|
||||||
commit: commit,
|
commit: this.commit,
|
||||||
showOptions: {
|
showOptions: {
|
||||||
preserveFocus: true,
|
preserveFocus: true,
|
||||||
preview: true
|
preview: true
|
||||||
@@ -26,16 +40,6 @@ export class CommitFileNode extends ExplorerNode {
|
|||||||
} as DiffWithPreviousCommandArgs
|
} as DiffWithPreviousCommandArgs
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
getChildren(): Promise<ExplorerNode[]> {
|
|
||||||
return Promise.resolve([]);
|
|
||||||
}
|
|
||||||
|
|
||||||
getTreeItem(): TreeItem {
|
|
||||||
const item = new TreeItem(`${GitUri.getFormattedPath(this.status.fileName)}`, TreeItemCollapsibleState.None);
|
|
||||||
item.contextValue = this.resourceType;
|
|
||||||
item.command = this.command;
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { Iterables } from '../system';
|
import { Iterables } from '../system';
|
||||||
import { Command, ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
|
import { ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
|
||||||
import { CommitFileNode } from './commitFileNode';
|
import { CommitFileNode } from './commitFileNode';
|
||||||
import { ExplorerNode, ResourceType } from './explorerNode';
|
import { ExplorerNode, ResourceType } from './explorerNode';
|
||||||
import { CommitFormatter, GitCommit, GitService, GitUri } from '../gitService';
|
import { CommitFormatter, GitCommit, GitService, GitUri } from '../gitService';
|
||||||
@@ -8,25 +8,9 @@ import { CommitFormatter, GitCommit, GitService, GitUri } from '../gitService';
|
|||||||
export class CommitNode extends ExplorerNode {
|
export class CommitNode extends ExplorerNode {
|
||||||
|
|
||||||
readonly resourceType: ResourceType = 'commit';
|
readonly resourceType: ResourceType = 'commit';
|
||||||
command: Command;
|
|
||||||
|
|
||||||
constructor(public commit: GitCommit, uri: GitUri, context: ExtensionContext, git: GitService) {
|
constructor(public commit: GitCommit, uri: GitUri, context: ExtensionContext, git: GitService) {
|
||||||
super(uri, context, git);
|
super(uri, context, git);
|
||||||
|
|
||||||
// this.command = {
|
|
||||||
// title: 'Compare File with Previous',
|
|
||||||
// command: Commands.DiffWithPrevious,
|
|
||||||
// arguments: [
|
|
||||||
// Uri.file(commit.uri.fsPath),
|
|
||||||
// {
|
|
||||||
// commit: commit,
|
|
||||||
// showOptions: {
|
|
||||||
// preserveFocus: true,
|
|
||||||
// preview: true
|
|
||||||
// }
|
|
||||||
// } as DiffWithPreviousCommandArgs
|
|
||||||
// ]
|
|
||||||
// };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getChildren(): Promise<ExplorerNode[]> {
|
async getChildren(): Promise<ExplorerNode[]> {
|
||||||
@@ -48,7 +32,6 @@ export class CommitNode extends ExplorerNode {
|
|||||||
dark: this.context.asAbsolutePath('images/dark/icon-commit.svg'),
|
dark: this.context.asAbsolutePath('images/dark/icon-commit.svg'),
|
||||||
light: this.context.asAbsolutePath('images/light/icon-commit.svg')
|
light: this.context.asAbsolutePath('images/light/icon-commit.svg')
|
||||||
};
|
};
|
||||||
item.command = this.command;
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { Command, ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
|
import { ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
|
||||||
import { CommitFileNode } from './commitFileNode';
|
import { CommitFileNode } from './commitFileNode';
|
||||||
import { ExplorerNode, ResourceType } from './explorerNode';
|
import { ExplorerNode, ResourceType } from './explorerNode';
|
||||||
import { CommitFormatter, GitService, GitStashCommit, GitUri } from '../gitService';
|
import { CommitFormatter, GitService, GitStashCommit, GitUri } from '../gitService';
|
||||||
@@ -7,25 +7,12 @@ import { CommitFormatter, GitService, GitStashCommit, GitUri } from '../gitServi
|
|||||||
export class StashCommitNode extends ExplorerNode {
|
export class StashCommitNode extends ExplorerNode {
|
||||||
|
|
||||||
readonly resourceType: ResourceType = 'stash-commit';
|
readonly resourceType: ResourceType = 'stash-commit';
|
||||||
command: Command;
|
|
||||||
|
|
||||||
constructor(public commit: GitStashCommit, uri: GitUri, context: ExtensionContext, git: GitService) {
|
constructor(public commit: GitStashCommit, uri: GitUri, context: ExtensionContext, git: GitService) {
|
||||||
super(uri, context, git);
|
super(uri, context, git);
|
||||||
|
|
||||||
// this.command = {
|
|
||||||
// title: 'Show Stash Details',
|
|
||||||
// command: Commands.ShowQuickCommitDetails,
|
|
||||||
// arguments: [
|
|
||||||
// new GitUri(commit.uri, commit),
|
|
||||||
// {
|
|
||||||
// commit: commit,
|
|
||||||
// sha: commit.sha
|
|
||||||
// } as ShowQuickCommitDetailsCommandArgs
|
|
||||||
// ]
|
|
||||||
// };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getChildren(): Promise<CommitFileNode[]> {
|
async getChildren(): Promise<CommitFileNode[]> {
|
||||||
return Promise.resolve((this.commit as GitStashCommit).fileStatuses.map(_ => new CommitFileNode(_, this.commit, this.uri, this.context, this.git)));
|
return Promise.resolve((this.commit as GitStashCommit).fileStatuses.map(_ => new CommitFileNode(_, this.commit, this.uri, this.context, this.git)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,7 +21,17 @@ export class StashCommitNode extends ExplorerNode {
|
|||||||
|
|
||||||
const item = new TreeItem(label, TreeItemCollapsibleState.Collapsed);
|
const item = new TreeItem(label, TreeItemCollapsibleState.Collapsed);
|
||||||
item.contextValue = this.resourceType;
|
item.contextValue = this.resourceType;
|
||||||
item.command = this.command;
|
// item.command = {
|
||||||
|
// title: 'Show Stash Details',
|
||||||
|
// command: Commands.ShowQuickCommitDetails,
|
||||||
|
// arguments: [
|
||||||
|
// new GitUri(commit.uri, commit),
|
||||||
|
// {
|
||||||
|
// commit: this.commit,
|
||||||
|
// sha: this.commit.sha
|
||||||
|
// } as ShowQuickCommitDetailsCommandArgs
|
||||||
|
// ]
|
||||||
|
// };
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user