From 48a871186b4659fd5948ca011773593323267f64 Mon Sep 17 00:00:00 2001 From: jess Date: Sat, 30 May 2026 20:55:33 -0700 Subject: [PATCH] syntax highlighting editor exports --- viewport/src/editor/eval.rs | 8 ++++---- viewport/src/editor/state.rs | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/viewport/src/editor/eval.rs b/viewport/src/editor/eval.rs index 76e68cd..69c4018 100644 --- a/viewport/src/editor/eval.rs +++ b/viewport/src/editor/eval.rs @@ -399,7 +399,7 @@ impl super::EditorState { pub(super) fn build_eval_interpreter(&self, block_idx: usize) -> acord_core::interp::Interpreter { use acord_core::interp; - let mut eval_interp = interp::Interpreter::new(); + let mut eval_interp = self.new_eval_interpreter(); let block_id = match self.layout.get(block_idx) { Some(&id) => id, None => return eval_interp, @@ -451,7 +451,7 @@ impl super::EditorState { return interp::ModuleExports::default(); } - let mut interp = interp::Interpreter::new(); + let mut interp = self.new_eval_interpreter(); if !module.is_root { if let Some(root) = self.modules.iter().find(|m| m.is_root) { @@ -541,7 +541,7 @@ impl super::EditorState { }); if let Some(submod) = submodule_match { - let mut nested = interp::Interpreter::new(); + let mut nested = self.new_eval_interpreter(); for d in interp::extract_use_declarations(&clean) { self.apply_use_decl(&d, visited, &mut nested); } @@ -557,7 +557,7 @@ impl super::EditorState { return; } - let mut nested = interp::Interpreter::new(); + let mut nested = self.new_eval_interpreter(); for d in interp::extract_use_declarations(&clean) { self.apply_use_decl(&d, visited, &mut nested); } diff --git a/viewport/src/editor/state.rs b/viewport/src/editor/state.rs index 84f31d1..1c3ac78 100644 --- a/viewport/src/editor/state.rs +++ b/viewport/src/editor/state.rs @@ -115,6 +115,8 @@ pub struct EditorState { pub(super) heavy_token: u64, /// deferred-rebuild arm; set on edit, cleared on debounce fire. pub(super) heavy_pending: bool, + /// setup applied to every interpreter the editor builds for eval. + pub(super) interp_setup: Option>, } impl EditorState { @@ -184,9 +186,28 @@ impl EditorState { syntax_rules: crate::syntax::SyntaxRules::cordial(), heavy_token: 0, heavy_pending: false, + interp_setup: None, } } + /// installs a routine run on each fresh eval interpreter — register hooks, + /// provide shared state, seed vars, add module paths. + pub fn set_interpreter_setup(&mut self, setup: F) + where + F: Fn(&mut acord_core::interp::Interpreter) + 'static, + { + self.interp_setup = Some(std::rc::Rc::new(setup)); + } + + /// fresh interpreter with the registered project setup applied. + pub(super) fn new_eval_interpreter(&self) -> acord_core::interp::Interpreter { + let mut i = acord_core::interp::Interpreter::new(); + if let Some(setup) = &self.interp_setup { + setup(&mut i); + } + i + } + /// replaces the active syntax rule set. pub fn set_syntax_rules(&mut self, rules: crate::syntax::SyntaxRules) { self.syntax_rules = rules;