Skip to content
flow

FeaturesCode navigation

Code navigation

Go to definition, find references and jump history in the Files tab, with standard-library sources, language docs and external code search.

View as Markdown
On this page

The Files tab's code view can jump to a symbol's definition and list its references without a language server. Each lookup is one quick search of your disk (ripgrep, else git grep), so there is no index to build and nothing runs in the background between lookups. When one hit clearly wins, Flow opens it. When several could be right, they open in the file picker and you choose. If nothing on disk matches, the language's docs and an external code search are one keystroke away.

Code navigation works in Rust, Python, Java, JavaScript / TypeScript, shell (sh, bash, zsh), C and C++. The language comes from the file extension. A file with no extension counts as shell when its #! line names sh, bash, zsh, dash or ksh. In any other file type, a lookup shows No code navigation for this file type in the tab's footer.

Look up a symbol

Open a file in a Files tab first. Then:

Gesture or keyWhat it does
⌘-hoverUnderlines the word a ⌘-click would look up, and the pointer becomes a hand
⌘-clickMoves the caret to the word and goes to its definition
⌥⌘-clickFinds references
⇧⌘-clickGoes to the definition. If nothing on disk defines it, opens the first escape row directly: the docs, else the external search, in the other place (see Where links open)
⌘BGo to definition at the caret (keyboard.go_to_definition)
⇧⌘BFind references at the caret (keyboard.find_references)
F12 / ⇧F12Definition / references at the caret, while the code view holds the keyboard
⌃- / ⌃⇧-Back / forward through the jump history, while the code view holds the keyboard
EscCancels a lookup that is still running

"Go to definition" and "Find references" are also in the command palette, and you can rebind them in Settings › Keyboard. They act on the focused Files tab's caret, so with no Files tab focused or no caret they do nothing. The code view holds the keyboard after you click in the code or land on a jump (the caret shows). Clicking in the explorer gives the keyboard back to the explorer.

While a lookup runs, the footer reads Finding X…. Pressing ⌘-click again, or moving on before it answers, drops the old answer. Moving on means another line, tab, group or page, or a palette you opened yourself, so a late answer never pulls you back.

What opens

  • One clear winner opens straight away, with the caret on the symbol. A file under the tab's folder opens in the same tab. A file outside it (a dependency, or the repository top above the tab's folder) opens in a Files tab rooted at that file's own folder.
  • Several plausible hits open the file picker in Defs mode with the ranked hits already listed and the first one selected and previewed.
  • The caret is already on the definition: you get its references instead, as in an IDE. This also covers a struct field, an enum variant, a TypeScript class field (name: string;) and a Python self.x = 0 in __init__. A C prototype is not a definition, so its caret goes to the function.
  • Find references always opens the picker in Refs mode, even when there are no references. Then the list is empty and its first escape row is selected, so ↩ searches outside.
  • Nothing on disk: the Defs picker opens empty with its first escape row selected, which is the docs for a language word, else Search for more on github.com… (or your configured host).
  • A keyword (fn, def, class, if) searches nothing and goes straight to the empty picker with its docs row.

Where Flow looks

