Skip to content

Commit ac7c727

Browse files
committed
Splits search constants into new constants file
1 parent 8a52ce2 commit ac7c727

File tree

17 files changed

+74
-71
lines changed

17 files changed

+74
-71
lines changed

src/commands/git/search.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import type { QuickInputButton, QuickPick } from 'vscode';
22
import { ThemeIcon, window } from 'vscode';
33
import { GlyphChars } from '../../constants';
4+
import type { NormalizedSearchOperators, SearchOperators, SearchQuery } from '../../constants.search';
5+
import { searchOperators } from '../../constants.search';
46
import type { Container } from '../../container';
57
import { showDetailsView } from '../../git/actions/commit';
68
import type { GitCommit } from '../../git/models/commit';
79
import type { GitLog } from '../../git/models/log';
810
import type { Repository } from '../../git/models/repository';
9-
import type { NormalizedSearchOperators, SearchOperators, SearchQuery } from '../../git/search';
10-
import { getSearchQueryComparisonKey, parseSearchQuery, searchOperators } from '../../git/search';
11+
import { getSearchQueryComparisonKey, parseSearchQuery } from '../../git/search';
1112
import { showContributorsPicker } from '../../quickpicks/contributorsPicker';
1213
import type { QuickPickItemOfT } from '../../quickpicks/items/common';
1314
import { ActionQuickPickItem } from '../../quickpicks/items/common';

src/commands/searchCommits.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Commands } from '../constants.commands';
2+
import type { SearchQuery } from '../constants.search';
23
import type { Container } from '../container';
34
import { executeGitCommand } from '../git/actions';
4-
import type { SearchQuery } from '../git/search';
55
import { command } from '../system/command';
66
import { configuration } from '../system/configuration';
77
import { SearchResultsNode } from '../views/nodes/searchResultsNode';

