vvv_core/oracle.rs
1//! A second opinion on what a token refers to, from something that knows
2//! more than syntax — a compiler, a language server, an index. The graph
3//! judges every token by the file's imports and the layout; where that
4//! leaves a token unresolved, an oracle may say what it is.
5
6use crate::paths::RelPath;
7use std::path::Path;
8
9use crate::text::Span;
10
11/// Where a declaration is: the file and the span of its name, both as the
12/// workspace spells them (relative paths).
13#[derive(Debug, Clone, PartialEq, Eq)]
14pub struct Referent {
15 pub path: RelPath,
16 pub name_span: Span,
17}
18
19/// Something that can say what an identifier refers to. Asked one token at
20/// a time, only for tokens the graph could not judge, and never trusted
21/// blindly: the engine maps the answer onto a declaration it knows before
22/// it counts. Implementations are free to answer `None` for anything.
23pub trait Oracle: Send + Sync {
24 /// The declaration the identifier at `span` in `file` refers to, when
25 /// the oracle knows.
26 fn refers(&self, file: &Path, span: Span) -> Option<Referent>;
27}