summaryrefslogtreecommitdiff
path: root/crates/typst-ide/src/utils.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/typst-ide/src/utils.rs')
-rw-r--r--crates/typst-ide/src/utils.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/crates/typst-ide/src/utils.rs b/crates/typst-ide/src/utils.rs
index 903fb2f3..ad8ed6b5 100644
--- a/crates/typst-ide/src/utils.rs
+++ b/crates/typst-ide/src/utils.rs
@@ -3,7 +3,9 @@ use std::fmt::Write;
use comemo::Track;
use ecow::{eco_format, EcoString};
use typst::engine::{Engine, Route, Sink, Traced};
+use typst::foundations::Scope;
use typst::introspection::Introspector;
+use typst::syntax::{LinkedNode, SyntaxKind};
use typst::text::{FontInfo, FontStyle};
use crate::IdeWorld;
@@ -105,3 +107,21 @@ pub fn summarize_font_family<'a>(
detail
}
+
+/// The global definitions at the given node.
+pub fn globals<'a>(world: &'a dyn IdeWorld, leaf: &LinkedNode) -> &'a Scope {
+ let in_math = matches!(
+ leaf.parent_kind(),
+ Some(SyntaxKind::Equation)
+ | Some(SyntaxKind::Math)
+ | Some(SyntaxKind::MathFrac)
+ | Some(SyntaxKind::MathAttach)
+ );
+
+ let library = world.library();
+ if in_math {
+ library.math.scope()
+ } else {
+ library.global.scope()
+ }
+}