Skip to main content

definition_across_files

Function definition_across_files 

Source
pub fn definition_across_files(
    index: &ProjectIndex,
    declaring: &mut dyn FnMut(&Path) -> Option<FileView>,
    scopes: &ScopeTree,
    root: &CppSyntaxNode,
    path: &Path,
    offset: usize,
) -> Known<ProjectDefinition>
Expand description

Which declaration something refers to, using both layers.

The entry point a feature should call, and the reason it exists rather than each caller composing the two: C++ resolves a name in a fixed order, and getting that order wrong is a jump to the wrong file rather than an error. The order is:

1. this file's scopes        — a local shadows a header's declaration, always
2. this file's own top-level — a declaration written here is not the header's
3. the headers it includes   — reached through the include graph

§What it takes, and why each half is a reference

scopes and root are the file’s own analysis, which crate::build_scopes and the parser produce — the caller has them because it just parsed the file. The index holds the other files. Neither is derivable from the other: the index has no scopes for the open buffer, and the scopes know nothing outside it.

§The two reasons that reach step 3, and the one that does not

UnknownReason::NotDeclaredHere means the name is not in this file, which is exactly what step 3 is for. UnknownReason::Ambiguous does not mean that: the name is here, more than once, and looking in the headers would be answering a different question. So it stops.

Everything else stops too — a name that could not be read, a conditional the analysis cannot evaluate — for the same reason: the failure is not “not here”.