Languages¶
uh parses source files with tree-sitter grammars and lowers each file into a language-agnostic intermediate form (HIR): callables, call sites, types, fields and imports. A shared resolver links call sites to targets across the workspace. No compiler, language server or build step runs.
Supported languages¶
uh supports 11 languages. TypeScript and JavaScript count as one; C and C++ count as two, though one adapter handles both.
| Language | Files matched | Adapter id |
|---|---|---|
| Rust | .rs |
rust |
| Go | .go |
go |
| Java | .java |
java |
| Python | .py .pyi |
python |
| TypeScript / JavaScript | .ts .mts .cts, .tsx, .js .mjs .cjs, .jsx |
ts, tsx, js, jsx |
| C | .c .h |
cpp |
| C++ | .cc .cpp .cxx .hh .hpp .hxx |
cpp |
| Swift | .swift |
swift |
| Zig | .zig |
zig |
| Starlark | .bzl .star, and files named BUILD, BUILD.bazel, WORKSPACE, WORKSPACE.bazel, MODULE.bazel |
starlark |
| Protocol Buffers | .proto |
proto |
Files matching no adapter are skipped. Use the adapter id in --bridge-include / --bridge-exclude rules (see Bridge rules).
C files use the cpp id
.c and .h files use the C/C++ adapter, so their id is cpp. A bridge rule written as c matches nothing.
To see what uh extracts from a file, run uh parse:
$ uh parse examples/demo/c/checksum.c
examples/demo/c/checksum.c: package <none>
import L1: "checksum.h"
import L1: "checksum.h#impl"
fn L3-L19: acme_crc16
fn L21-L42: acme_verify_frame
call L37: acme_crc16()
...
examples/demo/ is a small project with one folder per language. Flags for uh parse and uh graph: CLI reference. Output formats: Graphs.
Support matrix¶
| Language | Call graph | Type graph | Scoped AST diff | Test files | Inline tests | OS-tagged files | Proto-generated names |
|---|---|---|---|---|---|---|---|
| Rust | yes | yes | yes | yes | yes | no | yes |
| Go | yes | yes | yes | yes | no | yes | yes |
| Java | yes | yes | yes | yes | no | no | yes |
| Python | yes | yes | yes | yes | no | no | no |
| TypeScript / JavaScript | yes | yes | yes | yes | no | no | no |
| C / C++ | yes | yes | yes | yes | no | yes | yes (C++) |
| Swift | yes | yes | yes | yes | yes | no | yes |
| Zig | yes | yes | yes | yes | yes | yes | no |
| Starlark | yes | yes | yes | yes | no | no | no |
| Protocol Buffers | yes | yes | no | yes | no | no | n/a |
- Call graph:
uh graph --layer calls(the default). - Type graph:
uh graph --layer types. Edges come from struct fields, embeds/extends, implements and type aliases, built from declarations only. Proto messages are structs; services are interfaces. Starlarkprovider(...)and module-levelstruct(...)bindings are types. - Scoped AST diff: the opt-in structural diff (
uh review --ast-diff). All grammars except Protocol Buffers are wired in. - Test files: path rules that mark test code (table below).
uh graph --exclude-testsdrops these files. - Inline tests: test code in a non-test file is marked per callable. Rust:
#[test]and items inside#[cfg(test)]. Swift:XCTestCasesubclasses and@Testdeclarations. Zig:test "..." { }blocks. - OS-tagged files: Files that build on only some operating systems never link to files whose OS set excludes theirs. Go:
_GOOS/_GOOS_GOARCHfile name suffixes and//go:build(or// +build) lines. C/C++: platform names in the file name or directory (foo_windows.cc,posix/). Zig: a file-levelpub fn available() boolgate onbuiltin.os.tag. - Proto-generated names: calls on code generated from a
.protofile link back to it (see Protocol Buffers bridge).
Test file rules¶
| Language | A file is test code when |
|---|---|
| Rust | it is under a tests/, benches/ or testdata/ directory, or its name ends in _test.rs or _tests.rs |
| Go | its name ends in _test.go |
| Java | it is under src/test/ or javatests/, or its name ends in Test.java or starts with Test; nothing under src/main/ is test code |
| Python | it is under a tests/ directory, or its name starts with test_ or ends in _test.py |
| TypeScript / JavaScript | it is under __tests__/, __mocks__/, test/, tests/ or test-d/, or its name contains .test. or .spec. |
| C / C++ | it is under test/ or tests/, or its stem ends in _test or starts with test_ |
| Swift | any parent directory name ends in Tests, or its name ends in Tests.swift or Test.swift |
| Zig | it is under a tests/ directory, or its name ends in _test.zig |
| Starlark | it is under tests/ or testdata/, or its name ends in _test.bzl or _tests.bzl |
| Protocol Buffers | its name ends in _test.proto |
How calls are resolved¶
Resolution is static. Each call site passes through four stages in order:
- Imports: a qualified call through an import (
fmt.Println,util.Helper) binds to that import, unless a local binding shadows the name. - Package-qualified calls: a qualified call into a workspace package or module binds to the callable there.
- Receiver methods: for
s.Run()ors.store.Save(), the receiver's type comes from local type propagation (declarations, assignments, fields, return types, generic arguments) and the method is looked up on that type and its bases. - Bare calls:
helper()binds to a local closure or function table, then the same file, then the same package or directory where the language allows it, then dot/glob imports and builtins.
A call that reaches nothing becomes an external boundary or an unresolved_internal entry with a reason such as unknown receiver type or method not found on receiver type. uh graph --strict fails if any unresolved internal call remains.
Import and module resolution¶
| Language | How an import maps to workspace files |
|---|---|
| Rust | crate::, self:: and super:: paths map to <m>.rs or <m>/mod.rs, then enclosing modules up to the crate root's lib.rs / main.rs. mod x; links x.rs or x/mod.rs when exactly one exists. Other crates resolve to workspace files when the crate is in the workspace. |
| Go | An import path names a package directory. Files in one directory share a package, so lowercase names are visible across them. go.mod module paths are read. |
| Java | Imports name packages and types, matched by key. A file's module is its declared package. On-demand imports (import com.foo.*;) put type names in scope. |
| Python | Candidates in order: package a/b/__init__.py, module a/b.py, then the package directory. A .pyi stub binds only when no source file exists. Relative imports start from the importer's package. Absolute imports are tried under ancestor source roots, the importer's own directory (not for stdlib names) and the repo root. |
| TypeScript / JavaScript | Relative specifiers (./util, ../a/b.js) map to files; a .js import also tries .ts / .tsx. Bare package specifiers are external. JavaScript files see and satisfy TypeScript declarations. |
| C / C++ | #include "x.h" searches the includer's directory first. A bare call binds to a function visible through the file's (transitive) includes, nearest include first. |
| Swift | import M maps to <ancestor>/Sources/M, nearest first. A file's module is its SwiftPM target directory. |
| Zig | @import("x.zig") resolves relative to the importing file. Imported declarations are reached only through the import binding. |
| Starlark | load("//pkg:f.bzl", ...) maps to pkg/f.bzl; :f.bzl maps to the loading file's directory, then each ancestor. Labels of other repositories (@repo//...) are external. |
| Protocol Buffers | import "a/b.proto"; is matched to the file path by the shared resolver. |
Per-language rules¶
The adapters tell the resolver how each language binds names.
| Language | Bare m() in a method means this.m() |
Self-calls dispatch to subclass overrides | Bare call may bind to a sibling file in the same directory | Bare call may bind to the workspace's only function of that name | Interfaces matched by |
|---|---|---|---|---|---|
| Rust | no | no | no | yes | declaration (impl Trait for) |
| Go | no | no | yes | no | method set, identical types |
| Java | yes | yes | no | no | declaration |
| Python | no | yes | no | no | method set |
| TypeScript / JavaScript | no | yes | no | no | method set |
| C / C++ | yes | no | yes | yes | method set |
| Swift | yes | yes | yes | yes | declaration |
| Zig | yes | no | no | no | method set |
| Starlark | no | no | no | no | method set |
| Protocol Buffers | no | no | no | no | method set |
Other language-specific behavior:
- Overloads: Python has none; a later
defof the same name replaces the earlier one. Java overloads accumulate across a class hierarchy; in C++ a member name hides all inherited overloads of that name. - Provided methods: in Rust, Java and Swift, a method missing on a resolved workspace type (trait default methods, derives, blanket impls,
java.lang.Object, protocol extensions) becomes an externalprovidedboundary, not an unresolved call. - Whole-module imports: in Java and Swift, an unresolved capitalized name (
Text("hi"),JSONDecoder().decode()) becomes an external boundary of the file's whole-module imports. - Glob imports: in Python a later
from m import *rebinds names an earlier one bound. Elsewhere two globs bringing in one name are ambiguous. - Starlark:
name = rule(implementation = _impl, ...)(alsoaspect,repository_rule,module_extension,macro,subrule,transition) is a callable that calls its implementation function. Loaded symbols resolve by original name in the loaded file, even when aliased. Nesteddefs are callables namedouter.inner.
Dispatch kinds¶
Each call-graph edge has a dispatch value. Graphs describes the JSON field.
dispatch |
Meaning |
|---|---|
direct |
Static call to a concrete function or method. |
dynamic_dispatch |
Interface, trait or virtual call to implementing types, when the interface is outside the workspace or the receiver admits only some implementations. |
non_virtual |
A call bound past overrides (super.m(), Base.m(self)): only the named method runs. |
override |
Not a call: from an overridable method or bodyless declaration to an override or implementation that may run instead. |
generated |
Through generated code: a gRPC stub method to the proto rpc, or a proto rpc to the workspace method that implements it. |
function_ref |
An indirect function-value reference (see Indirect function references). |
bridge |
Diff mode only. A synthesized edge across unchanged intermediate callables. |
Possible edges¶
An edge is certain when the call provably reaches the target. It is possible when the resolver found the target but cannot prove the call reaches it. Possible edges are kept, not dropped. Each carries exactly one reason from a closed set. In JSON, a possible edge has "confidence": "possible" and a reason; certain edges omit both.
reason |
Meaning |
|---|---|
ambiguous-overload |
Several overloads fit the call and none is preferred. |
dispatch-no-evidence |
The target is an interface implementer, and nothing shows the receiver can hold that type. |
fallback-name-match |
The target was found by name outside the call's scope: the workspace's only function of that name, or one in the same directory. |
unresolved-include |
The target is declared in a header whose include did not resolve. Defined in the set, but the current resolver does not emit it. |
alternative-definition |
Several definitions share the target's owner, name and signature (alternative platform branches, ImportError fallbacks, Zig comptime alternatives). Which one runs is unknown. |
reassignable-binding |
The call goes through a function value that may be reassigned: a package-level one (every Go package-level function value), or one of several bindings reaching the call. |
decorator-wrapped |
The call goes through a function wrapped by a non-marker decorator (Python); the wrapper may or may not call the body. |
external-shadowing |
A bare call bound to an enclosing class's method, which a same-named method on a supertype outside the workspace would shadow. |
union-member |
The receiver is annotated as a union (A \| B) whose members reach different targets; which member the value holds is unknown. |
In the web UI possible edges are drawn dashed; see Web UI.
External boundaries¶
A call leaving the workspace ends at an external boundary node (ext::...). Each boundary has a kind:
kind |
Meaning |
|---|---|
stdlib |
The language's standard library. |
dependency |
A third-party package not in the workspace, or a provided method (see above). |
interface |
An abstract workspace interface method with no workspace implementation. |
generated |
A generated member of a workspace proto type (a message accessor or builder method). |
uh graph --boundaries all (default) keeps every boundary, third-party drops standard-library ones, and none drops them all.
An import is standard library when:
| Language | Standard-library rule |
|---|---|
| Rust | the path starts with std, core, alloc or proc_macro |
| Go | the first path segment has no . (fmt, net/http) |
| Java | the path starts with java., javax. or sun. |
| Python | the top-level module is in the built-in stdlib module list |
| TypeScript / JavaScript | the specifier starts with node: |
| C / C++ | the header is in the built-in standard header list |
| Swift | the root module is a Swift standard library, Apple SDK or platform module |
| Zig | the import is std or builtin (or starts with std. / builtin.) |
| Starlark | the label starts with @bazel_tools// |
| Protocol Buffers | the path starts with google/protobuf/ |
Language builtins (len, sizeof, println!, common container methods) are not graph nodes.
Cross-language links¶
Protocol Buffers and gRPC¶
For each .proto file with a package, the proto adapter computes the names that protoc and the gRPC plugins generate in other languages. The resolver matches references in those languages against them.
| Target language | Generated names recognized |
|---|---|
| Java | protoc java_out and grpc-java classes, honoring java_package, java_outer_classname and java_multiple_files |
| Go | go_package types, FooClient, FooServer, UnimplementedFooServer, UnsafeFooServer |
| C++ | pkg::Msg (nested as pkg::Outer_Inner and pkg::Outer::Inner), pkg::Svc::Stub, StubInterface, Service, CallbackService |
| Rust | prost and tonic: pkg::Msg, pkg::svc_client::SvcClient, pkg::svc_server::{Svc, SvcServer} |
| Swift | swift-protobuf and grpc-swift 1.x: Pkg_Sub_Msg, honoring swift_prefix |
This produces generated edges in two directions:
- a call on a gRPC stub method goes to the proto
rpcit invokes; - a proto
rpcgoes to each workspace method that implements it, on a type whose base is the generated service base (JavaFooGrpc.FooImplBase, GoUnimplementedFooServer).
Other member calls on generated message types become generated external boundaries, not unresolved calls.
Names that depend on the .proto file's path are not generated: Python foo_pb2, C++ foo.pb.h and the default Java outer class FooProto. Python and TypeScript have no generated-name support.
Bridge rules¶
In diff mode, uh graph --bridges keeps only changed callables and adds bridge edges across unchanged ones between them. --bridge-include and --bridge-exclude filter those edges by language at each end. --bridge-exclude also drops matching direct cross-language edges.
| Rule | Matches |
|---|---|
<lang> |
any bridge with <lang> at either end |
<lang_a>:<lang_b> |
bridges between the two languages, either direction |
same |
bridges whose ends are in the same language |
cross |
bridges whose ends are in different languages |
Languages are adapter ids from the table above. Accepted aliases: rs for rust, py for python, typescript for ts, javascript for js, c++ / cc / cxx for cpp, bazel / bzl for starlark, protobuf for proto. Rules are case-insensitive.
Full flag details: CLI reference.
Starlark targets do not link to their sources
Starlark files resolve within Starlark: load() labels, rule implementation functions, providers and struct namespaces. A BUILD target does not link to the files in its srcs.
Indirect function references¶
uh review adds function_ref edges for functions used as values, not called:
- callbacks and higher-order function arguments;
- route and handler registrations;
- vtables and dispatch tables.
A table binding that holds workspace functions (WAKER_VTABLE, ROUTES, routeMap, TASKS) becomes its own node. The function using the table links to it, and the table links to each function it holds. One table propagates at most 32 targets.
This pass lexically scans source lines against workspace callables, using per-language comment and string rules. It runs when uh review builds the base and head graphs. uh graph output omits these edges.
The core resolver separately handles calls through local closures and function tables (stage 4 above). Calls through function values that may change get the reassignable-binding reason.
Known limits¶
- No type inference beyond local propagation. Receiver types come from declarations, assignments, fields, return types and generic arguments in the source. A receiver whose type cannot be read this way is reported as
unknown receiver type. - The type graph is structural. It records fields, embedding/extension, implementations and aliases.
- Macros are not expanded. Rust
macro_rules!definitions are callables, and item-position macro invocations whose body parses as items (cfg_feature! { ... }) are unwrapped; other macro bodies are not analyzed. A macro call that matches no workspacemacro_rules!and is not a known builtin is reported asunresolved macro. - C/C++ preprocessor branches are not evaluated. Declarations from all
#if/#elsebranches are read; same-signature alternatives producealternative-definitionedges. - C++ self-calls do not dispatch to overrides. Member functions are treated as non-virtual for
this->m()calls. - Swift
#if os(...)guards regions, not files, so Swift files carry no OS tags. - Proto generated names are computed from file contents only, not file paths (see above), and only for Java, Go, C++, Rust and Swift.
- Scoped AST diff is not available for
.protofiles.