-
Notifications
You must be signed in to change notification settings - Fork 253
Expand file tree
/
Copy pathsyntaxDescription.ts
More file actions
110 lines (76 loc) · 3.96 KB
/
syntaxDescription.ts
File metadata and controls
110 lines (76 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* LLM-readable description of the Sourcebot search query syntax.
* Keep this in sync with query.grammar and tokens.ts when the syntax changes.
*/
export const SEARCH_SYNTAX_DESCRIPTION = String.raw`
# Sourcebot Search Query Syntax
## Search terms
Bare words search across file content and are interpreted as case-sensitive regular expressions:
useState — matches files containing "useState"
useS?tate — matches files containing "useState" or "usetate"
^import — matches lines beginning with "import"
error.*handler — matches "error" followed by "handler" on the same line
Wrap terms in double quotes to match a phrase with spaces:
"password reset" — matches files containing the phrase "password reset"
## Filters
Narrow searches with prefix:value syntax:
file:<value> — filter by file path
lang:<value> — filter by language. Uses linguist language definitions (e.g. TypeScript, Python, Go, Rust, Java)
repo:<value> — filter by repository name (use ONLY to limit WHICH repositories are searched, NOT for content within files)
sym:<value> — filter by symbol name
rev:<value> — filter by git branch or tag
All filter values are interpreted as case-sensitive regular expressions.
A plain word matches as a substring. No forward slashes around values.
IMPORTANT: When users want to search for content or keywords INSIDE files, use bare search terms or quoted phrases, NOT the repo: filter. The repo: filter only controls which repositories to search, it does not search file content.
## Boolean logic
Space = AND. All space-separated terms must match.
useState lang:TypeScript — TypeScript files containing useState
or = OR (must be lowercase, not at start/end of query).
auth or login — files containing "auth" or "login"
- = negation. Only valid before a filter or a parenthesized group.
-file:test — exclude paths matching /test/
-(file:test or file:spec) — exclude test and spec files
## Grouping
Parentheses group expressions:
(auth or login) lang:TypeScript
-(file:test or file:spec)
## Quoting
Wrap a value in double quotes when it contains spaces:
"password reset"
"error handler"
When the quoted value itself contains double-quote characters, escape each one as \":
"\"key\": \"value\"" — matches the literal text: "key": "value"
For unquoted values, escape regex metacharacters with a single backslash:
file:package\.json — matches literal "package.json"
## Examples
Input: find all TODO comments
Output: //\s*TODO
Input: find TypeScript files that use useState
Output: lang:TypeScript useState
Input: find files that import from react
Output: lang:TypeScript "from \"react\""
Input: find all test files
Output: file:(test|spec)
Input: find all API route handlers
Output: file:route\.(ts|js)$
Input: find package.json files that depend on react
Output: file:package\.json "\"react\": \""
Input: find package.json files with beta or alpha dependencies
Output: file:package\.json "\"[^\"]+\": \"[^\"]*-(beta|alpha)"
Input: find package.json files where next is pinned to version 15
Output: file:package\.json "\"next\": \"\\^?15\\."
Input: find next versions less than 15
Output: file:package\.json "\"next\": \"\^?(1[0-4]|[1-9])\."
Input: find log4j versions 2.3.x or lower
Output: file:package\.json "\"log4j\": \"\^?2\.([0-2]|3)\."
Input: find TypeScript files that import from react or react-dom
Output: lang:TypeScript "from \"(react|react-dom)\""
Input: find files with password reset logic, excluding tests
Output: "password reset" -file:test
Input: find Terraform files that reference glennbot or glenn-bot deployments
Output: lang:Terraform (glennbot|glenn-bot)
Input: find all files mentioning the myapp-api service
Output: myapp-api
Input: find Python files in the backend repo that use requests library
Output: lang:Python repo:backend import requests
`.trim();