pub struct Declaration {
pub path: FilePath,
pub source: String,
pub tree: Tree,
pub hash: ContentHash,
pub has_error: bool,
/* private fields */
}Expand description
A declaration file this run has read and parsed.
Fields§
§path: FilePathWhere it was read from, relative to the project root.
source: StringIts text, which every byte range in tree indexes.
tree: TreeIts parse.
hash: ContentHashWhat its bytes hashed to when it was read.
Compared, within a run, against the hash of the bytes the asking file’s own
FileAccess reads: two accesses over one path can see two different files when the
file is rewritten mid-run, which is routine under --watch, and serving this parse
against the other access’s hash would write a cache entry that describes neither
version. See BuiltinProvider::declaration. Load-bearing across requests too: a
provider held for a session (#191) drops an entry whose hash moved.
has_error: boolWhether its parse carries a fault anywhere — an ERROR node, or a MISSING token
the parser inserted where one was expected. Node::has_error at the root counts
both; an unclosed brace produces the second and no ERROR at all.
tree_sitter::Parser::parse answers a tree for any UTF-8 input, so a file this
provider could not really read is indistinguishable from one it read cleanly unless
the question is asked here. The arms still answer whatever the tree does hold — a
declaration outside the damaged span is a real declaration — and it is complete()
that turns this into the honest label on a partial answer.
The per-declaration granularity is the reached node’s own has_error(), asked
by the walk of the declaration it ends at; this whole-file flag is what a nameless
import keeps, and what a name the walk cannot follow to a declaration falls back to.
Implementations§
Source§impl Declaration
impl Declaration
Sourcepub fn parse(
path: FilePath,
source: String,
parser: &mut Parser,
resolver: Arc<dyn BindingResolver>,
) -> Option<Self>
pub fn parse( path: FilePath, source: String, parser: &mut Parser, resolver: Arc<dyn BindingResolver>, ) -> Option<Self>
Parse a declaration file that has already been read through a tracked access.
Takes the parser rather than making one: a provider owns exactly one for the run, and a constructor that made its own would put a second parser behind an API that reads like it could not.
Trait Implementations§
Source§impl Debug for Declaration
impl Debug for Declaration
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
source is summarized rather than printed, the same call the oracle’s own Debug
makes: a whole declaration file in every log line the value appears in is not one
anybody can read, and its length identifies which file this is as well as the bytes do.