diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-06-26 13:57:21 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-06-27 18:40:17 +0200 |
| commit | 7b92bd7c340d9f9c094ed2fa57912049317d9b20 (patch) | |
| tree | b91399526ba94d87309d09d864df2935dd7a4d0a /src/ide | |
| parent | 9c7f31870b4e1bf37df79ebbe1df9a56df83d878 (diff) | |
Basic package management
Diffstat (limited to 'src/ide')
| -rw-r--r-- | src/ide/analyze.rs | 20 | ||||
| -rw-r--r-- | src/ide/jump.rs | 11 |
2 files changed, 11 insertions, 20 deletions
diff --git a/src/ide/analyze.rs b/src/ide/analyze.rs index ba3a9b78..55ec8281 100644 --- a/src/ide/analyze.rs +++ b/src/ide/analyze.rs @@ -1,5 +1,3 @@ -use std::path::PathBuf; - use comemo::Track; use ecow::EcoString; @@ -7,7 +5,6 @@ use crate::doc::Frame; use crate::eval::{eval, Module, Route, Tracer, Value}; use crate::model::{Introspector, Label}; use crate::syntax::{ast, LinkedNode, Source, SyntaxKind}; -use crate::util::PathExt; use crate::World; /// Try to determine a set of possible values for an expression. @@ -42,7 +39,7 @@ pub fn analyze_expr(world: &(dyn World + 'static), node: &LinkedNode) -> Vec<Val world.track(), route.track(), tracer.track_mut(), - world.main(), + &world.main(), ) .and_then(|module| { typst::model::typeset( @@ -66,18 +63,11 @@ pub fn analyze_import( source: &Source, path: &str, ) -> Option<Module> { - let full: PathBuf = if let Some(path) = path.strip_prefix('/') { - world.root().join(path).normalize() - } else if let Some(dir) = source.path().parent() { - dir.join(path).normalize() - } else { - path.into() - }; let route = Route::default(); let mut tracer = Tracer::default(); - let id = world.resolve(&full).ok()?; - let source = world.source(id); - eval(world.track(), route.track(), tracer.track_mut(), source).ok() + let id = source.id().join(path).ok()?; + let source = world.source(id).ok()?; + eval(world.track(), route.track(), tracer.track_mut(), &source).ok() } /// Find all labels and details for them. @@ -112,7 +102,7 @@ pub fn analyze_labels( let split = output.len(); // Bibliography keys. - for (key, detail) in (items.bibliography_keys)(world.track(), introspector.track()) { + for (key, detail) in (items.bibliography_keys)(introspector.track()) { output.push((Label(key), detail)); } diff --git a/src/ide/jump.rs b/src/ide/jump.rs index 42ed2ab5..14a82e26 100644 --- a/src/ide/jump.rs +++ b/src/ide/jump.rs @@ -3,16 +3,17 @@ use std::num::NonZeroUsize; use ecow::EcoString; use crate::doc::{Destination, Frame, FrameItem, Meta, Position}; +use crate::file::FileId; use crate::geom::{Geometry, Point, Size}; use crate::model::Introspector; -use crate::syntax::{LinkedNode, Source, SourceId, Span, SyntaxKind}; +use crate::syntax::{LinkedNode, Source, Span, SyntaxKind}; use crate::World; /// Where to [jump](jump_from_click) to. #[derive(Debug, Clone, Eq, PartialEq)] pub enum Jump { /// Jump to a position in a source file. - Source(SourceId, usize), + Source(FileId, usize), /// Jump to an external URL. Url(EcoString), /// Jump to a point on a page. @@ -21,9 +22,9 @@ pub enum Jump { impl Jump { fn from_span(world: &dyn World, span: Span) -> Option<Self> { - let source = world.source(span.source()); + let source = world.source(span.id()).ok()?; let node = source.find(span)?; - Some(Self::Source(source.id(), node.offset())) + Some(Self::Source(span.id(), node.offset())) } } @@ -78,7 +79,7 @@ pub fn jump_from_click( Size::new(width, text.size), click, ) { - let source = world.source(span.source()); + let source = world.source(span.id()).ok()?; let node = source.find(span)?; let pos = if node.kind() == SyntaxKind::Text { let range = node.range(); |
