MCPcopy Create free account
hub / github.com/sourcebot-dev/sourcebot / transformPrefixExpr

Function transformPrefixExpr

packages/web/src/features/search/parser.ts:234–431  ·  view source on GitHub ↗
(node: SyntaxNode)

Source from the content-addressed store, hash-verified

232 }
233
234 const transformPrefixExpr = async (node: SyntaxNode): Promise<QueryIR> => {
235 // Find which specific prefix type this is
236 const prefixNode = node.firstChild;
237 if (!prefixNode) {
238 throw new Error("PrefixExpr has no child");
239 }
240
241 const prefixTypeId = prefixNode.type.id;
242
243 // Extract the full text (e.g., "file:test.js") and split on the colon
244 const fullText = input.substring(prefixNode.from, prefixNode.to);
245 const colonIndex = fullText.indexOf(':');
246 if (colonIndex === -1) {
247 throw new Error(`${prefixNode.type.name} missing colon`);
248 }
249
250 // Get the value part after the colon and remove quotes if present
251 const value = fullText.substring(colonIndex + 1).replace(/^"|"$/g, '');
252
253 switch (prefixTypeId) {
254 case FileExpr:
255 return {
256 regexp: {
257 regexp: value,
258 case_sensitive: isCaseSensitivityEnabled,
259 file_name: true,
260 content: false
261 },
262 query: "regexp"
263 };
264
265 case RepoExpr:
266 return {
267 repo: {
268 regexp: value
269 },
270 query: "repo"
271 };
272
273 case RevisionExpr:
274 return {
275 branch: {
276 // Special case - "*" means search all branches. Passing in a
277 // blank string will match all branches.
278 pattern: value === '*' ? "" : value,
279 exact: false
280 },
281 query: "branch"
282 };
283
284 case ContentExpr:
285 return isRegexEnabled ? {
286 regexp: {
287 regexp: value,
288 case_sensitive: isCaseSensitivityEnabled,
289 file_name: false,
290 content: true
291 },

Callers 1

transformNodeFunction · 0.85

Calls 4

findLinguistLanguageFunction · 0.85
isVisibilityValueFunction · 0.85
isArchivedValueFunction · 0.85
isForkValueFunction · 0.85

Tested by

no test coverage detected