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 */
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);

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

@ -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<SearchPattern>;
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
}
};

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

@ -106,6 +106,7 @@ export type SearchOperators =
| 'file:'
| '~:'
| 'change:';
export const searchOperators = new Set<string>([
'',
'=:',
@ -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<SearchOperators, SearchOperators>([
['', '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<GitLog | undefined> {
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 { 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 = {

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

@ -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<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 { 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,

Loading…
Cancel
Save