Every lookup searches your disk first. The docs and the external search come only after that. In order, stopping at the first step that answers:

  1. The file itself. Unless the word is a member access (obj.x, self.x, p->x) or an import binds it, Flow takes the nearest binding at or above the caret: let, a parameter, for … in, destructuring, with … as, local x or a shell function.
  2. A Rust enum variant (Verdict::Jump, Self::Empty, or Some / None / Ok / Err). Flow finds the enum first, then the variant inside it.
  3. The repository. The search root is the file's git top level. Flow matches the language's definition shapes (functions, types, classes, methods, constants, macros) and respects .gitignore. Hidden folders are skipped, except .github, .husky, .circleci, .buildkite, .devcontainer, .gitlab and .config. Agents' worktree copies under .claude/ and .worktrees/ are never searched. The open file's own definitions always count, even when the file is untracked or has no extension.
  4. Fields, attributes and variants, for a member access that found no method or function. This covers struct fields, enum variants, Python self.x attributes, JS / TS class fields, this.x = and exports.x =.
  5. Dependencies on disk (local tabs only):
    • JS / TS: a bare import's nearest node_modules package.
    • Python: a package in a virtualenv's site-packages ($VIRTUAL_ENV, .venv, venv, env).
    • Rust: a crate's sources under $CARGO_HOME/registry/src, at the version Cargo.lock names.
    • Java, C, C++ and shell have no dependency step.
  6. The standard library (local tabs only). Flow searches the version chosen in Settings › Code › Languages for built-ins and standard names such as derive, Vec, len, setTimeout and printf. For C and C++ it searches the SDK headers for any name. These hits show their origin in the picker, for example fn · std · Rust 1.83.
  7. Escape rows. Nothing on disk: the empty Defs picker described above.

How hits are ranked

Flow drops lines that only look like definitions: calls, uses (struct S *p) and whole-line comments. The remaining hits rank by:

  • Where they are. A path matching the file's import ranks far above the rest, then the same file, the same folder and shared parent folders.
  • What they define. Types, functions and modules rank above methods, then macros and constants, then variables. A declaration (a C prototype, a forward struct S;) never ranks above a definition.
  • Tests and build output. Test files and vendored or build folders rank lower.

Each picker row ends with a tag that says what the line defines and why it ranks, for example fn · imported, local · same file, method or var · reference.

Defs and Refs in the file picker

Defs and Refs are modes of the file picker, after Grep. ⇥ cycles to them. When a Files tab lookup opened the picker, it ranks with that lookup's language, imports and file for as long as the query is still that symbol. Type any other symbol (two characters or more) and the picker searches every supported language's definitions (Defs) or whole-word occurrences (Refs) in the picker's folder.

