summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-03-17 16:27:40 +0100
committerLaurenz <laurmaedje@gmail.com>2023-03-17 18:18:47 +0100
commitaf7fe4d76083c597ec2198a73383b9e3899d75ea (patch)
treecb3b9766ee15dbfbecf7f9b9a2257859d7a7b3c7 /cli
parent6d64d3e8e9123f3fa8166c8b710e2b2c61ed5898 (diff)
Hover and autocomplete in show rules
Diffstat (limited to 'cli')
-rw-r--r--cli/src/main.rs43
1 files changed, 24 insertions, 19 deletions
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<HashMap<PathBuf, FileResult<PathHash>>>,
paths: RefCell<HashMap<PathHash, PathSlot>>,
sources: FrozenVec<Box<Source>>,
+ 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<SourceId> {
+ 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<FontBook> {
&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<SourceId> {
- 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 {