mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-12 19:18:32 -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';
|
||||
import { Command, ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
|
||||
import { ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
|
||||
import { Commands, DiffWithPreviousCommandArgs } from '../commands';
|
||||
import { ExplorerNode, ResourceType } from './explorerNode';
|
||||
import { GitCommit, GitService, GitUri, IGitStatusFile } from '../gitService';
|
||||
@@ -7,18 +7,32 @@ import { GitCommit, GitService, GitUri, IGitStatusFile } from '../gitService';
|
||||
export class CommitFileNode extends ExplorerNode {
|
||||
|
||||
readonly resourceType: ResourceType = 'commit-file';
|
||||
command: Command;
|
||||
|
||||
constructor(public status: IGitStatusFile, public commit: GitCommit, uri: GitUri, context: ExtensionContext, git: GitService) {
|
||||
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',
|
||||
command: Commands.DiffWithPrevious,
|
||||
arguments: [
|
||||
GitUri.fromFileStatus(this.status, this.commit.repoPath),
|
||||
{
|
||||
commit: commit,
|
||||
commit: this.commit,
|
||||
showOptions: {
|
||||
preserveFocus: true,
|
||||
preview: true
|
||||
@@ -26,16 +40,6 @@ export class CommitFileNode extends ExplorerNode {
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user