pub struct HostContext { /* private fields */ }Expand description
Host state for one file, shared with the functions installed on ctx.
Debug is hand-written: requiring it on BindingResolver would burden every language
implementation for the sake of one derive here.
Implementations§
Source§impl HostContext
impl HostContext
Sourcepub fn new(tree: Tree, source: String, file_path: &str) -> Self
pub fn new(tree: Tree, source: String, file_path: &str) -> Self
Build a context over a parsed file.
Sourcepub fn with_resolver_from(self, language: &dyn Language) -> Self
pub fn with_resolver_from(self, language: &dyn Language) -> Self
Attach whatever resolver a language provides, if any.
Sourcepub fn with_today(self, today: &str) -> Self
pub fn with_today(self, today: &str) -> Self
Supply the date rules see as ctx.today.
Fixed for the run by the caller, not read here: two files checked a millisecond apart
must not disagree about what day it is. Without one, ctx.today is absent rather than
empty — a rule comparing against undefined would silently take a branch nobody
intended, where a missing property is a TypeError naming what it reached for.
Sourcepub fn date_was_read(&self) -> bool
pub fn date_was_read(&self) -> bool
Whether anything read ctx.today while checking this file.
The caller needs this to decide whether the result may be cached across days.
Sourcepub fn with_language(self, language: Arc<dyn Language>) -> Self
pub fn with_language(self, language: Arc<dyn Language>) -> Self
Attach the grammar querySubtree and closestAncestor compile queries against.
Without one they are absent rather than present-and-failing. A rule reaching for them
then gets a TypeError naming the function, which is the truthful answer — a stub
returning nothing would look like a query that matched nothing.
Sourcepub fn with_resolver(self, resolver: Arc<dyn BindingResolver>) -> Self
pub fn with_resolver(self, resolver: Arc<dyn BindingResolver>) -> Self
Attach a binding resolver, enabling the import-resolution functions.
Without one, those functions return false or undefined rather than being
absent. A rule written against a language that has no resolver then behaves as
though nothing resolves, which is a truthful answer — where a missing function
would be a TypeError blamed on the rule.
Sourcepub fn with_file_access(self, files: Arc<FileAccess>) -> Self
pub fn with_file_access(self, files: Arc<FileAccess>) -> Self
Allow tracked reads of other files in the project.
Without one, readFile and fileExists are absent rather than present-and-failing.
A rule reaching for them then gets a TypeError naming the function, which is the
truthful answer — where a stub returning undefined would look like an empty project
and produce a rule that silently checks nothing.
Takes an Arc rather than an Rc so the same access can be handed to the
component engine’s context for the same file. Two memos over one file would let two
rules see a file rewritten between them differently, which is the determinism invariant
and not a tidiness question — see FileAccess’s own seen field.
Sourcepub fn arena(&self) -> &Rc<RefCell<NodeArena>>
pub fn arena(&self) -> &Rc<RefCell<NodeArena>>
The arena, for interning query captures before invoking a handler.
Sourcepub fn take_reports(&self) -> Vec<Report>
pub fn take_reports(&self) -> Vec<Report>
Take everything reported so far, leaving the context empty.
Sourcepub fn take_facts(&self) -> Vec<EmittedFact>
pub fn take_facts(&self) -> Vec<EmittedFact>
Take everything emitted so far, in emission order, leaving the context empty.
Trait Implementations§
Source§impl Clone for HostContext
impl Clone for HostContext
Source§fn clone(&self) -> HostContext
fn clone(&self) -> HostContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more