diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-03-11 23:28:35 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-03-11 23:29:32 +0100 |
| commit | ca6edf5283c258d8410134d678347977cb273cdd (patch) | |
| tree | b2b46ba70c054b0cbdefa06edbc5fd999cddb1fa /src/syntax/source.rs | |
| parent | 1a390deaea040191cf0e5937bd8e1427b49db71b (diff) | |
Jump to source and preview
Diffstat (limited to 'src/syntax/source.rs')
| -rw-r--r-- | src/syntax/source.rs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/syntax/source.rs b/src/syntax/source.rs index f00d779b..607a2603 100644 --- a/src/syntax/source.rs +++ b/src/syntax/source.rs @@ -9,7 +9,7 @@ use comemo::Prehashed; use unscanny::Scanner; use super::ast::Markup; -use super::{is_newline, parse, reparse, Span, SyntaxNode}; +use super::{is_newline, parse, reparse, LinkedNode, Span, SyntaxNode}; use crate::diag::SourceResult; use crate::util::{PathExt, StrExt}; @@ -149,13 +149,20 @@ impl Source { self.lines.len() } + /// Find the node with the given span. + /// + /// Panics if the span does not point into this source file. + pub fn find(&self, span: Span) -> LinkedNode<'_> { + LinkedNode::new(&self.root) + .find(span) + .expect("span does not point into this source file") + } + /// Map a span that points into this source file to a byte range. /// /// Panics if the span does not point into this source file. pub fn range(&self, span: Span) -> Range<usize> { - self.root - .range(span, 0) - .expect("span does not point into this source file") + self.find(span).range() } /// Return the index of the UTF-16 code unit at the byte index. |
