From b9bc84f0d2e42966ccf5b407dbfc6de99c2515a1 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sat, 16 Dec 2017 01:34:42 -0500 Subject: [PATCH] Adds Show All Commits to commit search Adds Show in Results to file history quick pick Adds re-query support to GitLog Fixes Open in File/Revision for file history quick pick --- README.md | 11 +++-- src/commands/diffWithRevision.ts | 16 ++++++-- src/commands/showCommitSearch.ts | 75 +++++++++++++++------------------- src/commands/showQuickBranchHistory.ts | 3 -- src/commands/showQuickFileHistory.ts | 23 ++++++++--- src/git/models/log.ts | 2 + src/gitService.ts | 18 ++++++++ src/quickPicks/commits.ts | 16 +++++--- src/quickPicks/common.ts | 21 ++++++++-- src/quickPicks/fileHistory.ts | 46 +++++++++++---------- src/views/explorerCommands.ts | 2 +- src/views/resultsExplorer.ts | 23 ++++++++--- 12 files changed, 157 insertions(+), 99 deletions(-) diff --git a/README.md b/README.md index 3edf6b5..96ec977 100644 --- a/README.md +++ b/README.md @@ -241,7 +241,7 @@ While GitLens is highly customizable and provides many [configuration settings]( ![File History Quick Pick Menu](https://raw.githubusercontent.com/eamodio/vscode-gitlens/master/images/screenshot-file-history.png) - - Provides entries to `Show Branch History` and `Open File in ` when available + - Provides additional entries to `Show in Results`, `Show Branch History`, and `Open File in ` when available - Navigate back to the previous quick pick menu via `alt+left arrow`, if available - Navigate pages via `alt+,` and `alt+.` to go backward and forward respectively @@ -250,7 +250,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 entries to `Copy to Clipboard`, `Compare Directory with...`, `Open Changed Files`, `Open File in ` when available, and more + - Provides additional entries to `Open Commit in ` when available, `Open Files`, `Open Revisions`, `Compare Directory with Previous Revision`, `Compare Directory 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`](#extension-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 @@ -259,7 +259,7 @@ While GitLens is highly customizable and provides many [configuration settings]( ![Commit File Details Quick Pick Menu](https://raw.githubusercontent.com/eamodio/vscode-gitlens/master/images/screenshot-commit-file-details.png) - - Provides entries to `Show Commit Details`, `Show File History`, `Compare File with...`, `Copy to Clipboard`, `Open File`, `Open File in ` when available, and more + - Provides entries to `Open Changes`, `Open Changes with Working Tree`, `Open File`, `Open Revision`, `Open File in ` when available, `Open Revision in ` when available, `Copy Commit ID to Clipboard`, `Copy Commit Message to Clipboard`, `Show Commit Details`, `Show File History`, and `Show Previous File History` - 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`](#extension-settings) is set @@ -279,7 +279,7 @@ While GitLens is highly customizable and provides many [configuration settings]( ![Stashed Changes Quick Pick Menu](https://raw.githubusercontent.com/eamodio/vscode-gitlens/master/images/screenshot-stash-list.png) - - Provides entries to `Stash Changes` + - Provides additional entries to `Stash Changes` - Navigate back to the previous quick pick menu via `alt+left arrow`, if available - Choosing a stash entry shows a **stash details quick pick menu** which is very similar to the **commit details quick pick menu** above @@ -287,8 +287,7 @@ While GitLens is highly customizable and provides many [configuration settings]( ![Stash Details Quick Pick Menu](https://raw.githubusercontent.com/eamodio/vscode-gitlens/master/images/screenshot-stash-details.png) - Quickly see the set of files changed in the stash, complete with status indicators for adds, changes, renames, and deletes - - Provides entries to `Copy Message to Clipboard`, `Compare Directory with...`, and `Open Changed Files` - - Provides entries to `Apply Stashed Changes` and `Delete Stashed Changes` — both require a confirmation + - Provides additional entries to `Apply Stashed Changes` (requires confirmation), `Delete Stashed Changes` (requires confirmation), `Open Files`, `Open Revisions`, `Compare Directory with Previous Revision`, `Compare Directory with Working Tree`, `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`](#extension-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/commands/diffWithRevision.ts b/src/commands/diffWithRevision.ts index 27792dc..ef99435 100644 --- a/src/commands/diffWithRevision.ts +++ b/src/commands/diffWithRevision.ts @@ -1,6 +1,8 @@ 'use strict'; +import { Strings } from '../system'; import { commands, TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode'; import { ActiveEditorCommand, Commands, getCommandUri } from './common'; +import { GlyphChars } from '../constants'; import { DiffWithCommandArgs } from './diffWith'; import { GitService, GitUri } from '../gitService'; import { Logger } from '../logger'; @@ -32,9 +34,6 @@ export class DiffWithRevisionCommand extends ActiveEditorCommand { } const gitUri = await GitUri.fromUri(uri, this.git); - if (args.maxCount == null) { - args.maxCount = this.git.config.advanced.maxQuickHistory; - } const progressCancellation = FileHistoryQuickPick.showProgress(gitUri); try { @@ -43,7 +42,16 @@ export class DiffWithRevisionCommand extends ActiveEditorCommand { if (progressCancellation.token.isCancellationRequested) return undefined; - const pick = await FileHistoryQuickPick.show(this.git, log, gitUri, progressCancellation, { pickerOnly: true }); + const label = `${gitUri.getFormattedPath()}${gitUri.sha ? ` ${Strings.pad(GlyphChars.Dot, 1, 1)} ${gitUri.shortSha}` : ''}`; + const pick = await FileHistoryQuickPick.show(this.git, log, gitUri, label, progressCancellation, { + pickerOnly: true, + showAllCommand: log !== undefined && log.truncated + ? new CommandQuickPickItem({ + label: `$(sync) Show All Commits`, + description: `${Strings.pad(GlyphChars.Dash, 2, 3)} this may take a while` + }, Commands.ShowQuickFileHistory, [uri, { ...args, maxCount: 0 }]) + : undefined + }); if (pick === undefined) return undefined; if (pick instanceof CommandQuickPickItem) return pick.execute(); diff --git a/src/commands/showCommitSearch.ts b/src/commands/showCommitSearch.ts index a96bbb4..7138e60 100644 --- a/src/commands/showCommitSearch.ts +++ b/src/commands/showCommitSearch.ts @@ -6,7 +6,7 @@ import { GlyphChars } from '../constants'; import { GitRepoSearchBy, GitService, GitUri } from '../gitService'; import { Logger } from '../logger'; import { Messages } from '../messages'; -import { CommandQuickPickItem, CommitsQuickPick, ShowCommitsInResultsQuickPickItem } from '../quickPicks'; +import { CommandQuickPickItem, CommitsQuickPick, ShowCommitsSearchInResultsQuickPickItem } from '../quickPicks'; import { ShowQuickCommitDetailsCommandArgs } from './showQuickCommitDetails'; const searchByRegex = /^([@~=:#])/; @@ -21,6 +21,7 @@ const searchByMap = new Map([ export interface ShowCommitSearchCommandArgs { search?: string; searchBy?: GitRepoSearchBy; + maxCount?: number; goBackCommand?: CommandQuickPickItem; } @@ -42,6 +43,8 @@ export class ShowCommitSearchCommand extends ActiveEditorCachedCommand { if (!repoPath) return Messages.showNoRepositoryWarningMessage(`Unable to show commit search`); args = { ...args }; + const originalArgs = { ...args }; + if (!args.search || args.searchBy == null) { try { if (!args.search) { @@ -64,6 +67,8 @@ export class ShowCommitSearchCommand extends ActiveEditorCachedCommand { } as InputBoxOptions); if (args.search === undefined) return args.goBackCommand === undefined ? undefined : args.goBackCommand.execute(); + originalArgs.search = args.search; + const match = searchByRegex.exec(args.search); if (match && match[1]) { args.searchBy = searchByMap.get(match[1]); @@ -81,67 +86,54 @@ export class ShowCommitSearchCommand extends ActiveEditorCachedCommand { args.searchBy = GitRepoSearchBy.Message; } - let originalSearch: string | undefined = undefined; - let placeHolder: string | undefined = undefined; + let searchLabel: string | undefined = undefined; switch (args.searchBy) { case GitRepoSearchBy.Author: - originalSearch = `@${args.search}`; - placeHolder = `commits with an author matching '${args.search}'`; + searchLabel = `commits with an author matching '${args.search}'`; break; case GitRepoSearchBy.Changes: - originalSearch = `~${args.search}`; - placeHolder = `commits with changes matching '${args.search}'`; + searchLabel = `commits with changes matching '${args.search}'`; break; case GitRepoSearchBy.ChangesOccurrences: - originalSearch = `=${args.search}`; - placeHolder = `commits with changes (new occurrences) matching '${args.search}'`; + searchLabel = `commits with changes (new occurrences) matching '${args.search}'`; break; case GitRepoSearchBy.Files: - originalSearch = `:${args.search}`; - placeHolder = `commits with files matching '${args.search}'`; + searchLabel = `commits with files matching '${args.search}'`; break; case GitRepoSearchBy.Message: - originalSearch = args.search; - placeHolder = `commits with a message matching '${args.search}'`; + searchLabel = `commits with a message matching '${args.search}'`; break; case GitRepoSearchBy.Sha: - originalSearch = `#${args.search}`; - placeHolder = `commits with an id matching '${args.search}'`; + searchLabel = `commits with an id matching '${args.search}'`; break; } - const progressCancellation = CommitsQuickPick.showProgress(placeHolder!); + const progressCancellation = CommitsQuickPick.showProgress(searchLabel!); try { - const queryFn = ((search: string, searchBy: GitRepoSearchBy) => (maxCount: number | undefined) => this.git.getLogForRepoSearch(repoPath, search, searchBy, { maxCount: maxCount }))(args.search, args.searchBy); - const log = await queryFn(undefined); + const log = await this.git.getLogForRepoSearch(repoPath, args.search, args.searchBy, { maxCount: args.maxCount }); if (progressCancellation.token.isCancellationRequested) return undefined; - // Create a command to get back to here - const currentCommand = new CommandQuickPickItem({ - label: `go back ${GlyphChars.ArrowBack}`, - description: `${Strings.pad(GlyphChars.Dash, 2, 3)} to commit search` - }, Commands.ShowCommitSearch, [ - uri, - { - search: originalSearch, - goBackCommand: args.goBackCommand - } as ShowCommitSearchCommandArgs - ]); - - const showInResultsExplorer = log !== undefined - ? new ShowCommitsInResultsQuickPickItem(placeHolder!, log, queryFn, { - label: 'Show in Results', - description: `${Strings.pad(GlyphChars.Dash, 2, 2)} displays results in the GitLens Results view` - }) - : undefined; - - const pick = await CommitsQuickPick.show(this.git, log, placeHolder!, progressCancellation, currentCommand, showInResultsExplorer); + const pick = await CommitsQuickPick.show(this.git, log, searchLabel!, progressCancellation, { + goBackCommand: new CommandQuickPickItem({ + label: `go back ${GlyphChars.ArrowBack}`, + description: `${Strings.pad(GlyphChars.Dash, 2, 3)} to commit search` + }, Commands.ShowCommitSearch, [uri, originalArgs]), + showAllCommand: log !== undefined && log.truncated + ? new CommandQuickPickItem({ + label: `$(sync) Show All Commits`, + description: `${Strings.pad(GlyphChars.Dash, 2, 3)} this may take a while` + }, Commands.ShowCommitSearch, [uri, { ...args, maxCount: 0 }]) + : undefined, + showInResultsExplorerCommand: log !== undefined + ? new ShowCommitsSearchInResultsQuickPickItem(log, searchLabel!) + : undefined + }); if (pick === undefined) return undefined; if (pick instanceof CommandQuickPickItem) return pick.execute(); @@ -153,11 +145,8 @@ export class ShowCommitSearchCommand extends ActiveEditorCachedCommand { commit: pick.commit, goBackCommand: new CommandQuickPickItem({ label: `go back ${GlyphChars.ArrowBack}`, - description: `${Strings.pad(GlyphChars.Dash, 2, 2)} to search for ${placeHolder}` - }, Commands.ShowCommitSearch, [ - uri, - args - ]) + description: `${Strings.pad(GlyphChars.Dash, 2, 2)} to search for ${searchLabel}` + }, Commands.ShowCommitSearch, [ uri, args ]) } as ShowQuickCommitDetailsCommandArgs); } catch (ex) { diff --git a/src/commands/showQuickBranchHistory.ts b/src/commands/showQuickBranchHistory.ts index 8ac062a..ecaa268 100644 --- a/src/commands/showQuickBranchHistory.ts +++ b/src/commands/showQuickBranchHistory.ts @@ -32,9 +32,6 @@ export class ShowQuickBranchHistoryCommand extends ActiveEditorCachedCommand { const gitUri = uri && await GitUri.fromUri(uri, this.git); args = { ...args }; - if (args.maxCount == null) { - args.maxCount = this.git.config.advanced.maxQuickHistory; - } let progressCancellation = args.branch === undefined ? undefined : BranchHistoryQuickPick.showProgress(args.branch); try { diff --git a/src/commands/showQuickFileHistory.ts b/src/commands/showQuickFileHistory.ts index 8479b62..1c857ee 100644 --- a/src/commands/showQuickFileHistory.ts +++ b/src/commands/showQuickFileHistory.ts @@ -5,7 +5,7 @@ import { ActiveEditorCachedCommand, Commands, getCommandUri } from './common'; import { GlyphChars } from '../constants'; import { GitLog, GitService, GitUri } from '../gitService'; import { Logger } from '../logger'; -import { CommandQuickPickItem, FileHistoryQuickPick } from '../quickPicks'; +import { CommandQuickPickItem, FileHistoryQuickPick, ShowCommitsInResultsQuickPickItem } from '../quickPicks'; import { ShowQuickCommitFileDetailsCommandArgs } from './showQuickCommitFileDetails'; import { Messages } from '../messages'; import * as path from 'path'; @@ -34,9 +34,6 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCachedCommand { const gitUri = await GitUri.fromUri(uri, this.git); args = { ...args }; - if (args.maxCount == null) { - args.maxCount = this.git.config.advanced.maxQuickHistory; - } const progressCancellation = FileHistoryQuickPick.showProgress(gitUri); try { @@ -47,7 +44,23 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCachedCommand { if (progressCancellation.token.isCancellationRequested) return undefined; - const pick = await FileHistoryQuickPick.show(this.git, args.log, gitUri, progressCancellation, { goBackCommand: args.goBackCommand, nextPageCommand: args.nextPageCommand }); + const label = `${gitUri.getFormattedPath()}${gitUri.sha ? ` ${Strings.pad(GlyphChars.Dot, 1, 1)} ${gitUri.shortSha}` : ''}`; + const pick = await FileHistoryQuickPick.show(this.git, args.log, gitUri, label, progressCancellation, { + goBackCommand: args.goBackCommand, + nextPageCommand: args.nextPageCommand, + showAllCommand: args.log !== undefined && args.log.truncated + ? new CommandQuickPickItem({ + label: `$(sync) Show All Commits`, + description: `${Strings.pad(GlyphChars.Dash, 2, 3)} this may take a while` + }, Commands.ShowQuickFileHistory, [uri, { ...args, maxCount: 0 }]) + : undefined, + showInResultsExplorerCommand: args.log !== undefined + ? new ShowCommitsInResultsQuickPickItem(args.log, { + label: label, + resultsType: { singular: 'commit', plural: 'commits' } + }) + : undefined + }); if (pick === undefined) return undefined; if (pick instanceof CommandQuickPickItem) return pick.execute(); diff --git a/src/git/models/log.ts b/src/git/models/log.ts index de443ef..ee1d9ca 100644 --- a/src/git/models/log.ts +++ b/src/git/models/log.ts @@ -13,4 +13,6 @@ export interface GitLog { maxCount: number | undefined; range: Range; truncated: boolean; + + query: (maxCount: number | undefined) => Promise; } \ No newline at end of file diff --git a/src/gitService.ts b/src/gitService.ts index 511991b..706cd71 100644 --- a/src/gitService.ts +++ b/src/gitService.ts @@ -870,6 +870,12 @@ export class GitService extends Disposable { try { const data = await Git.log(repoPath, { maxCount: maxCount, ref: options.ref, reverse: options.reverse }); const log = GitLogParser.parse(data, GitCommitType.Branch, repoPath, undefined, options.ref, maxCount, options.reverse!, undefined); + + if (log !== undefined) { + const opts = { ...options }; + log.query = (maxCount: number | undefined) => this.getLogForRepo(repoPath, { ...opts, maxCount: maxCount }); + } + return log; } catch (ex) { @@ -910,6 +916,12 @@ export class GitService extends Disposable { try { const data = await Git.log_search(repoPath, searchArgs, { maxCount: maxCount }); const log = GitLogParser.parse(data, GitCommitType.Branch, repoPath, undefined, undefined, maxCount, false, undefined); + + if (log !== undefined) { + const opts = { ...options }; + log.query = (maxCount: number | undefined) => this.getLogForRepoSearch(repoPath, search, searchBy, { ...opts, maxCount: maxCount }); + } + return log; } catch (ex) { @@ -1000,6 +1012,12 @@ export class GitService extends Disposable { const data = await Git.log_file(root, file, { ...opts, maxCount: maxCount, startLine: range && range.start.line + 1, endLine: range && range.end.line + 1 }); const log = GitLogParser.parse(data, GitCommitType.File, root, file, opts.ref, maxCount, opts.reverse!, range); + + if (log !== undefined) { + const opts = { ...options }; + log.query = (maxCount: number | undefined) => this.getLogForFile(repoPath, fileName, { ...opts, maxCount: maxCount }); + } + return log; } catch (ex) { diff --git a/src/quickPicks/commits.ts b/src/quickPicks/commits.ts index be0a3a5..390e9f1 100644 --- a/src/quickPicks/commits.ts +++ b/src/quickPicks/commits.ts @@ -16,20 +16,24 @@ export class CommitsQuickPick { }); } - static async show(git: GitService, log: GitLog | undefined, placeHolder: string, progressCancellation: CancellationTokenSource, goBackCommand?: CommandQuickPickItem, showInResultsExplorerCommand?: CommandQuickPickItem): Promise { + static async show(git: GitService, log: GitLog | undefined, placeHolder: string, progressCancellation: CancellationTokenSource, options: { goBackCommand?: CommandQuickPickItem, showAllCommand?: CommandQuickPickItem, showInResultsExplorerCommand?: CommandQuickPickItem }): Promise { const items = ((log && [...Iterables.map(log.commits.values(), c => new CommitQuickPickItem(c))]) || [new MessageQuickPickItem('No results found')]) as (CommitQuickPickItem | CommandQuickPickItem)[]; - if (showInResultsExplorerCommand !== undefined) { - items.splice(0, 0, showInResultsExplorerCommand); + if (options.showInResultsExplorerCommand !== undefined) { + items.splice(0, 0, options.showInResultsExplorerCommand); } - if (goBackCommand !== undefined) { - items.splice(0, 0, goBackCommand); + if (options.showAllCommand !== undefined) { + items.splice(0, 0, options.showAllCommand); + } + + if (options.goBackCommand !== undefined) { + items.splice(0, 0, options.goBackCommand); } if (progressCancellation.token.isCancellationRequested) return undefined; - const scope = await Keyboard.instance.beginScope({ left: goBackCommand }); + const scope = await Keyboard.instance.beginScope({ left: options.goBackCommand }); progressCancellation.cancel(); diff --git a/src/quickPicks/common.ts b/src/quickPicks/common.ts index 4202558..ec759fd 100644 --- a/src/quickPicks/common.ts +++ b/src/quickPicks/common.ts @@ -194,16 +194,29 @@ export class CommitQuickPickItem implements QuickPickItem { export class ShowCommitsInResultsQuickPickItem extends CommandQuickPickItem { constructor( - public readonly search: string, public readonly results: GitLog, - public readonly queryFn: (maxCount: number | undefined) => Promise, - item: QuickPickItem + 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` + } ) { super(item, undefined, undefined); } async execute(options: TextDocumentShowOptions = { preserveFocus: false, preview: false }): Promise<{} | undefined> { - ResultsExplorer.instance.showCommitSearchResults(this.search, this.results, this.queryFn); + ResultsExplorer.instance.showCommitsInResults(this.results, this.resultsLabel); return undefined; } +} + +export class ShowCommitsSearchInResultsQuickPickItem extends ShowCommitsInResultsQuickPickItem { + + constructor( + public readonly results: GitLog, + public readonly search: string, + item?: QuickPickItem + ) { + super(results, { label: search }, item); + } } \ No newline at end of file diff --git a/src/quickPicks/fileHistory.ts b/src/quickPicks/fileHistory.ts index c527ef7..c220109 100644 --- a/src/quickPicks/fileHistory.ts +++ b/src/quickPicks/fileHistory.ts @@ -20,27 +20,24 @@ export class FileHistoryQuickPick { }); } - static async show(git: GitService, log: GitLog, uri: GitUri, progressCancellation: CancellationTokenSource, options: { goBackCommand?: CommandQuickPickItem, nextPageCommand?: CommandQuickPickItem, pickerOnly?: boolean } = {}): Promise { - options = { ...{ pickerOnly: false }, ...options }; + static async show(git: GitService, log: GitLog, uri: GitUri, placeHolder: string, progressCancellation: CancellationTokenSource, options: { goBackCommand?: CommandQuickPickItem, nextPageCommand?: CommandQuickPickItem, pickerOnly?: boolean, showAllCommand?: CommandQuickPickItem, showInResultsExplorerCommand?: CommandQuickPickItem } = {}): Promise { + options = { pickerOnly: false, ...options }; const items = Array.from(Iterables.map(log.commits.values(), c => new CommitQuickPickItem(c))) as (CommitQuickPickItem | CommandQuickPickItem)[]; let previousPageCommand: CommandQuickPickItem | undefined = undefined; let index = 0; + + if (options.showInResultsExplorerCommand !== undefined) { + index++; + items.splice(0, 0, options.showInResultsExplorerCommand); + } + if (log.truncated || log.sha) { - if (log.truncated) { + if (options.showAllCommand !== undefined) { index++; - items.splice(0, 0, new CommandQuickPickItem({ - label: `$(sync) Show All Commits`, - description: `${Strings.pad(GlyphChars.Dash, 2, 3)} this may take a while` - }, Commands.ShowQuickFileHistory, [ - Uri.file(uri.fsPath), - { - maxCount: 0, - goBackCommand: options.goBackCommand - } as ShowQuickFileHistoryCommandArgs - ])); + items.splice(0, 0, options.showAllCommand); } else { const workingFileName = await git.findWorkingFileName(log.repoPath, path.relative(log.repoPath, uri.fsPath)); @@ -138,12 +135,19 @@ export class FileHistoryQuickPick { const remotes = (await git.getRemotes(uri.repoPath!)).filter(r => r.provider !== undefined); if (remotes.length) { - items.splice(index++, 0, new OpenRemotesCommandQuickPickItem(remotes, { - type: 'revision', - branch: branch!.name, - fileName: uri.getRelativePath(), - sha: uri.sha - } as RemoteResource, currentCommand)); + const resource = uri.sha !== undefined + ? { + type: 'revision', + branch: branch!.name, + fileName: uri.getRelativePath(), + sha: uri.sha + } as RemoteResource + : { + type: 'file', + branch: branch!.name, + fileName: uri.getRelativePath() + } as RemoteResource; + items.splice(index++, 0, new OpenRemotesCommandQuickPickItem(remotes, resource, currentCommand)); } if (options.goBackCommand) { @@ -159,14 +163,12 @@ export class FileHistoryQuickPick { '.': options.nextPageCommand }); - const commit = Iterables.first(log.commits.values()); - progressCancellation.cancel(); const pick = await window.showQuickPick(items, { matchOnDescription: true, matchOnDetail: true, - placeHolder: `${commit.getFormattedPath()}${uri.sha ? ` ${Strings.pad(GlyphChars.Dot, 1, 1)} ${uri.shortSha}` : ''}`, + placeHolder: placeHolder, ignoreFocusOut: getQuickPickIgnoreFocusOut() // onDidSelectItem: (item: QuickPickItem) => { // scope.setKeyCommand('right', item); diff --git a/src/views/explorerCommands.ts b/src/views/explorerCommands.ts index f35d96c..7b6bad9 100644 --- a/src/views/explorerCommands.ts +++ b/src/views/explorerCommands.ts @@ -57,7 +57,7 @@ export class ExplorerCommands extends Disposable { if (this._selection === undefined || !(node instanceof ExplorerRefNode)) return; if (this._selection.repoPath !== node.repoPath) return; - ResultsExplorer.instance.showCommitComparisonResults(this._selection.repoPath, this._selection.ref, node.ref); + ResultsExplorer.instance.showComparisonInResults(this._selection.repoPath, this._selection.ref, node.ref); } private _selection: { ref: string, repoPath: string | undefined } | undefined; diff --git a/src/views/resultsExplorer.ts b/src/views/resultsExplorer.ts index b64ffa7..6bb6c9c 100644 --- a/src/views/resultsExplorer.ts +++ b/src/views/resultsExplorer.ts @@ -125,21 +125,31 @@ export class ResultsExplorer implements TreeDataProvider { this._onDidChangeTreeData.fire(); } - async showCommitComparisonResults(repoPath: string, ref1: string, ref2: string) { + async showComparisonInResults(repoPath: string, ref1: string, ref2: string) { this.addResults(new ComparisionResultsNode(repoPath, ref1, ref2, this)); setCommandContext(CommandContext.ResultsExplorer, true); } - showCommitSearchResults(search: string, results: GitLog, queryFn: (maxCount: number | undefined) => Promise) { + showCommitsInResults(results: GitLog, resultsLabel: string | { label: string, resultsType?: { singular: string, plural: string } }) { + const query = results.query === undefined + ? (maxCount: number | undefined) => Promise.resolve(results) + : results.query; + const labelFn = (log: GitLog | undefined) => { + if (typeof resultsLabel === 'string') return resultsLabel; + const count = log !== undefined ? log.count : 0; const truncated = log !== undefined ? log.truncated : false; - if (count === 1) return `1 result for ${search}`; - return `${count === 0 ? 'No' : `${count}${truncated ? '+' : ''}`} results for ${search}`; + const resultsType = resultsLabel.resultsType === undefined + ? { singular: 'result', plural: 'results' } + : resultsLabel.resultsType; + + if (count === 1) return `1 ${resultsType.singular} for ${resultsLabel.label}`; + return `${count === 0 ? 'No' : `${count}${truncated ? '+' : ''}`} ${resultsType.plural} for ${resultsLabel.label}`; }; - this.addResults(new CommitsResultsNode(results.repoPath, labelFn, Functions.seeded(queryFn, results), this, ResourceType.SearchResults)); + this.addResults(new CommitsResultsNode(results.repoPath, labelFn, Functions.seeded(query, results), this, ResourceType.SearchResults)); setCommandContext(CommandContext.ResultsExplorer, true); } @@ -167,6 +177,9 @@ export class ResultsExplorer implements TreeDataProvider { if (index === -1) return; this._roots.splice(index, 1); + + node.dispose(); + this.refresh(); }