Skip to content
This repository was archived by the owner on Jan 19, 2023. It is now read-only.

Commit b7e3b39

Browse files
vdavidltagliaferri
andauthored
Fix a few typos and small problems on the code search cheat sheet page (#482)
* Fix a few typos and small problems on the page I was just reading the page to learn about the search syntax, spotted a few problems, and decided to fix them to improve this page. For the types, I used https://docs.sourcegraph.com/code_search/reference/queries as a source. * Update markdown for links Co-authored-by: ltagliaferri <[email protected]>
1 parent 52fda6f commit b7e3b39

File tree

1 file changed

+40
-28
lines changed

1 file changed

+40
-28
lines changed

posts/how-to-search-code-with-sourcegraph-a-cheat-sheet.md

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ type: posts
1313

1414
Sourcegraph is a universal code search tool, enabling you to search across both open source and your own private code repositories. Code search can help you onboard onto new codebases, contribute to open source, find bugs and error messages, understand dependency libraries, and more.
1515

16-
This cheat sheet style guide can help you get up to speed with Sourcegraph commands quickly. For more thorough tutorials on using Sourcegraph, refer to our tutorials(https://learn.sourcegraph.com/tags/sourcegraph) and our documentation(https://docs.sourcegraph.com/).
16+
This cheat sheet style guide can help you get up to speed with Sourcegraph commands quickly. For more thorough tutorials on using Sourcegraph, refer to our [tutorials](https://learn.sourcegraph.com/tags/sourcegraph) and our [documentation](https://docs.sourcegraph.com/).
1717

18-
You can use these commands on either Sourcegraph Cloud(https://sourcegraph.com/search) or your own Sourcegraph instance(https://docs.sourcegraph.com/admin/install).
18+
You can use these commands on either [Sourcegraph Cloud](https://sourcegraph.com/search) or your own [Sourcegraph instance](https://docs.sourcegraph.com/admin/install).
1919

2020
## Searching an organization’s repository
2121

@@ -48,10 +48,10 @@ When searching a repository, command chaining can be used to return more specifi
4848

4949
**Search for a repository that contains a file**
5050

51-
If you are searching for a file in a repository, use `repo.contains.file`.
51+
If you are searching for a file in a repository, use `repo:contains.file`.
5252

5353
<Highlighter
54-
input='repo:repository-path repo.contains.file(file-path)'
54+
input='repo:repository-path repo:contains.file(file-path)'
5555
matcher='file-path'
5656
/>
5757

@@ -67,15 +67,15 @@ This query returns repositories that contain a `package.json` file and has conte
6767

6868
**Search for a repository that contains some content**
6969

70-
Suppose you are searching for some content in a repository, such as a library. Use `repo.contains.content`.
70+
Suppose you are searching for some content in a repository, such as a library. Use `repo:contains.content`.
7171

7272
<Highlighter
73-
input='repo:repo-path repo.contains.content(your-content)'
73+
input='repo:repo-path repo:contains.content(your-content)'
7474
matcher='your-content'
7575
/>
7676

7777
<Highlighter
78-
input='repo:repo-path repo.contains.content(regular-pattern)'
78+
input='repo:repo-path repo:contains.content(regular-pattern)'
7979
matcher='regular-pattern'
8080
/>
8181

@@ -128,7 +128,7 @@ after:time-period'
128128
matcher='time-period'
129129
/>
130130

131-
Sometimes the time period can be literal, like `last week`, `last year`, `3 months ago`, `february 10 2021` or have actual dates in the format `dd/mm/yyyy`.
131+
Sometimes the time period can be relative, like `last week`, `last year`, `3 months ago` or absolute, in several formats including `{month} {day} {year}` (example: `february 10 2021`), `dd/mm/yyyy`, and ISO format `yyyy-mm-dd`.
132132

133133
<Highlighter
134134
input='before:last week'
@@ -158,10 +158,18 @@ Note that `before` and `after` only work in conjunction when combined with `type
158158
The `archived` keyword will bring up those results from repositories that have been archived.
159159

160160
<Highlighter
161-
input='archived:yes/only
162-
archived:yes
163-
archived:only'
164-
matcher='yes/only'
161+
input='archived:yes'
162+
matcher='yes'
163+
/>
164+
165+
<Highlighter
166+
input='archived:no'
167+
matcher='no'
168+
/>
169+
170+
<Highlighter
171+
input='archived:only'
172+
matcher='only'
165173
/>
166174

167175
We can surface only archived repositories within the Sourcegraph organization with the following query.
@@ -175,13 +183,16 @@ This can help us understand past decisions made within a given codebase.
175183
Use `yes` or `no` with the `case` search query to specify if the search should be case sensitive or not. By default, searches are case insensitive.
176184

177185
<Highlighter
178-
input='case:yes/no
179-
case:yes
180-
case:no'
181-
matcher='yes/no'
186+
input='case:yes'
187+
matcher='yes'
188+
/>
189+
190+
<Highlighter
191+
input='case:no'
192+
matcher='no'
182193
/>
183194

184-
Suppose you would like to check to align the style of a given codebase to help you bring all function calls in Python to be consistent with the PEP 8(https://www.python.org/dev/peps/pep-0008/) guidance. You can use Sourcegraph to understand which functions are using camelCase rather than lowercase names with underscores between words (also called snake_case).
195+
Suppose you would like to check to align the style of a given codebase to help you bring all function calls in Python to be consistent with the [PEP 8](https://www.python.org/dev/peps/pep-0008/) guidance. You can use Sourcegraph to understand which functions are using camelCase rather than lowercase names with underscores between words (also called snake_case).
185196

186197
<SourcegraphSearch query="case:yes lang:python myFunction" />
187198

@@ -193,20 +204,21 @@ If you would like to find all declared functions that use camelCase, you can try
193204
Types define the scope of code search. A search scope consists of commits, diffs, symbols, repos, paths and files. It is typically used alongside other search commands to further narrow search results.
194205

195206
<Highlighter
196-
input='type:commit|paths|diff|symbol|repo|files'
197-
matcher='commit|paths|diff|symbol|repo|files'
207+
input='type:commit|path|diff|symbol|repo|file'
208+
matcher='commit|path|diff|symbol|repo|file'
198209
/>
199210

200211
Here is an example to show us time-based commits on the Sourcegraph repo.
201212

202213
<SourcegraphSearch query="repo:sourcegraph after:yesterday type:commit" />
203214

204215
A `type` scope can use the following commands, which will restrict search to the following:
205-
* `commit` — commits to a repository
206-
* `diff` — show diffs(https://git-scm.com/docs/git-diff), or changes, within a repository
207-
*`repo` — repositories available to you
208-
* `files` — returns files
209-
*`symbol` — returns files that contain names or keywords in a library.
216+
* `commit` — commits to a repository.
217+
* `path` — restricts terms to matching filenames only (not file contents).
218+
* `diff` — show [diffs](https://git-scm.com/docs/git-diff), or changes, within a repository.
219+
* `repo` — repositories available to you.
220+
* `file` — restricts terms to matching file contents only (not filenames).
221+
* `symbol` — returns files that contain names or keywords in a library.
210222

211223
Searching by type can help you find exactly what you need in a codebase by narrowing down the scope of your search.
212224

@@ -319,8 +331,8 @@ This can allow you to search across the code that is private to only you. _Pleas
319331
## Further resources
320332

321333
To learn more about how to search effectively with Sourcegraph, you can read through our Sourcegraph search series:
322-
* How To Search with Sourcegraph using Literal Patterns(/how-to-search-code-with-sourcegraph-using-literal-patterns)
323-
* How To Search with Sourcegraph using Regular Expression Patterns(/how-to-search-with-sourcegraph-using-regular-expression-patterns)
324-
* How To Search with Sourcegraph using Structural Patterns(/how-to-search-with-sourcegraph-using-structural-patterns)
334+
* [How To Search with Sourcegraph using Literal Patterns](/how-to-search-code-with-sourcegraph-using-literal-patterns)
335+
* [How To Search with Sourcegraph using Regular Expression Patterns](/how-to-search-with-sourcegraph-using-regular-expression-patterns)
336+
* [How To Search with Sourcegraph using Structural Patterns](/how-to-search-with-sourcegraph-using-structural-patterns)
325337

326-
You can also check out Sourcegraph product documentation(https://docs.sourcegraph.com/) and Sourcegraph tutorials(https://learn.sourcegraph.com/tags/sourcegraph).
338+
You can also check out [Sourcegraph product documentation](https://docs.sourcegraph.com/) and [Sourcegraph tutorials](https://learn.sourcegraph.com/tags/sourcegraph).

0 commit comments

Comments
 (0)