typst_analyzer_analysis/
lib.rs1#![deny(
2 clippy::unwrap_used,
3 clippy::panicking_unwrap,
4 clippy::or_then_unwrap,
5 clippy::get_unwrap,
6 unreachable_pub
7)]
8
9mod actions;
10pub mod bibliography;
11pub mod completion;
12mod diagnostics;
13pub mod dict;
14mod hints;
15pub mod node;
16pub mod definition;
17
18pub use completion::resources::*;
19pub use diagnostics::handle::*;
20pub use hints::handle::*;
21
22#[macro_export]
36macro_rules! typ_logger {
37 ($($args:tt)*) => {{
38 {
39 use std::io::Write;
40 use anyhow::{Context, Result};
41
42 fn log_message(msg: &str) -> Result<()> {
43 let log_dir = dirs::cache_dir()
44 .ok_or_else(|| anyhow::anyhow!("Cache directory not found"))?
45 .join("typst-analyzer");
46
47 if !log_dir.exists() {
49 std::fs::create_dir_all(&log_dir).context("Failed to create log directory")?;
50 }
51
52 let log_file = log_dir.join("state.log");
53 let mut file = std::fs::OpenOptions::new()
54 .append(true)
55 .create(true)
56 .open(&log_file)
57 .context("Failed to open log file")?;
58
59 writeln!(file, "{}", msg).context("Failed to write to log file")?;
60 Ok(())
61 }
62
63 let msg = format!($($args)*);
64 if let Err(e) = log_message(&msg) {
65 eprintln!("Failed to log message: {e:?}");
66 }
67 }
68 }};
69}