From af5b8b7e09a4b452af3c8dad89fde9e336818671 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Thu, 16 Feb 2017 17:06:37 -0500 Subject: [PATCH] Changes behavior of CodeLens showQuickFileHistory It now opens commit details directly --- src/commands/quickPicks.ts | 6 +++--- src/commands/showQuickFileHistory.ts | 26 +++++++++++++++----------- src/gitCodeLensProvider.ts | 6 +++--- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/commands/quickPicks.ts b/src/commands/quickPicks.ts index f570735..9646604 100644 --- a/src/commands/quickPicks.ts +++ b/src/commands/quickPicks.ts @@ -28,14 +28,14 @@ export class CommitQuickPick { label: `$(versions) Show Previous Commit History`, description: `\u2022 ${commit.fileName}`, detail: `Shows the previous commit history starting at $(git-commit) ${commit.sha}` - }, Commands.ShowQuickFileHistory, [new GitUri(commit.uri, commit), undefined, currentCommand])); + }, Commands.ShowQuickFileHistory, [new GitUri(commit.uri, commit), undefined, undefined, currentCommand])); if (workingFileName) { items.push(new CommandQuickPickItem({ label: `$(versions) Show Commit History`, description: `\u2022 ${commit.fileName}`, detail: `Shows the commit history starting at the most recent commit` - }, Commands.ShowQuickFileHistory, [commit.uri, undefined, currentCommand])); + }, Commands.ShowQuickFileHistory, [commit.uri, undefined, undefined, currentCommand])); } } @@ -80,7 +80,7 @@ export class FileCommitsQuickPick { label: `$(sync) Show All Commits`, description: `\u2014 Currently only showing the first ${defaultMaxCount} commits`, detail: `This may take a while` - }, Commands.ShowQuickFileHistory, [uri, 0, goBackCommand])); + }, Commands.ShowQuickFileHistory, [uri, 0, undefined, goBackCommand])); } // Only show the full repo option if we are the root diff --git a/src/commands/showQuickFileHistory.ts b/src/commands/showQuickFileHistory.ts index 49402b2..0383518 100644 --- a/src/commands/showQuickFileHistory.ts +++ b/src/commands/showQuickFileHistory.ts @@ -2,7 +2,7 @@ import { commands, TextEditor, Uri, window } from 'vscode'; import { ActiveEditorCommand } from './commands'; import { Commands } from '../constants'; -import GitProvider, { GitUri } from '../gitProvider'; +import GitProvider, { GitCommit, GitUri } from '../gitProvider'; import { Logger } from '../logger'; import { CommandQuickPickItem } from './quickPickItems'; import { FileCommitsQuickPick } from './quickPicks'; @@ -13,7 +13,7 @@ export default class ShowQuickFileHistoryCommand extends ActiveEditorCommand { super(Commands.ShowQuickFileHistory); } - async execute(editor: TextEditor, uri?: Uri, maxCount?: number, goBackCommand?: CommandQuickPickItem) { + async execute(editor: TextEditor, uri?: Uri, maxCount?: number, commit?: GitCommit, goBackCommand?: CommandQuickPickItem) { if (!(uri instanceof Uri)) { if (!editor || !editor.document) return undefined; uri = editor.document.uri; @@ -26,23 +26,27 @@ export default class ShowQuickFileHistoryCommand extends ActiveEditorCommand { } try { - const log = await this.git.getLogForFile(gitUri.fsPath, gitUri.sha, gitUri.repoPath, undefined, maxCount); - if (!log) return window.showWarningMessage(`Unable to show file history. File is probably not under source control`); + if (!commit) { + const log = await this.git.getLogForFile(gitUri.fsPath, gitUri.sha, gitUri.repoPath, undefined, maxCount); + if (!log) return window.showWarningMessage(`Unable to show file history. File is probably not under source control`); - let pick = await FileCommitsQuickPick.show(log, uri, maxCount, this.git.config.advanced.maxQuickHistory, goBackCommand); - if (!pick) return undefined; + let pick = await FileCommitsQuickPick.show(log, uri, maxCount, this.git.config.advanced.maxQuickHistory, goBackCommand); + if (!pick) return undefined; - if (pick instanceof CommandQuickPickItem) { - return pick.execute(); + if (pick instanceof CommandQuickPickItem) { + return pick.execute(); + } + + commit = pick.commit; } return commands.executeCommand(Commands.ShowQuickCommitDetails, - new GitUri(pick.commit.uri, pick.commit), - pick.commit.sha, pick.commit, + new GitUri(commit.uri, commit), + commit.sha, commit, new CommandQuickPickItem({ label: `go back \u21A9`, description: null - }, Commands.ShowQuickFileHistory, [uri, maxCount, goBackCommand]), + }, Commands.ShowQuickFileHistory, [uri, maxCount, undefined, goBackCommand]), { showFileHistory: false }); } catch (ex) { diff --git a/src/gitCodeLensProvider.ts b/src/gitCodeLensProvider.ts index 8f533ac..263814b 100644 --- a/src/gitCodeLensProvider.ts +++ b/src/gitCodeLensProvider.ts @@ -212,7 +212,7 @@ export default class GitCodeLensProvider implements CodeLensProvider { case CodeLensCommand.ShowBlameHistory: return this._applyShowBlameHistoryCommand(title, lens, blame, recentCommit); case CodeLensCommand.ShowFileHistory: return this._applyShowFileHistoryCommand(title, lens, blame, recentCommit); case CodeLensCommand.DiffWithPrevious: return this._applyDiffWithPreviousCommand(title, lens, blame, recentCommit); - case CodeLensCommand.ShowQuickFileHistory: return this._applyShowQuickFileHistoryCommand(title, lens, blame); + case CodeLensCommand.ShowQuickFileHistory: return this._applyShowQuickFileHistoryCommand(title, lens, blame, recentCommit); default: return lens; } } @@ -295,11 +295,11 @@ export default class GitCodeLensProvider implements CodeLensProvider { return lens; } - _applyShowQuickFileHistoryCommand(title: string, lens: T, blame: IGitBlameLines): T { + _applyShowQuickFileHistoryCommand(title: string, lens: T, blame: IGitBlameLines, commit?: GitCommit): T { lens.command = { title: title, command: CodeLensCommand.ShowQuickFileHistory, - arguments: [Uri.file(lens.uri.fsPath)] + arguments: [Uri.file(lens.uri.fsPath), undefined, commit] }; return lens; }