Add host-configurable language service
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
use crate::{Engine, ImportLoader, Result};
|
||||
|
||||
/// Host-owned configuration shared by runtime and language tooling.
|
||||
///
|
||||
/// Implementations create the import loader and install global bindings on a
|
||||
/// fresh engine. Calling [`HostEnvironment::create_engine`] therefore gives
|
||||
/// every consumer the same Decodal execution environment.
|
||||
pub trait HostEnvironment {
|
||||
type Loader: ImportLoader;
|
||||
|
||||
fn create_loader(&self) -> Self::Loader;
|
||||
|
||||
fn configure_engine(&self, _engine: &mut Engine<Self::Loader>) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn create_engine(&self) -> Result<Engine<Self::Loader>> {
|
||||
let mut engine = Engine::new(self.create_loader());
|
||||
self.configure_engine(&mut engine)?;
|
||||
Ok(engine)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: HostEnvironment + ?Sized> HostEnvironment for &T {
|
||||
type Loader = T::Loader;
|
||||
|
||||
fn create_loader(&self) -> Self::Loader {
|
||||
T::create_loader(*self)
|
||||
}
|
||||
|
||||
fn configure_engine(&self, engine: &mut Engine<Self::Loader>) -> Result<()> {
|
||||
T::configure_engine(*self, engine)
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ pub mod ast;
|
||||
pub mod constraints;
|
||||
pub mod diagnostic;
|
||||
pub mod embedding;
|
||||
pub mod environment;
|
||||
pub mod eval;
|
||||
mod lexer;
|
||||
pub mod module;
|
||||
@@ -20,6 +21,7 @@ pub use constraints::normalize_constraints;
|
||||
pub use decodal_derive::Decodal;
|
||||
pub use diagnostic::{Diagnostic, DiagnosticKind, Result};
|
||||
pub use embedding::{HostField, HostValue};
|
||||
pub use environment::HostEnvironment;
|
||||
pub use eval::{Engine, format_diagnostic_with};
|
||||
pub use module::{EmptyLoader, ImportLoader, LoadedImport, LoadedSource, LoadedValue, Module};
|
||||
pub use parser::{ParseOutput, Parser, SourceForm, parse_source, parse_source_with_source_id};
|
||||
|
||||
Reference in New Issue
Block a user