From b4ecb701b2f612ac3ab776e035770fd7d3b8f312 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sat, 30 Dec 2017 11:46:16 -0500 Subject: [PATCH] Closes #237 - Adds single commit in results --- CHANGELOG.md | 8 ++++++-- README.md | 6 +++--- src/quickPicks/commitDetails.ts | 6 +++++- src/quickPicks/common.ts | 24 ++++++++++++++++++++++-- src/views/commitResultsNode.ts | 32 ++++++++++++++++++++++++++++++++ src/views/explorerNodes.ts | 1 + src/views/resultsExplorer.ts | 9 +++++++-- 7 files changed, 76 insertions(+), 10 deletions(-) create mode 100644 src/views/commitResultsNode.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ffd908..80ed38a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Added +- Adds semi-persistent results for commit operations, via the `Show Commit Details` command (`gitlens.showQuickCommitDetails`) in the `GitLens Results` view -- closes [#237](https://github.com/eamodio/vscode-gitlens/issues/237) +- Adds `Show in Results` option to the commit details quick pick menu to show the commit in the `GitLens Results` view + ### Changed - Improves startup performance and reduces package size @@ -55,12 +59,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p - Adds an all-new, on-demand `GitLens Results` view to the Explorer activity - - Provides semi-persistent results for commit search operations, via `Show Commit Search` command (`gitlens.showCommitSearch`), and file history operations, via `Show File History` command (`gitlens.showQuickFileHistory`) + - Provides semi-persistent results for commit search operations, via the `Show Commit Search` command (`gitlens.showCommitSearch`), and file history operations, via the `Show File History` command (`gitlens.showQuickFileHistory`) - Expand each revision (commit) to quickly see the set of files changed, complete with status indicators for adds, changes, renames, and deletes - Provides a context menu on each revision (commit) with `Open Commit in Remote`, `Open All Changes`, `Open All Changes with Working Tree`, `Open Files`, `Open Revisions`, `Copy Commit ID to Clipboard`, `Copy Commit Message to Clipboard`, `Show Commit Details`, `Compare with Selected`, `Select for Compare`, `Rebase Commit (via Terminal)`, `Reset Commit (via Terminal)`, and `Refresh` commands - Provides a context menu on each changed file with `Open Changes`, `Open Changes with Working Tree`, `Open File`, `Open Revision`, `Open File in Remote`, `Open Revision in Remote`, `Apply Changes`, and `Show Commit File Details` commands - - Provides semi-persistent results for revision comparison operations, via `Select for Compare` command (`gitlens.explorers.selectForCompare`) and `Compare with Selected` command (`gitlens.explorers.compareWithSelected`) + - Provides semi-persistent results for revision comparison operations, via the `Select for Compare` command (`gitlens.explorers.selectForCompare`) and the `Compare with Selected` command (`gitlens.explorers.compareWithSelected`) - `Commits` node — provides a list of the commits between the compared revisions (branches or commits) - Expand each revision (commit) to quickly see the set of files changed, complete with status indicators for adds, changes, renames, and deletes - Provides a context menu on each revision (commit) with `Open Commit in Remote`, `Open All Changes`, `Open All Changes with Working Tree`, `Open Files`, `Open Revisions`, `Copy Commit ID to Clipboard`, `Copy Commit Message to Clipboard`, `Show Commit Details`, `Compare with Selected`, `Select for Compare`, `Rebase Commit (via Terminal)`, `Reset Commit (via Terminal)`, and `Refresh` commands diff --git a/README.md b/README.md index 7839586..69aeb0c 100644 --- a/README.md +++ b/README.md @@ -210,12 +210,12 @@ While GitLens is highly customizable and provides many [configuration settings]( - Adds an on-demand, [customizable](#gitlens-results-view-settings) `GitLens Results` view to the Explorer activity - - Provides semi-persistent results for commit search operations, via Show Commit Search command (`gitlens.showCommitSearch`), and file history operations, via Show File History command (`gitlens.showQuickFileHistory`) + - Provides semi-persistent results for commit search operations, via the `Show Commit Search` command (`gitlens.showCommitSearch`), file history operations, via the `Show File History` command (`gitlens.showQuickFileHistory`), and commit operations, via the `Show Commit Details` command (`gitlens.showQuickCommitDetails`) - Expand each revision (commit) to quickly see the set of files changed, complete with status indicators for adds, changes, renames, and deletes - Provides a context menu on each revision (commit) with `Open Commit in Remote`, `Open All Changes`, `Open All Changes with Working Tree`, `Open Files`, `Open Revisions`, `Copy Commit ID to Clipboard`, `Copy Commit Message to Clipboard`, `Show Commit Details`, `Compare with Selected`, `Select for Compare`, `Rebase Commit (via Terminal)`, `Reset Commit (via Terminal)`, and `Refresh` commands - Provides a context menu on each changed file with `Open Changes`, `Open Changes with Working Tree`, `Open File`, `Open Revision`, `Open File in Remote`, `Open Revision in Remote`, `Apply Changes`, and `Show Commit File Details` commands - - Provides semi-persistent results for revision comparison operations, via `Select for Compare` command (`gitlens.explorers.selectForCompare`) and `Compare with Selected` command (`gitlens.explorers.compareWithSelected`) + - Provides semi-persistent results for revision comparison operations, via the `Select for Compare` command (`gitlens.explorers.selectForCompare`) and the `Compare with Selected` command (`gitlens.explorers.compareWithSelected`) - `Commits` node — provides a list of the commits between the compared revisions (branches or commits) - Expand each revision (commit) to quickly see the set of files changed, complete with status indicators for adds, changes, renames, and deletes - Provides a context menu on each revision (commit) with `Open Commit in Remote`, `Open All Changes`, `Open All Changes with Working Tree`, `Open Files`, `Open Revisions`, `Copy Commit ID to Clipboard`, `Copy Commit Message to Clipboard`, `Show Commit Details`, `Compare with Selected`, `Select for Compare`, `Rebase Commit (via Terminal)`, `Reset Commit (via Terminal)`, and `Refresh` commands @@ -258,7 +258,7 @@ While GitLens is highly customizable and provides many [configuration settings]( ![Commit Details Quick Pick Menu](https://raw.githubusercontent.com/eamodio/vscode-gitlens/master/images/screenshot-commit-details.png) - Quickly see the set of files changed in the commit, complete with status indicators for adds, changes, renames, and deletes - - Provides additional entries to `Open Commit in ` when available, `Open Files`, `Open Revisions`, `Open Directory Compare with Previous Revision`, `Open Directory Compare with Working Tree`, `Copy Commit ID to Clipboard`, `Copy Commit Message to Clipboard` + - Provides additional entries to `Show in Results`, `Open Commit in ` when available, `Open Files`, `Open Revisions`, `Open Directory Compare with Previous Revision`, `Open Directory Compare with Working Tree`, `Copy Commit ID to Clipboard`, `Copy Commit Message to Clipboard` - Navigate back to the previous quick pick menu via `alt+left arrow`, if available - Use the `alt+right arrow` shortcut on an entry to execute it without closing the quick pick menu, if possible — commands that open windows outside of VS Code will still close the quick pick menu unless [`"gitlens.advanced.quickPick.closeOnFocusOut": false`](#advanced-settings) is set - Use the `alt+right arrow` shortcut on a file entry in the `Changed Files` section to preview the comparison of the current revision with the previous one diff --git a/src/quickPicks/commitDetails.ts b/src/quickPicks/commitDetails.ts index 7929de8..a953f05 100644 --- a/src/quickPicks/commitDetails.ts +++ b/src/quickPicks/commitDetails.ts @@ -2,7 +2,7 @@ import { Arrays, Iterables, Strings } from '../system'; import { commands, QuickPickOptions, TextDocumentShowOptions, Uri, window } from 'vscode'; import { Commands, CopyMessageToClipboardCommandArgs, CopyShaToClipboardCommandArgs, DiffDirectoryCommandCommandArgs, DiffWithPreviousCommandArgs, ShowQuickCommitDetailsCommandArgs, StashApplyCommandArgs, StashDeleteCommandArgs } from '../commands'; -import { CommandQuickPickItem, getQuickPickIgnoreFocusOut, KeyCommandQuickPickItem, OpenFileCommandQuickPickItem, OpenFilesCommandQuickPickItem, QuickPickItem } from './common'; +import { CommandQuickPickItem, getQuickPickIgnoreFocusOut, KeyCommandQuickPickItem, OpenFileCommandQuickPickItem, OpenFilesCommandQuickPickItem, QuickPickItem, ShowCommitInResultsQuickPickItem } from './common'; import { GlyphChars } from '../constants'; import { getGitStatusOcticon, GitLog, GitLogCommit, GitService, GitStashCommit, GitStatusFile, GitStatusFileStatus, GitUri, IGitStatusFile, RemoteResource } from '../gitService'; import { Keyboard, KeyCommand, KeyNoopCommand, Keys } from '../keyboard'; @@ -122,8 +122,12 @@ export class CommitDetailsQuickPick { } as StashDeleteCommandArgs ]) ); + + items.splice(index++, 0, new ShowCommitInResultsQuickPickItem(commit)); } else { + items.splice(index++, 0, new ShowCommitInResultsQuickPickItem(commit)); + const remotes = (await git.getRemotes(commit.repoPath)).filter(r => r.provider !== undefined); if (remotes.length) { items.splice(index++, 0, new OpenRemotesCommandQuickPickItem(remotes, { diff --git a/src/quickPicks/common.ts b/src/quickPicks/common.ts index 9e8ab07..740090d 100644 --- a/src/quickPicks/common.ts +++ b/src/quickPicks/common.ts @@ -174,6 +174,23 @@ export class CommitQuickPickItem implements QuickPickItem { } } +export class ShowCommitInResultsQuickPickItem extends CommandQuickPickItem { + constructor( + public readonly commit: GitLogCommit, + item: QuickPickItem = { + label: 'Show in Results', + description: `${Strings.pad(GlyphChars.Dash, 2, 2)} displays commit in the GitLens Results view` + } + ) { + super(item, undefined, undefined); + } + + async execute(options: TextDocumentShowOptions = { preserveFocus: false, preview: false }): Promise<{} | undefined> { + ResultsExplorer.instance.showCommitInResults(this.commit); + return undefined; + } +} + export class ShowCommitsInResultsQuickPickItem extends CommandQuickPickItem { constructor( @@ -181,7 +198,7 @@ export class ShowCommitsInResultsQuickPickItem extends CommandQuickPickItem { public readonly resultsLabel: string | { label: string, resultsType?: { singular: string, plural: string } }, item: QuickPickItem = { label: 'Show in Results', - description: `${Strings.pad(GlyphChars.Dash, 2, 2)} displays results in the GitLens Results view` + description: `${Strings.pad(GlyphChars.Dash, 2, 2)} displays commits in the GitLens Results view` } ) { super(item, undefined, undefined); @@ -198,7 +215,10 @@ export class ShowCommitsSearchInResultsQuickPickItem extends ShowCommitsInResult constructor( public readonly results: GitLog, public readonly search: string, - item?: QuickPickItem + item: QuickPickItem = { + label: 'Show in Results', + description: `${Strings.pad(GlyphChars.Dash, 2, 2)} displays results in the GitLens Results view` + } ) { super(results, { label: search }, item); } diff --git a/src/views/commitResultsNode.ts b/src/views/commitResultsNode.ts new file mode 100644 index 0000000..bba9c43 --- /dev/null +++ b/src/views/commitResultsNode.ts @@ -0,0 +1,32 @@ +'use strict'; +import { Strings } from '../system'; +import { TreeItem, TreeItemCollapsibleState } from 'vscode'; +import { CommitNode } from './commitNode'; +import { GlyphChars } from '../constants'; +import { Explorer, ExplorerNode, MessageNode, ResourceType } from './explorerNode'; +import { CommitFormatter, GitLogCommit } from '../gitService'; + +export class CommitResultsNode extends ExplorerNode { + + constructor( + readonly commit: GitLogCommit, + private readonly explorer: Explorer, + private readonly contextValue: ResourceType = ResourceType.Results + ) { + super(commit.toGitUri()); + } + + async getChildren(): Promise { + const children = await new CommitNode(this.commit, this.explorer).getChildren(); + // Since we can't control the tooltip separately from the message (see https://github.com/Microsoft/vscode/issues/32012), don't truncate it + children.splice(0, 0, new MessageNode(CommitFormatter.fromTemplate('${message}', this.commit, { truncateMessageAtNewLine: false }))); + return children; + } + + async getTreeItem(): Promise { + const label = CommitFormatter.fromTemplate(`Commit \${sha} ${Strings.pad(GlyphChars.Dash, 1, 1)} \${authorAgo}`, this.commit, this.explorer.git.config.defaultDateFormat); + const item = new TreeItem(label, TreeItemCollapsibleState.Expanded); + item.contextValue = this.contextValue; + return item; + } +} \ No newline at end of file diff --git a/src/views/explorerNodes.ts b/src/views/explorerNodes.ts index 96fca7d..ab91d1a 100644 --- a/src/views/explorerNodes.ts +++ b/src/views/explorerNodes.ts @@ -6,6 +6,7 @@ export * from './branchesNode'; export * from './branchNode'; export * from './commitFileNode'; export * from './commitNode'; +export * from './commitResultsNode'; export * from './commitsNode'; export * from './commitsResultsNode'; export * from './comparisionResultsNode'; diff --git a/src/views/resultsExplorer.ts b/src/views/resultsExplorer.ts index f624813..e5bdca2 100644 --- a/src/views/resultsExplorer.ts +++ b/src/views/resultsExplorer.ts @@ -4,8 +4,8 @@ import { commands, ConfigurationChangeEvent, ConfigurationTarget, Event, EventEm import { configuration, ExplorerFilesLayout, IExplorerConfig } from '../configuration'; import { CommandContext, setCommandContext, WorkspaceState } from '../constants'; import { ExplorerCommands, RefreshNodeCommandArgs } from './explorerCommands'; -import { CommitsResultsNode, ComparisionResultsNode, ExplorerNode, MessageNode, RefreshReason, ResourceType } from './explorerNodes'; -import { clearGravatarCache, GitLog, GitService } from '../gitService'; +import { CommitResultsNode, CommitsResultsNode, ComparisionResultsNode, ExplorerNode, MessageNode, RefreshReason, ResourceType } from './explorerNodes'; +import { clearGravatarCache, GitLog, GitLogCommit, GitService } from '../gitService'; import { Logger } from '../logger'; export * from './explorerNodes'; @@ -134,6 +134,11 @@ export class ResultsExplorer implements TreeDataProvider { setCommandContext(CommandContext.ResultsExplorer, true); } + showCommitInResults(commit: GitLogCommit) { + this.addResults(new CommitResultsNode(commit, this)); + setCommandContext(CommandContext.ResultsExplorer, true); + } + showCommitsInResults(results: GitLog, resultsLabel: string | { label: string, resultsType?: { singular: string, plural: string } }) { const query = results.query === undefined ? (maxCount: number | undefined) => Promise.resolve(results)