From af7fe4d76083c597ec2198a73383b9e3899d75ea Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 17 Mar 2023 16:27:40 +0100 Subject: Hover and autocomplete in show rules --- cli/src/main.rs | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'cli/src') diff --git a/cli/src/main.rs b/cli/src/main.rs index 65b21e22..b7cac1ee 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -229,12 +229,11 @@ fn compile(command: CompileCommand) -> StrResult<()> { /// Compile a single time. fn compile_once(world: &mut SystemWorld, command: &CompileCommand) -> StrResult<()> { status(command, Status::Compiling).unwrap(); - world.reset(); - let main = world.resolve(&command.input).map_err(|err| err.to_string())?; - let source = world.source(main); + world.reset(); + world.main = world.resolve(&command.input).map_err(|err| err.to_string())?; - match typst::compile(world, source) { + match typst::compile(world) { // Export the PDF. Ok(document) => { let buffer = typst::export::pdf(&document); @@ -372,6 +371,7 @@ struct SystemWorld { hashes: RefCell>>, paths: RefCell>, sources: FrozenVec>, + main: SourceId, } /// Holds details about the location of a font and lazily the font itself. @@ -401,6 +401,7 @@ impl SystemWorld { hashes: RefCell::default(), paths: RefCell::default(), sources: FrozenVec::new(), + main: SourceId::detached(), } } } @@ -414,6 +415,25 @@ impl World for SystemWorld { &self.library } + fn main(&self) -> &Source { + self.source(self.main) + } + + fn resolve(&self, path: &Path) -> FileResult { + self.slot(path)? + .source + .get_or_init(|| { + let buf = read(path)?; + let text = String::from_utf8(buf)?; + Ok(self.insert(path, text)) + }) + .clone() + } + + fn source(&self, id: SourceId) -> &Source { + &self.sources[id.into_u16() as usize] + } + fn book(&self) -> &Prehashed { &self.book } @@ -434,21 +454,6 @@ impl World for SystemWorld { .get_or_init(|| read(path).map(Buffer::from)) .clone() } - - fn resolve(&self, path: &Path) -> FileResult { - self.slot(path)? - .source - .get_or_init(|| { - let buf = read(path)?; - let text = String::from_utf8(buf)?; - Ok(self.insert(path, text)) - }) - .clone() - } - - fn source(&self, id: SourceId) -> &Source { - &self.sources[id.into_u16() as usize] - } } impl SystemWorld { -- cgit v1.2.3