summaryrefslogtreecommitdiff
path: root/src/ide
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-03-21 12:55:39 +0100
committerLaurenz <laurmaedje@gmail.com>2023-03-21 12:55:39 +0100
commitc913271b2965027953c71a0b8f85a8c7cb802444 (patch)
tree5b126c4c594a722941d1a690b689cd439d388aa2 /src/ide
parent69136b74dc0026bcac09997569a172ba0a5083b5 (diff)
Fix crash for jump to outdated span
Diffstat (limited to 'src/ide')
-rw-r--r--src/ide/jump.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/ide/jump.rs b/src/ide/jump.rs
index d123ac06..fc98747c 100644
--- a/src/ide/jump.rs
+++ b/src/ide/jump.rs
@@ -20,10 +20,10 @@ pub enum Jump {
}
impl Jump {
- fn from_span(world: &dyn World, span: Span) -> Self {
+ fn from_span(world: &dyn World, span: Span) -> Option<Self> {
let source = world.source(span.source());
- let node = source.find(span);
- Self::Source(source.id(), node.offset())
+ let node = source.find(span)?;
+ Some(Self::Source(source.id(), node.offset()))
}
}
@@ -78,7 +78,7 @@ pub fn jump_from_click(
click,
) {
let source = world.source(glyph.span.source());
- let node = source.find(glyph.span);
+ let node = source.find(glyph.span)?;
let pos = if node.kind() == SyntaxKind::Text {
let range = node.range();
let mut offset = range.start + usize::from(glyph.offset);
@@ -99,12 +99,12 @@ pub fn jump_from_click(
FrameItem::Shape(shape, span) => {
let Geometry::Rect(size) = shape.geometry else { continue };
if is_in_rect(pos, size, click) {
- return Some(Jump::from_span(world, *span));
+ return Jump::from_span(world, *span);
}
}
FrameItem::Image(_, size, span) if is_in_rect(pos, *size, click) => {
- return Some(Jump::from_span(world, *span));
+ return Jump::from_span(world, *span);
}
_ => {}