src/constants.search.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
export type NormalizedSearchOperators = 'message:' | 'author:' | 'commit:' | 'file:' | 'change:' | 'type:';
2+
export type SearchOperators = NormalizedSearchOperators | '' | '=:' | '@:' | '#:' | '?:' | '~:';
3+
4+
export const searchOperators = new Set<string>([
5+
'',
6+
'=:',
7+
'message:',
8+
'@:',
9+
'author:',
10+
'#:',
11+
'commit:',
12+
'?:',
13+
'file:',
14+
'~:',
15+
'change:',
16+
'type:',
17+
]);
18+
19+
export const normalizeSearchOperatorsMap = new Map<SearchOperators, NormalizedSearchOperators>([
20+
['', 'message:'],
21+
['=:', 'message:'],
22+
['message:', 'message:'],
23+
['@:', 'author:'],
24+
['author:', 'author:'],
25+
['#:', 'commit:'],
26+
['commit:', 'commit:'],
27+
['?:', 'file:'],
28+
['file:', 'file:'],
29+
['~:', 'change:'],
30+
['change:', 'change:'],
31+
['type:', 'type:'],
32+
]);
33+
34+
export const searchOperationRegex =
35+
/(?:(?<op>=:|message:|@:|author:|#:|commit:|\?:|file:|~:|change:|type:)\s?(?<value>".+?"|\S+}?))|(?<text>\S+)(?!(?:=|message|@|author|#|commit|\?|file|~|change|type):)/g;
36+
37+
export interface SearchQuery {
38+
query: string;
39+
matchAll?: boolean;
40+
matchCase?: boolean;
41+
matchRegex?: boolean;
42+
}

src/constants.storage.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { GraphBranchesVisibility, ViewShowBranchComparison } from './config';
22
import type { AIProviders } from './constants.ai';
33
import type { Environment } from './container';
4-
import type { StoredSearchQuery } from './git/search';
54
import type { Subscription } from './plus/gk/account/subscription';
65
import type { Integration } from './plus/integrations/integration';
76
import type { IntegrationId } from './plus/integrations/providers/models';
@@ -271,6 +270,13 @@ export interface StoredSearch {
271270
search: StoredSearchQuery;
272271
}
273272

273+
export interface StoredSearchQuery {
274+
pattern: string;
275+
matchAll?: boolean;
276+
matchCase?: boolean;
277+
matchRegex?: boolean;
278+
}
279+
274280
export type StoredSearchAndCompareItem = StoredComparison | StoredSearch;
275281
export type StoredSearchAndCompareItems = Record<string, StoredSearchAndCompareItem>;
276282
export type StoredStarred = Record<string, boolean>;

src/env/node/git/localGitProvider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type { GitExtension, API as ScmGitApi } from '../../../@types/vscode.git'
1212
import { getCachedAvatarUri } from '../../../avatars';
1313
import type { GitConfigKeys } from '../../../constants';
1414
import { GlyphChars, Schemes } from '../../../constants';
15+
import type { SearchQuery } from '../../../constants.search';
1516
import type { Container } from '../../../container';
1617
import { emojify } from '../../../emojis';
1718
import { CancellationError } from '../../../errors';
@@ -159,7 +160,7 @@ import { parseGitTags } from '../../../git/parsers/tagParser';
159160
import { parseGitLsFiles, parseGitTree } from '../../../git/parsers/treeParser';
160161
import { parseGitWorktrees } from '../../../git/parsers/worktreeParser';
161162
import { getRemoteProviderMatcher, loadRemoteProviders } from '../../../git/remotes/remoteProviders';
162-
import type { GitSearch, GitSearchResultData, GitSearchResults, SearchQuery } from '../../../git/search';
163+
import type { GitSearch, GitSearchResultData, GitSearchResults } from '../../../git/search';
163164
import { getGitArgsFromSearchQuery, getSearchQueryComparisonKey } from '../../../git/search';
164165
import {
165166
showBlameInvalidIgnoreRevsFileWarningMessage,

src/git/gitProvider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { CancellationToken, Disposable, Event, Range, TextDocument, Uri, Wo
22
import type { Commit, InputBox } from '../@types/vscode.git';
33
import type { ForcePushMode } from '../@types/vscode.git.enums';
44
import type { GitConfigKeys } from '../constants';
5+
import type { SearchQuery } from '../constants.search';
56
import type { Features } from '../features';
67
import type { GitUri } from './gitUri';
78
import type { GitBlame, GitBlameLine, GitBlameLines } from './models/blame';
@@ -24,7 +25,7 @@ import type { GitTag, TagSortOptions } from './models/tag';
2425
import type { GitTreeEntry } from './models/tree';
2526
import type { GitUser } from './models/user';
2627
import type { GitWorktree } from './models/worktree';
27-
import type { GitSearch, SearchQuery } from './search';
28+
import type { GitSearch } from './search';
2829

2930
export type GitCaches =
3031
| 'branches'

src/git/gitProviderService.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { isWeb } from '@env/platform';
1414
import { resetAvatarCache } from '../avatars';
1515
import type { GitConfigKeys } from '../constants';
1616
import { GlyphChars, Schemes } from '../constants';
17+
import type { SearchQuery } from '../constants.search';
1718
import type { Container } from '../container';
1819
import { AccessDeniedError, CancellationError, ProviderNotFoundError } from '../errors';
1920
import type { FeatureAccess, Features, PlusFeatures, RepoFeatureAccess } from '../features';
@@ -81,7 +82,7 @@ import type { GitTreeEntry } from './models/tree';
8182
import type { GitUser } from './models/user';
8283
import type { GitWorktree } from './models/worktree';
8384
import type { RemoteProvider } from './remotes/remoteProvider';
84-
import type { GitSearch, SearchQuery } from './search';
85+
import type { GitSearch } from './search';
8586

8687
const emptyArray = Object.freeze([]) as unknown as any[];
8788
const emptyDisposable = Object.freeze({

src/git/models/repository.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { md5, uuid } from '@env/crypto';
44
import type { CreatePullRequestActionContext } from '../../api/gitlens';
55
import type { RepositoriesSorting } from '../../config';
66
import { Schemes } from '../../constants';
7+
import type { SearchQuery } from '../../constants.search';
78
import type { Container } from '../../container';
89
import type { FeatureAccess, Features, PlusFeatures } from '../../features';
910
import { showCreatePullRequestPrompt, showGenericErrorMessage } from '../../messages';
@@ -25,7 +26,7 @@ import { basename, normalizePath } from '../../system/path';
2526
import { sortCompare } from '../../system/string';
2627
import type { GitDir, GitProviderDescriptor, GitRepositoryCaches, PagingOptions } from '../gitProvider';
2728
import type { RemoteProvider } from '../remotes/remoteProvider';
28-
import type { GitSearch, SearchQuery } from '../search';
29+
import type { GitSearch } from '../search';
2930
import type { BranchSortOptions, GitBranch } from './branch';
3031
import { getBranchNameWithoutRemote, getRemoteNameFromBranchName } from './branch';
3132
import type { GitCommit } from './commit';

src/git/search.ts

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,10 @@
1+
import type { NormalizedSearchOperators, SearchOperators, SearchQuery } from '../constants.search';
2+
import { normalizeSearchOperatorsMap, searchOperationRegex } from '../constants.search';
3+
import type { StoredSearchQuery } from '../constants.storage';
14
import type { GitRevisionReference } from './models/reference';
25
import { isSha, shortenRevision } from './models/reference';
36
import type { GitUser } from './models/user';
47

5-
export type NormalizedSearchOperators = 'message:' | 'author:' | 'commit:' | 'file:' | 'change:';
6-
export type SearchOperators = NormalizedSearchOperators | '' | '=:' | '@:' | '#:' | '?:' | '~:';
7-
8-
export const searchOperators = new Set<string>([
9-
'',
10-
'=:',
11-
'message:',
12-
'@:',
13-
'author:',
14-
'#:',
15-
'commit:',
16-
'?:',
17-
'file:',
18-
'~:',
19-
'change:',
20-
]);
21-
22-
export interface SearchQuery {
23-
query: string;
24-
matchAll?: boolean;
25-
matchCase?: boolean;
26-
matchRegex?: boolean;
27-
}
28-
29-
// Don't change this shape as it is persisted in storage
30-
export interface StoredSearchQuery {
31-
pattern: string;
32-
matchAll?: boolean;
33-
matchCase?: boolean;
34-
matchRegex?: boolean;
35-
}
36-
378
export interface GitSearchResultData {
389
date: number;
3910
i: number;
@@ -90,23 +61,6 @@ export function createSearchQueryForCommits(refsOrCommits: (string | GitRevision
9061
return refsOrCommits.map(r => `#:${typeof r === 'string' ? shortenRevision(r) : r.name}`).join(' ');
9162
}
9263

93-
const normalizeSearchOperatorsMap = new Map<SearchOperators, NormalizedSearchOperators>([
94-
['', 'message:'],
95-
['=:', 'message:'],
96-
['message:', 'message:'],
97-
['@:', 'author:'],
98-
['author:', 'author:'],
99-
['#:', 'commit:'],
100-
['commit:', 'commit:'],
101-
['?:', 'file:'],
102-
['file:', 'file:'],
103-
['~:', 'change:'],
104-
['change:', 'change:'],
105-
]);
106-
107-
const searchOperationRegex =
108-
/(?:(?<op>=:|message:|@:|author:|#:|commit:|\?:|file:|~:|change:)\s?(?<value>".+?"|\S+}?))|(?<text>\S+)(?!(?:=|message|@|author|#|commit|\?|file|~|change):)/g;
109-
11064
export function parseSearchQuery(search: SearchQuery): Map<NormalizedSearchOperators, Set<string>> {
11165
const operations = new Map<NormalizedSearchOperators, Set<string>>();
11266

src/plus/integrations/providers/github/githubGitProvider.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { EventEmitter, FileType, Uri, window, workspace } from 'vscode';
1212
import { encodeUtf8Hex } from '@env/hex';
1313
import { isWeb } from '@env/platform';
1414
import { CharCode, Schemes } from '../../../../constants';
15+
import type { SearchOperators, SearchQuery } from '../../../../constants.search';
1516
import type { Container } from '../../../../container';
1617
import { emojify } from '../../../../emojis';
1718
import {
@@ -84,13 +85,7 @@ import type { GitTreeEntry } from '../../../../git/models/tree';
8485
import type { GitUser } from '../../../../git/models/user';
8586
import { isUserMatch } from '../../../../git/models/user';
8687
import { getRemoteProviderMatcher, loadRemoteProviders } from '../../../../git/remotes/remoteProviders';
87-
import type {
88-
GitSearch,
89-
GitSearchResultData,
90-
GitSearchResults,
91-
SearchOperators,
92-
SearchQuery,
93-
} from '../../../../git/search';
88+
import type { GitSearch, GitSearchResultData, GitSearchResults } from '../../../../git/search';
9489
import { getSearchQueryComparisonKey, parseSearchQuery } from '../../../../git/search';
9590
import { configuration } from '../../../../system/configuration';
9691
import { setContext } from '../../../../system/context';

src/plus/webviews/graph/protocol.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import type {
2323
WorkDirStats,
2424
} from '@gitkraken/gitkraken-components';
2525
import type { Config, DateStyle, GraphBranchesVisibility } from '../../../config';
26+
import type { SearchQuery } from '../../../constants.search';
2627
import type { RepositoryVisibility } from '../../../git/gitProvider';
2728
import type { GitTrackingState } from '../../../git/models/branch';
2829
import type { GitGraphRowType } from '../../../git/models/graph';
@@ -35,7 +36,7 @@ import type {
3536
GitTagReference,
3637
} from '../../../git/models/reference';
3738
import type { ProviderReference } from '../../../git/models/remoteProvider';
38-
import type { GitSearchResultData, SearchQuery } from '../../../git/search';
39+
import type { GitSearchResultData } from '../../../git/search';
3940
import type { DateTimeFormat } from '../../../system/date';
4041
import type { WebviewItemContext, WebviewItemGroupContext } from '../../../system/webview';
4142
import type { IpcScope, WebviewState } from '../../../webviews/protocol';

src/views/nodes/searchResultsNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type { TreeItem } from 'vscode';
22
import { ThemeIcon } from 'vscode';
33
import { md5 } from '@env/crypto';
4+
import type { SearchQuery } from '../../constants.search';
45
import { executeGitCommand } from '../../git/actions';
56
import { GitUri } from '../../git/gitUri';
67
import type { GitLog } from '../../git/models/log';
78
import type { CommitsQueryResults } from '../../git/queryResults';
8-
import type { SearchQuery } from '../../git/search';
99
import { getSearchQueryComparisonKey, getStoredSearchQuery } from '../../git/search';
1010
import { gate } from '../../system/decorators/gate';
1111
import { debug } from '../../system/decorators/log';

src/views/searchAndCompareView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import type { ConfigurationChangeEvent, Disposable } from 'vscode';
22
import { TreeItem, TreeItemCollapsibleState } from 'vscode';
33
import type { SearchAndCompareViewConfig, ViewFilesLayout } from '../config';
44
import { Commands } from '../constants.commands';
5+
import type { SearchQuery } from '../constants.search';
56
import type { StoredNamedRef, StoredSearchAndCompareItem } from '../constants.storage';
67
import type { Container } from '../container';
78
import { unknownGitUri } from '../git/gitUri';
89
import type { GitLog } from '../git/models/log';
910
import { getRevisionRangeParts, isRevisionRange, shortenRevision } from '../git/models/reference';
10-
import type { SearchQuery } from '../git/search';
1111
import { getSearchQuery } from '../git/search';
1212
import { ReferencesQuickPickIncludes, showReferencePicker } from '../quickpicks/referencePicker';
1313
import { getRepositoryOrShowPicker } from '../quickpicks/repositoryPicker';

src/webviews/apps/plus/graph/GraphWrapper.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import type { FormEvent, MouseEvent, ReactElement } from 'react';
2020
import React, { createElement, useEffect, useMemo, useRef, useState } from 'react';
2121
import { getPlatform } from '@env/platform';
2222
import type { DateStyle, GraphBranchesVisibility } from '../../../../config';
23-
import type { SearchQuery } from '../../../../git/search';
23+
import type { SearchQuery } from '../../../../constants.search';
2424
import type { FocusCommandArgs } from '../../../../plus/focus/focus';
2525
import type { Subscription } from '../../../../plus/gk/account/subscription';
2626
import { isSubscriptionPaid } from '../../../../plus/gk/account/subscription';

src/webviews/apps/plus/graph/graph.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import type { CssVariables, GraphRef, GraphRefOptData, GraphRow } from '@gitkrak
33
import React from 'react';
44
import { render, unmountComponentAtNode } from 'react-dom';
55
import type { GraphBranchesVisibility } from '../../../../config';
6+
import type { SearchQuery } from '../../../../constants.search';
67
import type { GitGraphRowType } from '../../../../git/models/graph';
7-
import type { SearchQuery } from '../../../../git/search';
88
import type {
99
DidSearchParams,
1010
GraphAvatars,

src/webviews/apps/shared/components/search/search-box.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { css, html } from 'lit';
33
import { customElement, property, query } from 'lit/decorators.js';
44
import type { Disposable } from 'vscode';
55
import { isMac } from '@env/platform';
6-
import type { SearchQuery } from '../../../../../git/search';
6+
import type { SearchQuery } from '../../../../../constants.search';
77
import { pluralize } from '../../../../../system/string';
88
import { DOM } from '../../dom';
99
import { GlElement } from '../element';

src/webviews/apps/shared/components/search/search-input.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { css, html } from 'lit';
22
import { customElement, property, query, state } from 'lit/decorators.js';
3-
import type { SearchQuery } from '../../../../../git/search';
3+
import type { SearchQuery } from '../../../../../constants.search';
44
import type { Deferrable } from '../../../../../system/function';
55
import { debounce } from '../../../../../system/function';
66
import { GlElement } from '../element';

0 commit comments

Comments
 (0)