Skip to content

Search the code

Search main's files with regular expressions, answered by the forge's own index, and only in the files you may read.

af search searches the files on main with a regular expression. The forge answers it from a trigram index it keeps of main, as Zoekt and Google’s code search do, so a search does not depend on your workspace: it finds files your workspace does not hold. It searches only the files you may read.

Find lines

Start a server and land some code:

$ af-server --dev
...
$ source ~/af-dev/dev/env
$ af workspace add ~/demo
Workspace at /home/you/demo
Paths: **
main has no landing yet
$ cd ~/demo
$ af new -m "Add a small program"
Working on change omukmnmmoypqyylrxspyusnmkpymtzyp at commit 45e3a1f056aa3879dceae71d2d5d7ce3f3220d46380cdc4285974d9e8a213e82
$ mkdir -p src docs
$ printf 'fn main() {\n    // TODO: greet by name\n    println!("Hello");\n}\n' > src/main.rs
$ printf '# Notes\n\nTODO: write the guide\n' > docs/notes.md
$ af submit
Submitted commit 448a7eef3d902915a65af99742efb4487ee2ef4c0535a0c4dd17a7b289a12e20, 2 edits in its last snapshot

Once the landing is in the index, each matching line comes back as path:line:text:

$ af search TODO
docs/notes.md:3:TODO: write the guide
src/main.rs:2:    // TODO: greet by name

Narrow it by file

-f keeps only files whose path matches a second expression:

$ af search TODO -f '\.rs$'
src/main.rs:2:    // TODO: greet by name

With only -f, af search lists the paths that match, which is a quick way to find files:

$ af search -f '\.md$'
docs/notes.md

The pattern is Rust’s regular expression syntax, and ^ and $ match at the start and end of each line. Results stop at 20 files and 20 lines a file; -n and --lines change that. A search by path alone gives the first files in path order. A search of text that matches more files than the limit gives some of them, listed in path order, but which ones is not decided by path order. An expression that does not parse is refused, and so is af search with neither an expression nor -f.

What search covers

  • Only main. A change that is still open is not searched. The index takes main in at most once a second, so a landing is searchable a moment after it lands, and a search straight after a landing can miss it. Search again.
  • Only files you may read. A folder you may not read gives no result, by text or by path.
  • Only text. A file is searched only if it is valid UTF-8, has no line longer than 2,000 bytes and is at most a mebibyte. A file that is not text is not in the index at all, so -f does not list it either. Search, caches and releases has the whole rule and says how the index is kept.

Next

Type to search…

↑↓ navigate↵ selectEsc close