|
| 1 | +import { Suggestion, SuggestionMode } from "./searchSuggestionsBox"; |
| 2 | + |
| 3 | +/** |
| 4 | + * List of search prefixes that can be used while the |
| 5 | + * `refine` suggestion mode is active. |
| 6 | + */ |
| 7 | +enum SearchPrefix { |
| 8 | + repo = "repo:", |
| 9 | + r = "r:", |
| 10 | + lang = "lang:", |
| 11 | + file = "file:", |
| 12 | + rev = "rev:", |
| 13 | + revision = "revision:", |
| 14 | + b = "b:", |
| 15 | + branch = "branch:", |
| 16 | + sym = "sym:", |
| 17 | + content = "content:", |
| 18 | + archived = "archived:", |
| 19 | + case = "case:", |
| 20 | + fork = "fork:", |
| 21 | + public = "public:" |
| 22 | +} |
| 23 | + |
| 24 | +const negate = (prefix: SearchPrefix) => { |
| 25 | + return `-${prefix}`; |
| 26 | +} |
| 27 | + |
| 28 | +type SuggestionModeMapping = { |
| 29 | + suggestionMode: SuggestionMode, |
| 30 | + prefixes: string[], |
| 31 | +} |
| 32 | + |
| 33 | +/** |
| 34 | + * Maps search prefixes to a suggestion mode. When a query starts |
| 35 | + * with a prefix, the corresponding suggestion mode is enabled. |
| 36 | + * @see [searchSuggestionsBox.tsx](./searchSuggestionsBox.tsx) |
| 37 | + */ |
| 38 | +export const suggestionModeMappings: SuggestionModeMapping[] = [ |
| 39 | + { |
| 40 | + suggestionMode: "repo", |
| 41 | + prefixes: [ |
| 42 | + SearchPrefix.repo, negate(SearchPrefix.repo), |
| 43 | + SearchPrefix.r, negate(SearchPrefix.r), |
| 44 | + ] |
| 45 | + }, |
| 46 | + { |
| 47 | + suggestionMode: "language", |
| 48 | + prefixes: [ |
| 49 | + SearchPrefix.lang, negate(SearchPrefix.lang), |
| 50 | + ] |
| 51 | + }, |
| 52 | + { |
| 53 | + suggestionMode: "file", |
| 54 | + prefixes: [ |
| 55 | + SearchPrefix.file, negate(SearchPrefix.file), |
| 56 | + ] |
| 57 | + }, |
| 58 | + { |
| 59 | + suggestionMode: "content", |
| 60 | + prefixes: [ |
| 61 | + SearchPrefix.content, negate(SearchPrefix.content), |
| 62 | + ] |
| 63 | + }, |
| 64 | + { |
| 65 | + suggestionMode: "revision", |
| 66 | + prefixes: [ |
| 67 | + SearchPrefix.rev, negate(SearchPrefix.rev), |
| 68 | + SearchPrefix.revision, negate(SearchPrefix.revision), |
| 69 | + SearchPrefix.branch, negate(SearchPrefix.branch), |
| 70 | + SearchPrefix.b, negate(SearchPrefix.b), |
| 71 | + ] |
| 72 | + }, |
| 73 | + { |
| 74 | + suggestionMode: "symbol", |
| 75 | + prefixes: [ |
| 76 | + SearchPrefix.sym, negate(SearchPrefix.sym), |
| 77 | + ] |
| 78 | + }, |
| 79 | + { |
| 80 | + suggestionMode: "archived", |
| 81 | + prefixes: [ |
| 82 | + SearchPrefix.archived |
| 83 | + ] |
| 84 | + }, |
| 85 | + { |
| 86 | + suggestionMode: "case", |
| 87 | + prefixes: [ |
| 88 | + SearchPrefix.case |
| 89 | + ] |
| 90 | + }, |
| 91 | + { |
| 92 | + suggestionMode: "fork", |
| 93 | + prefixes: [ |
| 94 | + SearchPrefix.fork |
| 95 | + ] |
| 96 | + }, |
| 97 | + { |
| 98 | + suggestionMode: "public", |
| 99 | + prefixes: [ |
| 100 | + SearchPrefix.public |
| 101 | + ] |
| 102 | + } |
| 103 | +]; |
| 104 | + |
| 105 | +export const refineModeSuggestions: Suggestion[] = [ |
| 106 | + { |
| 107 | + value: SearchPrefix.repo, |
| 108 | + description: "Include only results from the given repository.", |
| 109 | + spotlight: true, |
| 110 | + }, |
| 111 | + { |
| 112 | + value: negate(SearchPrefix.repo), |
| 113 | + description: "Exclude results from the given repository." |
| 114 | + }, |
| 115 | + { |
| 116 | + value: SearchPrefix.lang, |
| 117 | + description: "Include only results from the given language.", |
| 118 | + spotlight: true, |
| 119 | + }, |
| 120 | + { |
| 121 | + value: negate(SearchPrefix.lang), |
| 122 | + description: "Exclude results from the given language." |
| 123 | + }, |
| 124 | + { |
| 125 | + value: SearchPrefix.file, |
| 126 | + description: "Include only results from filepaths matching the given search pattern.", |
| 127 | + spotlight: true, |
| 128 | + }, |
| 129 | + { |
| 130 | + value: negate(SearchPrefix.file), |
| 131 | + description: "Exclude results from file paths matching the given search pattern." |
| 132 | + }, |
| 133 | + { |
| 134 | + value: SearchPrefix.rev, |
| 135 | + description: "Search a given branch or tag instead of the default branch.", |
| 136 | + spotlight: true, |
| 137 | + }, |
| 138 | + { |
| 139 | + value: negate(SearchPrefix.rev), |
| 140 | + description: "Exclude results from the given branch or tag." |
| 141 | + }, |
| 142 | + { |
| 143 | + value: SearchPrefix.sym, |
| 144 | + description: "Include only symbols matching the given search pattern.", |
| 145 | + spotlight: true, |
| 146 | + }, |
| 147 | + { |
| 148 | + value: negate(SearchPrefix.sym), |
| 149 | + description: "Exclude results from symbols matching the given search pattern." |
| 150 | + }, |
| 151 | + { |
| 152 | + value: SearchPrefix.content, |
| 153 | + description: "Include only results from files if their content matches the given search pattern." |
| 154 | + }, |
| 155 | + { |
| 156 | + value: negate(SearchPrefix.content), |
| 157 | + description: "Exclude results from files if their content matches the given search pattern." |
| 158 | + }, |
| 159 | + { |
| 160 | + value: SearchPrefix.archived, |
| 161 | + description: "Include results from archived repositories.", |
| 162 | + }, |
| 163 | + { |
| 164 | + value: SearchPrefix.case, |
| 165 | + description: "Control case-sensitivity of search patterns." |
| 166 | + }, |
| 167 | + { |
| 168 | + value: SearchPrefix.fork, |
| 169 | + description: "Include only results from forked repositories." |
| 170 | + }, |
| 171 | + { |
| 172 | + value: SearchPrefix.public, |
| 173 | + description: "Filter on repository visibility." |
| 174 | + }, |
| 175 | +]; |
| 176 | + |
| 177 | +export const publicModeSuggestions: Suggestion[] = [ |
| 178 | + { |
| 179 | + value: "yes", |
| 180 | + description: "Only include results from public repositories." |
| 181 | + }, |
| 182 | + { |
| 183 | + value: "no", |
| 184 | + description: "Only include results from private repositories." |
| 185 | + }, |
| 186 | +]; |
| 187 | + |
| 188 | +export const forkModeSuggestions: Suggestion[] = [ |
| 189 | + { |
| 190 | + value: "yes", |
| 191 | + description: "Only include results from forked repositories." |
| 192 | + }, |
| 193 | + { |
| 194 | + value: "no", |
| 195 | + description: "Only include results from non-forked repositories." |
| 196 | + }, |
| 197 | +]; |
| 198 | + |
| 199 | +export const caseModeSuggestions: Suggestion[] = [ |
| 200 | + { |
| 201 | + value: "auto", |
| 202 | + description: "Search patterns are case-insensitive if all characters are lowercase, and case sensitive otherwise (default)." |
| 203 | + }, |
| 204 | + { |
| 205 | + value: "yes", |
| 206 | + description: "Case sensitive search." |
| 207 | + }, |
| 208 | + { |
| 209 | + value: "no", |
| 210 | + description: "Case insensitive search." |
| 211 | + }, |
| 212 | +]; |
| 213 | + |
| 214 | +export const archivedModeSuggestions: Suggestion[] = [ |
| 215 | + { |
| 216 | + value: "yes", |
| 217 | + description: "Only include results in archived repositories." |
| 218 | + }, |
| 219 | + { |
| 220 | + value: "no", |
| 221 | + description: "Only include results in non-archived repositories." |
| 222 | + }, |
| 223 | +]; |
| 224 | + |
0 commit comments