Skip to main content

Declaration

Struct Declaration 

Source
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: FilePath

Where it was read from, relative to the project root.

§source: String

Its text, which every byte range in tree indexes.

§tree: Tree

Its parse.

§hash: ContentHash

What 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: bool

Whether 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

Source

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

Source§

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.