diff --git a/src/commands/git/search.ts b/src/commands/git/search.ts index d8db71e..b6fcb0b 100644 --- a/src/commands/git/search.ts +++ b/src/commands/git/search.ts @@ -2,7 +2,15 @@ /* eslint-disable no-loop-func */ import { QuickInputButton } from 'vscode'; import { Container } from '../../container'; -import { GitLog, GitLogCommit, GitService, Repository, searchOperators, SearchOperators } from '../../git/gitService'; +import { + GitLog, + GitLogCommit, + GitService, + Repository, + searchOperators, + SearchOperators, + SearchPattern +} from '../../git/gitService'; import { GlyphChars } from '../../constants'; import { QuickCommandBase, StepAsyncGenerator, StepSelection, StepState } from '../quickCommand'; import { RepositoryQuickPickItem } from '../../quickpicks'; @@ -376,13 +384,13 @@ export class SearchGitCommand extends QuickCommandBase { state.search = selection[0].item.trim(); } - const search = { + const search: SearchPattern = { pattern: state.search, matchAll: state.matchAll, matchCase: state.matchCase, matchRegex: state.matchRegex }; - const searchKey = JSON.stringify(search); + const searchKey = SearchPattern.toKey(search); if (resultsPromise === undefined || resultsKey !== searchKey) { resultsPromise = Container.git.getLogForSearch(state.repo.path, search); diff --git a/src/commands/searchCommits.ts b/src/commands/searchCommits.ts index 904d316..201fa58 100644 --- a/src/commands/searchCommits.ts +++ b/src/commands/searchCommits.ts @@ -4,14 +4,10 @@ import { SearchResultsCommitsNode } from '../views/nodes'; import { Container } from '../container'; import { Command, command, CommandContext, Commands, isCommandViewContextWithRepo } from './common'; import { GitCommandsCommandArgs } from '../commands'; +import { SearchPattern } from '../git/gitService'; export interface SearchCommitsCommandArgs { - search?: { - pattern?: string; - matchAll?: boolean; - matchCase?: boolean; - matchRegex?: boolean; - }; + search?: Partial; repoPath?: string; prefillOnly?: boolean; @@ -60,10 +56,7 @@ export class SearchCommitsCommand extends Command { prefillOnly: args.prefillOnly, state: { repo: repo, - search: args.search && args.search.pattern, - matchAll: args.search && args.search.matchAll, - matchCase: args.search && args.search.matchCase, - matchRegex: args.search && args.search.matchRegex, + ...args.search, showInView: args.showInView } }; diff --git a/src/git/gitService.ts b/src/git/gitService.ts index bc0cbac..209d302 100644 --- a/src/git/gitService.ts +++ b/src/git/gitService.ts @@ -106,6 +106,7 @@ export type SearchOperators = | 'file:' | '~:' | 'change:'; + export const searchOperators = new Set([ '', '=:', @@ -119,6 +120,22 @@ export const searchOperators = new Set([ '~:', 'change:' ]); + +export interface SearchPattern { + pattern: string; + matchAll?: boolean; + matchCase?: boolean; + matchRegex?: boolean; +} + +export namespace SearchPattern { + export function toKey(search: SearchPattern) { + return `${search.pattern}|${search.matchAll ? 'A' : ''}${search.matchCase ? 'C' : ''}${ + search.matchRegex ? 'R' : '' + }`; + } +} + const normalizeSearchOperatorsMap = new Map([ ['', 'message:'], ['=:', 'message:'], @@ -1464,12 +1481,7 @@ export class GitService implements Disposable { @log() async getLogForSearch( repoPath: string, - search: { - pattern: string; - matchAll?: boolean; - matchCase?: boolean; - matchRegex?: boolean; - }, + search: SearchPattern, options: { maxCount?: number } = {} ): Promise { search = { matchAll: false, matchCase: false, matchRegex: true, ...search }; diff --git a/src/quickpicks/commonQuickPicks.ts b/src/quickpicks/commonQuickPicks.ts index 0f17d06..c93bf01 100644 --- a/src/quickpicks/commonQuickPicks.ts +++ b/src/quickpicks/commonQuickPicks.ts @@ -3,7 +3,7 @@ import { CancellationTokenSource, commands, QuickPickItem, window } from 'vscode import { Commands } from '../commands'; import { configuration } from '../configuration'; import { Container } from '../container'; -import { GitLog, GitLogCommit, GitUri } from '../git/gitService'; +import { GitLog, GitLogCommit, GitUri, SearchPattern } from '../git/gitService'; import { KeyMapping, Keys } from '../keyboard'; import { ReferencesQuickPick, ReferencesQuickPickItem } from './referencesQuickPick'; @@ -121,7 +121,7 @@ export class ShowCommitInViewQuickPickItem extends CommandQuickPickItem { export class ShowCommitSearchResultsInViewQuickPickItem extends CommandQuickPickItem { constructor( - public readonly search: { pattern: string; matchAll?: boolean; matchCase?: boolean; matchRegex?: boolean }, + public readonly search: SearchPattern, public readonly results: GitLog, public readonly resultsLabel: string | { label: string; resultsType?: { singular: string; plural: string } }, item: QuickPickItem = { diff --git a/src/views/nodes/searchResultsCommitsNode.ts b/src/views/nodes/searchResultsCommitsNode.ts index e068675..c764ab5 100644 --- a/src/views/nodes/searchResultsCommitsNode.ts +++ b/src/views/nodes/searchResultsCommitsNode.ts @@ -5,6 +5,7 @@ import { Commands } from '../../commands/common'; import { ViewWithFiles } from '../viewBase'; import { CommitsQueryResults, ResultsCommitsNode } from './resultsCommitsNode'; import { ResourceType, ViewNode } from './viewNode'; +import { SearchPattern } from '../../git/gitService'; let instanceId = 0; @@ -15,12 +16,7 @@ export class SearchResultsCommitsNode extends ResultsCommitsNode { view: ViewWithFiles, parent: ViewNode, repoPath: string, - public readonly search: { - pattern: string; - matchAll?: boolean; - matchCase?: boolean; - matchRegex?: boolean; - }, + public readonly search: SearchPattern, label: string, commitsQuery: (maxCount: number | undefined) => Promise ) { diff --git a/src/views/searchView.ts b/src/views/searchView.ts index 2b20ce0..96c4f25 100644 --- a/src/views/searchView.ts +++ b/src/views/searchView.ts @@ -3,7 +3,7 @@ import { commands, ConfigurationChangeEvent } from 'vscode'; import { configuration, SearchViewConfig, ViewFilesLayout, ViewsConfig } from '../configuration'; import { CommandContext, setCommandContext, WorkspaceState } from '../constants'; import { Container } from '../container'; -import { GitLog } from '../git/gitService'; +import { GitLog, SearchPattern } from '../git/gitService'; import { Functions, Strings } from '../system'; import { nodeSupportsConditionalDismissal, SearchNode, SearchResultsCommitsNode, ViewNode } from './nodes'; import { ViewBase } from './viewBase'; @@ -105,12 +105,7 @@ export class SearchView extends ViewBase { async search( repoPath: string, - search: { - pattern: string; - matchAll?: boolean; - matchCase?: boolean; - matchRegex?: boolean; - }, + search: SearchPattern, { label, ...options @@ -146,12 +141,7 @@ export class SearchView extends ViewBase { showSearchResults( repoPath: string, - search: { - pattern: string; - matchAll?: boolean; - matchCase?: boolean; - matchRegex?: boolean; - }, + search: SearchPattern, results: GitLog, { label,