Browse Source

Adds SearchPattern type

main
Eric Amodio 5 years ago
parent
commit
ab006510a0
6 changed files with 39 additions and 40 deletions
  1. +11
    -3
      src/commands/git/search.ts
  2. +3
    -10
      src/commands/searchCommits.ts
  3. +18
    -6
      src/git/gitService.ts
  4. +2
    -2
      src/quickpicks/commonQuickPicks.ts
  5. +2
    -6
      src/views/nodes/searchResultsCommitsNode.ts
  6. +3
    -13
      src/views/searchView.ts

+ 11
- 3
src/commands/git/search.ts View File

@ -2,7 +2,15 @@
/* eslint-disable no-loop-func */ /* eslint-disable no-loop-func */
import { QuickInputButton } from 'vscode'; import { QuickInputButton } from 'vscode';
import { Container } from '../../container'; 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 { GlyphChars } from '../../constants';
import { QuickCommandBase, StepAsyncGenerator, StepSelection, StepState } from '../quickCommand'; import { QuickCommandBase, StepAsyncGenerator, StepSelection, StepState } from '../quickCommand';
import { RepositoryQuickPickItem } from '../../quickpicks'; import { RepositoryQuickPickItem } from '../../quickpicks';
@ -376,13 +384,13 @@ export class SearchGitCommand extends QuickCommandBase {
state.search = selection[0].item.trim(); state.search = selection[0].item.trim();
} }
const search = {
const search: SearchPattern = {
pattern: state.search, pattern: state.search,
matchAll: state.matchAll, matchAll: state.matchAll,
matchCase: state.matchCase, matchCase: state.matchCase,
matchRegex: state.matchRegex matchRegex: state.matchRegex
}; };
const searchKey = JSON.stringify(search);
const searchKey = SearchPattern.toKey(search);
if (resultsPromise === undefined || resultsKey !== searchKey) { if (resultsPromise === undefined || resultsKey !== searchKey) {
resultsPromise = Container.git.getLogForSearch(state.repo.path, search); resultsPromise = Container.git.getLogForSearch(state.repo.path, search);

+ 3
- 10
src/commands/searchCommits.ts View File

@ -4,14 +4,10 @@ import { SearchResultsCommitsNode } from '../views/nodes';
import { Container } from '../container'; import { Container } from '../container';
import { Command, command, CommandContext, Commands, isCommandViewContextWithRepo } from './common'; import { Command, command, CommandContext, Commands, isCommandViewContextWithRepo } from './common';
import { GitCommandsCommandArgs } from '../commands'; import { GitCommandsCommandArgs } from '../commands';
import { SearchPattern } from '../git/gitService';
export interface SearchCommitsCommandArgs { export interface SearchCommitsCommandArgs {
search?: {
pattern?: string;
matchAll?: boolean;
matchCase?: boolean;
matchRegex?: boolean;
};
search?: Partial<SearchPattern>;
repoPath?: string; repoPath?: string;
prefillOnly?: boolean; prefillOnly?: boolean;
@ -60,10 +56,7 @@ export class SearchCommitsCommand extends Command {
prefillOnly: args.prefillOnly, prefillOnly: args.prefillOnly,
state: { state: {
repo: repo, 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 showInView: args.showInView
} }
}; };

+ 18
- 6
src/git/gitService.ts View File

@ -106,6 +106,7 @@ export type SearchOperators =
| 'file:' | 'file:'
| '~:' | '~:'
| 'change:'; | 'change:';
export const searchOperators = new Set<string>([ export const searchOperators = new Set<string>([
'', '',
'=:', '=:',
@ -119,6 +120,22 @@ export const searchOperators = new Set([
'~:', '~:',
'change:' '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<SearchOperators, SearchOperators>([ const normalizeSearchOperatorsMap = new Map<SearchOperators, SearchOperators>([
['', 'message:'], ['', 'message:'],
['=:', 'message:'], ['=:', 'message:'],
@ -1464,12 +1481,7 @@ export class GitService implements Disposable {
@log() @log()
async getLogForSearch( async getLogForSearch(
repoPath: string, repoPath: string,
search: {
pattern: string;
matchAll?: boolean;
matchCase?: boolean;
matchRegex?: boolean;
},
search: SearchPattern,
options: { maxCount?: number } = {} options: { maxCount?: number } = {}
): Promise<GitLog | undefined> { ): Promise<GitLog | undefined> {
search = { matchAll: false, matchCase: false, matchRegex: true, ...search }; search = { matchAll: false, matchCase: false, matchRegex: true, ...search };

+ 2
- 2
src/quickpicks/commonQuickPicks.ts View File

@ -3,7 +3,7 @@ import { CancellationTokenSource, commands, QuickPickItem, window } from 'vscode
import { Commands } from '../commands'; import { Commands } from '../commands';
import { configuration } from '../configuration'; import { configuration } from '../configuration';
import { Container } from '../container'; 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 { KeyMapping, Keys } from '../keyboard';
import { ReferencesQuickPick, ReferencesQuickPickItem } from './referencesQuickPick'; import { ReferencesQuickPick, ReferencesQuickPickItem } from './referencesQuickPick';
@ -121,7 +121,7 @@ export class ShowCommitInViewQuickPickItem extends CommandQuickPickItem {
export class ShowCommitSearchResultsInViewQuickPickItem extends CommandQuickPickItem { export class ShowCommitSearchResultsInViewQuickPickItem extends CommandQuickPickItem {
constructor( constructor(
public readonly search: { pattern: string; matchAll?: boolean; matchCase?: boolean; matchRegex?: boolean },
public readonly search: SearchPattern,
public readonly results: GitLog, public readonly results: GitLog,
public readonly resultsLabel: string | { label: string; resultsType?: { singular: string; plural: string } }, public readonly resultsLabel: string | { label: string; resultsType?: { singular: string; plural: string } },
item: QuickPickItem = { item: QuickPickItem = {

+ 2
- 6
src/views/nodes/searchResultsCommitsNode.ts View File

@ -5,6 +5,7 @@ import { Commands } from '../../commands/common';
import { ViewWithFiles } from '../viewBase'; import { ViewWithFiles } from '../viewBase';
import { CommitsQueryResults, ResultsCommitsNode } from './resultsCommitsNode'; import { CommitsQueryResults, ResultsCommitsNode } from './resultsCommitsNode';
import { ResourceType, ViewNode } from './viewNode'; import { ResourceType, ViewNode } from './viewNode';
import { SearchPattern } from '../../git/gitService';
let instanceId = 0; let instanceId = 0;
@ -15,12 +16,7 @@ export class SearchResultsCommitsNode extends ResultsCommitsNode {
view: ViewWithFiles, view: ViewWithFiles,
parent: ViewNode, parent: ViewNode,
repoPath: string, repoPath: string,
public readonly search: {
pattern: string;
matchAll?: boolean;
matchCase?: boolean;
matchRegex?: boolean;
},
public readonly search: SearchPattern,
label: string, label: string,
commitsQuery: (maxCount: number | undefined) => Promise<CommitsQueryResults> commitsQuery: (maxCount: number | undefined) => Promise<CommitsQueryResults>
) { ) {

+ 3
- 13
src/views/searchView.ts View File

@ -3,7 +3,7 @@ import { commands, ConfigurationChangeEvent } from 'vscode';
import { configuration, SearchViewConfig, ViewFilesLayout, ViewsConfig } from '../configuration'; import { configuration, SearchViewConfig, ViewFilesLayout, ViewsConfig } from '../configuration';
import { CommandContext, setCommandContext, WorkspaceState } from '../constants'; import { CommandContext, setCommandContext, WorkspaceState } from '../constants';
import { Container } from '../container'; import { Container } from '../container';
import { GitLog } from '../git/gitService';
import { GitLog, SearchPattern } from '../git/gitService';
import { Functions, Strings } from '../system'; import { Functions, Strings } from '../system';
import { nodeSupportsConditionalDismissal, SearchNode, SearchResultsCommitsNode, ViewNode } from './nodes'; import { nodeSupportsConditionalDismissal, SearchNode, SearchResultsCommitsNode, ViewNode } from './nodes';
import { ViewBase } from './viewBase'; import { ViewBase } from './viewBase';
@ -105,12 +105,7 @@ export class SearchView extends ViewBase {
async search( async search(
repoPath: string, repoPath: string,
search: {
pattern: string;
matchAll?: boolean;
matchCase?: boolean;
matchRegex?: boolean;
},
search: SearchPattern,
{ {
label, label,
...options ...options
@ -146,12 +141,7 @@ export class SearchView extends ViewBase {
showSearchResults( showSearchResults(
repoPath: string, repoPath: string,
search: {
pattern: string;
matchAll?: boolean;
matchCase?: boolean;
matchRegex?: boolean;
},
search: SearchPattern,
results: GitLog, results: GitLog,
{ {
label, label,

Loading…
Cancel
Save