From 70113407d2a30ab9ac71e933662f722f6dd1f149 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Thu, 6 Oct 2022 14:35:18 +0300 Subject: refactor(tvix/eval): implement ToSpan directly for rnix::TextRange This logic was duplicated between the two rnix types before, but more crucially - it is also needed for correctly displaying the text ranges contained in syntax errors. Change-Id: Ifc6a521de1594d6ced9cba6274f1931df99b6634 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6870 Tested-by: BuildkiteCI Reviewed-by: grfn --- tvix/eval/src/spans.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'tvix') diff --git a/tvix/eval/src/spans.rs b/tvix/eval/src/spans.rs index c17ad2102ccf..9998e438b220 100644 --- a/tvix/eval/src/spans.rs +++ b/tvix/eval/src/spans.rs @@ -16,23 +16,22 @@ impl ToSpan for Span { } } +impl ToSpan for rnix::TextRange { + fn span_for(&self, file: &File) -> Span { + file.span + .subspan(u32::from(self.start()) as u64, u32::from(self.end()) as u64) + } +} + impl ToSpan for rnix::SyntaxToken { fn span_for(&self, file: &File) -> Span { - let rowan_span = self.text_range(); - file.span.subspan( - u32::from(rowan_span.start()) as u64, - u32::from(rowan_span.end()) as u64, - ) + self.text_range().span_for(file) } } impl ToSpan for rnix::SyntaxNode { fn span_for(&self, file: &File) -> Span { - let rowan_span = self.text_range(); - file.span.subspan( - u32::from(rowan_span.start()) as u64, - u32::from(rowan_span.end()) as u64, - ) + self.text_range().span_for(file) } } -- cgit 1.4.1