KeyWhat it does
↩Opens the hit at its line with the caret on the symbol (a lookup's pick is recorded in the jump history)
⌘↩Opens it in a new split
⌥↩Reveals its folder in the explorer
⌃↩Runs the first escape row, from any row
⇧↩ on an escape row, ⌃⇧↩ on any rowThe same, opening the URL in the other place
⌃DPins the hit as a search-result pin

Escape rows

A Defs, Refs or Grep list ends with extra rows once its search is done:

  1. Language docs, such as Rust docs: derive…, for one of the language's own words or a symbol the standard library defined. In shell this row is man ls instead (man bash: if for a keyword or bash builtin; man zshbuiltins, man zshzle or man zshcompsys for zsh-only ones). It opens a new terminal tab running man, which closes when you quit the page.
  2. Search for more on github.com… (or your configured host).

Escape rows are not counted as hits, and the preview shows the URL or command instead of a file. Grep lists have only the search row. Files, Changed, Recent and Pinned have none. With nothing to run, ⌃↩ explains in the footer: Type a query to search for more or Type at least 2 characters.

Language words and their docs

Some words belong to the language rather than your code:

  • Keywords: fn, def, class, if, then.
  • Built-ins:
    • Rust attributes inside #[…] (derive, cfg, test) and std macros called with ! (println!, vec!).
    • Java annotations (@Override).
    • Python builtins and decorators (len, print, property, dataclass).
    • C preprocessor directives on a # line.
    • Shell builtins (echo, cd).
  • Standard names:
    • Rust's prelude (Vec, Option) and anything through std::.
    • Python names through a stdlib module (os.path.join).
    • JS / TS globals (setTimeout, Promise, console.log).
    • Java's java.lang names.
    • C's libc (printf, malloc) and C++'s std:: names.

For these words, the picker's escape rows start with the docs, at the version you use:

LanguageDocs URLVersion used
Rusthttps://doc.rust-lang.org/{version}/std/?search={symbol}The chosen or on-disk toolchain (stable without one)
Pythonhttps://docs.python.org/{version}/search.html?q={symbol}major.minor (3 without one)
JS / TShttps://developer.mozilla.org/en-US/search?q={symbol}none
Javahttps://docs.oracle.com/en/java/javase/{version}/docs/api/search.html?q={symbol}The JDK's feature release (21 without one)
C / C++https://en.cppreference.com/mwiki/index.php?search={symbol}none
Shellman in a terminal tabnone

You can replace a language's docs URL in Settings › Code › Per language, or with code_search.docs in .flowspace.json (see below). An override for shell gives shell a docs row too.

Standard library sources

The standard-library step searches one copy of each language's sources. Settings › Code › Languages has one row per language. Each row shows what is on disk (version and origin) and what is downloaded (with its size), and has a version picker: Auto (what is on disk) or a specific version. The row also has Download / Remove buttons (Java: Extract sources / Remove), and Cancel while one runs.

LanguageFound on diskDownload
Rustrust-src of a rustup toolchain (rustup component add rust-src), a stable one firstrust-src from static.rust-lang.org, checked against its published SHA-256
PythonThe stdlib of the repository's .venv / venv base interpreter, else python3'sThe Python source tarball from python.org (HTTPS only, no checksum)
JS / TSThe repository's node_modules/typescript/libThe typescript package from the npm registry, checked against its sha512 integrity
JavaInstalled JDKs (9 or later), each lib/src.zipNone. Extract sources unzips a JDK's java.* modules once
C / C++The Xcode SDK's usr/include (C++ adds usr/include/c++/v1)None
ShellNothing (uses man)None

Rust and Python offer recent stable releases. TypeScript offers the npm registry's tags, and Download latest never picks a beta or release candidate. Downloads are stored in ~/Library/Application Support/flow/lang/ and shared by every worktree. A failed or cancelled download leaves nothing behind. A missing tool (no rustup, python3, JDK or Xcode) simply reads as "not found". Flow never triggers the Command Line Tools install prompt.

SettingTypeDefaultEffect
code_nav.lang.rust.version (also python, jsts, java, c, shell)stringautoThe version the standard-library step searches when it is installed (else the one on disk), and the version the docs links name. C++ uses the c key

Jump history

Every jump records where the caret was, whether the jump was direct or a pick from a lookup's picker. Each session has one history, shared by all its Files tabs.

  • The history holds up to 50 places. A repeat collapses into one entry, and a new jump clears the forward list.
  • ⌃- goes back. It brings the place's tab to the front and reopens its file, so ⌃- in a dependency's tab returns you to the tab you jumped from.
  • ⌃⇧- goes forward.

The history lasts until Flow quits.

When you run a Search for more row, Flow opens a code-search URL. By default that is GitHub code search: https://github.com/search?type=code&q={query}.

Settings › Code

The Code search block picks the engine: GitHub (the default), Sourcegraph (with a base URL for a self-hosted instance) or Custom (one URL template). The Per language block has a search template and a docs template for each language. An empty field uses the engine, or the language's built-in docs. Enter saves a field, and anything but an http:// or https:// URL is refused. Changes apply at once, with no restart. The block's first row says which search is in use for the active session's checkout and which layer set it (for example github.com · repo .flowspace.json overrides Settings).

SettingTypeDefaultEffect
code_search.enginegithub, sourcegraph or customgithubWhere Search for more goes
code_search.sourcegraph_urlURLempty (https://sourcegraph.com)The Sourcegraph instance, when the engine is Sourcegraph
code_search.urlURL templateempty (GitHub)The template, when the engine is Custom
code_search.by_lang.LANGURL templateempty (the engine)One language's search template, in place of the engine
code_search.docs.LANGURL templateempty (built-in docs)One language's docs row

LANG is one of rust, python, java, jsts, shell, c, cpp.

code_search in .flowspace.json

A repository can set its own search in .flowspace.json under the code_search key. A language without a by_lang entry uses url:

json
{
  "code_search": {
    "url": "https://sourcegraph.com/search?q=context:global+{symbol}+lang:{lang}",
    "by_lang": {
      "java": "https://opengrok.example.com/source/search?defs={symbol}&project=main"
    },
    "docs": {
      "shell": "https://docs.example.com/search?q={symbol}"
    }
  }
}

A subdirectory's file, your per-repository file and the repository's own .flowspace.json all beat Settings › Code, one field and one language at a time. Settings fill whatever the files leave out. To make your Settings win everywhere, mark code_search !important at the User scope: use the toggle on Settings › Repos, or add "!important": ["code_search"] to ~/.flow/flowspace.json. See Settings scopes and .flowspace.json.

Placeholders in a template (each URL-encoded):

PlaceholderIs
{symbol}The name looked up, with an import alias resolved to its original name. {text} is the same
{lang}GitHub's language name (Rust, TypeScript, C++, …)
{module}The import's module as written (serde::de, os.path, ./x)
{package}The module's first segment (serde, react)
{path}The current file, relative to the search root
{repo}owner/name of the repository's origin, when known
{query}GitHub-style: symbol:NAME language:LANG for a definition, NAME language:LANG for references, plus the package for a third-party import

Note: Only the built-in Sourcegraph engine speaks Sourcegraph's query syntax. Every template you write yourself keeps the GitHub-style {query}, so a template for a Sourcegraph instance should use {symbol}, as in the example above.

A query you type in the picker with no Files tab behind it (Grep, or a free-typed Defs / Refs symbol) has no language. It always uses url, never a by_lang template, and {lang}, {module}, {package} and {path} are empty. A remote tab uses Settings alone, and {repo} is empty there.

The search and docs URLs open like any other web link, as set by links.open_in (Settings › General › Tabs, "Open links in", shown while the web tabs experiment is on):

SettingTypeDefaultEffect
links.open_inbrowser or appbrowserOpens web links in your browser, or in a webview tab in Flow

In the picker, ⇧↩ on the Search for more row (or ⌃⇧↩ anywhere) flips that choice for one search. A ⇧⌘-click with no local definition also goes to the other place. Opening links in Flow needs the web tabs experiment (features.web_tabs). While it is off, links always open in the browser and ⇧ flips nothing. See Webview tabs.

From the command line

Scripts and agents can drive code navigation through flow-cli (see flow-cli):

sh
# Go to definition / find references at a 1-based line and 0-based column
# of the focused group's Files tab (or at the caret)
flow-cli files-nav def 120 8
flow-cli files-nav refs
# Step the jump history
flow-cli files-nav back
flow-cli files-nav forward
# Settings › Code › Languages
flow-cli lang-sources list
flow-cli lang-sources download rust 1.83.0
flow-cli lang-sources cancel rust

files-nav also takes --group NAME. flow-cli state reports each Files tab's last lookup under nav.

Limits

  • Pattern matching, not type resolution. An overloaded name, a method called on an expression of unclear type, or a macro-generated item may rank wrong or not be found. obj.len() finds every len method, ranked by path. The picker is there for these cases.
  • Remote tabs skip the dependency and standard-library steps and use the code search from Settings only. The repository search runs on the host.
  • Files on a paired device have no code navigation (Go to definition is not available for files on another device).
  • Searches stop at 200 definition hits, 500 reference hits, 20 hits per file and 1 MB files (8 MB for standard-library files). Without ripgrep or a git checkout nothing can be searched.
  • You can look up a word inside a comment, but a whole-line comment never counts as a definition, and in Refs, comment-only lines rank last.
Sources

Written from these files in the Flow app repo

  • docs/code-navigation.md
  • src/code_nav.rs
  • src/code_nav_ui.rs
  • src/lang_ref.rs
  • src/lang_sources.rs
  • src/files_code_ui.rs
  • src/files_ui.rs
  • src/file_picker.rs
  • src/file_picker_ui.rs
  • src/settings_catalog.rs
  • src/scope.rs
  • src/link_open.rs
  • src/pages.rs
  • src/bin/flow-cli.rs