typst_ide/lib.rs
1//! Capabilities for Typst IDE support.
2
3mod analyze;
4mod complete;
5mod definition;
6mod docs;
7mod jump;
8mod matchers;
9mod tooltip;
10mod utils;
11
12pub use self::analyze::{analyze_expr, analyze_import, analyze_labels};
13pub use self::complete::{Completion, CompletionKind, autocomplete};
14pub use self::definition::{Definition, definition};
15pub use self::jump::{Jump, jump_from_click, jump_from_click_in_frame, jump_from_cursor};
16pub use self::matchers::{DerefTarget, NamedItem, deref_target, named_items};
17pub use self::tooltip::{Tooltip, tooltip};
18
19use ecow::EcoString;
20use typst::World;
21use typst::syntax::FileId;
22use typst::syntax::package::PackageSpec;
23
24/// Extends the `World` for IDE functionality.
25pub trait IdeWorld: World {
26 /// Turn this into a normal [`World`].
27 ///
28 /// This is necessary because trait upcasting is experimental in Rust.
29 /// See <https://github.com/rust-lang/rust/issues/65991>.
30 ///
31 /// Implementors can simply return `self`.
32 fn upcast(&self) -> &dyn World;
33
34 /// A list of all available packages and optionally descriptions for them.
35 ///
36 /// This function is **optional** to implement. It enhances the user
37 /// experience by enabling autocompletion for packages. Details about
38 /// packages from the `@preview` namespace are available from
39 /// `https://packages.typst.org/preview/index.json`.
40 fn packages(&self) -> &[(PackageSpec, Option<EcoString>)] {
41 &[]
42 }
43
44 /// Returns a list of all known files.
45 ///
46 /// This function is **optional** to implement. It enhances the user
47 /// experience by enabling autocompletion for file paths.
48 fn files(&self) -> Vec<FileId> {
49 vec![]
50 }
51}
52
53#[cfg(test)]
54mod tests;