Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Commit

Permalink
chore: upgrade to typst 0.5.0 (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
Enter-tainer committed Jun 10, 2023
1 parent 515f4ac commit 22bae1d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "typst-ws"
version = "0.4.0"
version = "0.5.0"
authors = ["The Typst Project Developers"]
edition = "2021"

Expand All @@ -13,8 +13,8 @@ bench = false
doc = false

[dependencies]
typst = { git = "https://github.com/typst/typst.git", tag = "v0.4.0"}
typst-library = { git = "https://github.com/typst/typst.git", tag = "v0.4.0" }
typst = { git = "https://github.com/typst/typst.git", tag = "v0.5.0"}
typst-library = { git = "https://github.com/typst/typst.git", tag = "v0.5.0" }
chrono = { version = "0.4", default-features = false, features = [
"clock",
"std",
Expand Down
6 changes: 5 additions & 1 deletion addons/vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ Add preview button

## 0.4.1

Makes the WebSocket connection retry itself when it is closed, with a delay of 1 second.
- Makes the WebSocket connection retry itself when it is closed, with a delay of 1 second.

## v0.5.0

- Upgrade to typst v0.5.0
6 changes: 5 additions & 1 deletion addons/vscode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,8 @@ Add preview button

### 0.4.1

Makes the WebSocket connection retry itself when it is closed, with a delay of 1 second.
- Makes the WebSocket connection retry itself when it is closed, with a delay of 1 second.

### v0.5.0

- Upgrade to typst v0.5.0
2 changes: 1 addition & 1 deletion addons/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"type": "git",
"url": "https://github.com/Enter-tainer/typst-preview-vscode"
},
"version": "0.4.1",
"version": "0.5.0",
"engines": {
"vscode": "^1.77.0"
},
Expand Down
26 changes: 23 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod args;

use chrono::Datelike;
use clap::Parser;
use codespan_reporting::diagnostic::{Diagnostic, Label};
use codespan_reporting::term::{self, termcolor};
Expand All @@ -14,7 +15,7 @@ use once_cell::unsync::OnceCell;
use same_file::Handle;
use serde::{Deserialize, Serialize};
use siphasher::sip128::{Hasher128, SipHasher};
use std::cell::{RefCell, RefMut};
use std::cell::{RefCell, RefMut, Cell};
use std::collections::HashMap;
use std::fs::{self, File};
use std::hash::Hash;
Expand All @@ -32,7 +33,7 @@ use tokio::sync::{Mutex, RwLock};
use tokio_tungstenite::tungstenite::Message;
use tokio_tungstenite::WebSocketStream;
use typst::diag::{FileError, FileResult, SourceError, StrResult};
use typst::eval::Library;
use typst::eval::{Library, Datetime};
use typst::font::{Font, FontBook, FontInfo, FontVariant};
use typst::geom::RgbaColor;
use typst::syntax::{Source, SourceId};
Expand Down Expand Up @@ -577,6 +578,7 @@ struct SystemWorld {
hashes: RefCell<HashMap<PathBuf, FileResult<PathHash>>>,
paths: RefCell<HashMap<PathHash, PathSlot>>,
sources: FrozenVec<Box<Source>>,
today: Cell<Option<Datetime>>,
main: SourceId,
}

Expand Down Expand Up @@ -614,6 +616,7 @@ impl SystemWorld {
hashes: RefCell::default(),
paths: RefCell::default(),
sources: FrozenVec::new(),
today: Cell::new(None),
main: SourceId::detached(),
}
}
Expand Down Expand Up @@ -644,7 +647,7 @@ impl World for SystemWorld {
}

fn source(&self, id: SourceId) -> &Source {
&self.sources[id.into_u16() as usize]
&self.sources[id.as_u16() as usize]
}

fn book(&self) -> &Prehashed<FontBook> {
Expand All @@ -667,6 +670,23 @@ impl World for SystemWorld {
.get_or_init(|| read(path).map(Buffer::from))
.clone()
}

fn today(&self, offset: Option<i64>) -> Option<Datetime> {
if self.today.get().is_none() {
let datetime = match offset {
None => chrono::Local::now().naive_local(),
Some(o) => (chrono::Utc::now() + chrono::Duration::hours(o)).naive_utc(),
};

self.today.set(Some(Datetime::from_ymd(
datetime.year(),
datetime.month().try_into().ok()?,
datetime.day().try_into().ok()?,
)?))
}

self.today.get()
}
}

impl SystemWorld {
Expand Down

0 comments on commit 22bae1d

Please sign in to comment.