get_template_instances
Find concrete instantiations of a C/C++ template across all translation units, each with its full type signature, 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)>). The template declaration itself
is also returned as the first result when found.
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).
variant: Build variant (multi-build project). Omit to use
default_variant. One query answers for ONE build.
image: Sysbuild image within the variant. Required when the
variant holds several: each image is a separate program.
Returns: list[dict] with 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), instance_count (int)}
No match gives ``[]``. One dict with ``error`` means the query
failed — check that key first.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| image | No | Sysbuild image within the variant. Required when the variant holds several: each image is a separate program. | |
| limit | No | Maximum results (default 50, max 200). | |
| 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 | Build variant (multi-build project). Omit to use default_variant. 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 |