Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@ Browse Unity Technologies' official UnityCsReference C# source as a read-only lo
```bash
unity-cli reference fetch --accept-license
unity-cli reference status --output json
unity-cli reference find-symbol --name Animator --kind class
unity-cli reference grep "class Animator " --context 3
unity-cli reference view Runtime/Export/Animation/Animator.bindings.cs --start-line 100 --max-lines 60
unity-cli reference clean --keep 1 --dry-run
```

Use `reference find-symbol` first when you already know the type name (class / interface / struct / enum). It is backed by an on-disk index per Unity version (`~/.unity/cache/UnityCsReference/<version>/.unity-cli-index/symbols.json`) and is faster than `grep` for repeated lookups. Drop back to `grep` for free-text patterns or member-level matches.

## Examples

- "Show me how Unity implements `Animator.Play` so I can predict whether it allocates."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ The canonical reference → navigate → edit workflow when validating LLM-sugge
### 1. Locate the symbol in the official source

```bash
unity-cli reference grep "class Animator " --context 0
unity-cli reference find-symbol --name Animator --kind class
unity-cli reference find-symbol --name AssetDatabase --kind class --namespace UnityEditor
unity-cli reference grep "void Play\(" --file-glob "Animator*.cs" --context 2
unity-cli reference search "AssetDatabase.Refresh" --max-results 10
```

`grep` emits `{ path, line, text, context_before, context_after }` so the surrounding context survives a follow-up `view`.
`find-symbol` reads (and lazily builds) a per-version index of type definitions and returns `{ path, name, kind, line, namespace?, container?, fqn? }`. Use it when the type name is already known; the index is regenerated incrementally based on file size and mtime, so repeated lookups within the same Unity version are O(1) over the index. Fall back to `grep` when the pattern targets methods, properties, or free text — those are intentionally outside the Phase 2 index scope.

### 2. Read the relevant span

Expand Down
4 changes: 3 additions & 1 deletion docs/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ unity-cli tool schema input_keyboard --output json
unity-cli tool schema package_manager --output json
```

## Reference Cache (6 tools)
## Reference Cache (7 tools)

The `unity-cli reference *` family provides a local read-only mirror of the
official [UnityCsReference](https://github.com/Unity-Technologies/UnityCsReference)
Expand All @@ -267,12 +267,14 @@ fetch via `--accept-license` or `UNITY_CLI_ACCEPT_LICENSE=1`.
| `reference_grep` | Grep the cached reference source line-by-line with optional file glob and context lines. |
| `reference_view` | Display a slice of a file in the cached reference source by line range. |
| `reference_clean` | Remove old UnityCsReference snapshots, keeping the newest entries. |
| `reference_find_symbol` | Look up type definitions (class / interface / struct / enum) in the cached reference source via a per-version on-disk index. |

Typed CLI equivalents:

```bash
unity-cli reference fetch --accept-license
unity-cli reference status --output json
unity-cli reference find-symbol --name Animator --kind class
unity-cli reference grep "class Animator " --context 3
unity-cli reference view Runtime/Export/Animation/Animator.bindings.cs --start-line 100 --max-lines 60
unity-cli reference clean --keep 1 --dry-run
Expand Down
50 changes: 50 additions & 0 deletions src/app/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,24 @@ fn build_reference_call(command: &ReferenceCommand) -> (&'static str, Value) {
}
"reference_view"
}
ReferenceCommand::FindSymbol {
name,
kind,
namespace,
version,
} => {
params.insert("name".to_string(), Value::String(name.clone()));
if let Some(k) = kind {
params.insert("kind".to_string(), Value::String(k.clone()));
}
if let Some(ns) = namespace {
params.insert("namespace".to_string(), Value::String(ns.clone()));
}
if let Some(v) = version {
params.insert("version".to_string(), Value::String(v.clone()));
}
return ("reference_find_symbol", Value::Object(params));
}
ReferenceCommand::Clean {
keep,
version,
Expand Down Expand Up @@ -2142,6 +2160,38 @@ mod tests {
assert_eq!(params["dryRun"], true);
}

#[test]
fn build_reference_call_find_symbol_with_filters() {
let cmd = ReferenceCommand::FindSymbol {
name: "Animator".to_string(),
kind: Some("class".to_string()),
namespace: Some("UnityEngine".to_string()),
version: Some("2023.2.20f1".to_string()),
};
let (tool, params) = build_reference_call(&cmd);
assert_eq!(tool, "reference_find_symbol");
assert_eq!(params["name"], "Animator");
assert_eq!(params["kind"], "class");
assert_eq!(params["namespace"], "UnityEngine");
assert_eq!(params["version"], "2023.2.20f1");
}

#[test]
fn build_reference_call_find_symbol_minimal() {
let cmd = ReferenceCommand::FindSymbol {
name: "Foo".to_string(),
kind: None,
namespace: None,
version: None,
};
let (tool, params) = build_reference_call(&cmd);
assert_eq!(tool, "reference_find_symbol");
assert_eq!(params["name"], "Foo");
assert!(params.get("kind").is_none());
assert!(params.get("namespace").is_none());
assert!(params.get("version").is_none());
}

#[test]
fn build_reference_call_clean_defaults() {
let cmd = ReferenceCommand::Clean {
Expand Down
11 changes: 11 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,17 @@ pub enum ReferenceCommand {
#[arg(long)]
max_lines: Option<u32>,
},
/// Find a symbol (class/interface/struct/enum) in the cached reference index.
FindSymbol {
#[arg(long)]
name: String,
#[arg(long)]
kind: Option<String>,
#[arg(long)]
namespace: Option<String>,
#[arg(long)]
version: Option<String>,
},
/// Remove old UnityCsReference snapshots, keeping the newest entries.
Clean {
#[arg(long, default_value_t = 1)]
Expand Down
Loading
Loading