get_template_instances
Find all concrete instantiations of a C/C++ class or function template across translation units, with full type signatures, to resolve specializations that text search misses.
Instructions
Find all template instantiations for a C/C++ class or function template — libclang template-aware lookup. Finds concrete instantiations spread across all translation units, each with its full type signature. Text-based search cannot resolve template specializations across translation units.
Returns concrete instantiations of the template — each with its full type
signature (e.g. Callback<void(int)>). They are nested in the
instances list of one dict that describes the template itself.
Uses the template_usr column populated during indexing via libclang's
cursor.specialized_template.
Known limitation: libclang's specialized_template does not
reliably resolve implicit instantiations or template methods of
template classes. Header-only templates (e.g. RingBuffer<T>)
may report zero instances even when used in the codebase. Explicit
specializations and class/struct instantiations are detected more
reliably than method-level instantiations.
For finding the template declaration itself use lookup_symbol.
Read-only. No side effects.
Args:
template_name: Template name to find instantiations for.
E.g. 'Callback' or 'mbed::Callback'.
project_root: Project root. Auto-detected if omitted.
project: Project name or project_id — call list_projects to get them. Use
it to ask about a project that is not the project of the current
directory. It is an alternative to project_root, which takes a root
path. Give one of the two, not both.
limit: Maximum results (default 50, max 200).
offset: Skip this many instances. Reads the next page; the page
notice names the offset to use.
variant: Variant of the build (a board, or a PlatformIO
environment). On a project of more than one build, give the
arguments of one build as the refusal lists them: the
variant, the image, or the two. fw-context does not select a
build. One query answers for ONE build.
image: Image of the build: a separate program, such as the
application or the bootloader. Give it when the build has an
image name.
Returns:
list[dict]: the page notice {total, offset, shown, more, hint}
for the instances, then one element wrapping the template
declaration:
{name, qualified_name, kind, file, line, is_definition,
signature, instances (list of dicts, each with name,
qualified_name, kind, file, line, signature, is_definition — one
page of them), instance_count (int — all instances, as total)}
A page after the last instance gives one ``info`` dict that names
the total.
A dict with ``error`` means that the name was not found, is not a
template, or the query failed — check that key first. When a file
of the answer changed after the last index run, a ``warning`` dict
comes first.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| image | No | Image of the build: a separate program, such as the application or the bootloader. On a project of more than one build, give it when that build has an image name, as the refusal lists it. | |
| limit | No | Maximum results (default 50, max 200). | |
| offset | No | Skip this many instances. Reads the next page of a template with many instances. | |
| project | No | Project name or project_id — call list_projects to get them. Use it to ask about a project that is not the project of the current directory. It is an alternative to project_root, which takes a root path. Give one of the two, not both. | |
| variant | No | Variant of the build (a board, or a PlatformIO environment). On a project of more than one build, give the arguments of one build as the refusal lists them: the variant, the image, or the two. fw-context does not select a build for you. One query answers for ONE build. | |
| project_root | No | Project root. Auto-detected if omitted. This field also accepts a project name or a project_id, but project is the clear field for those. | |
| template_name | Yes | Template name to find instantiations for. E.g. 'Callback' or 'mbed::Callback'. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |