diff options
author | Vincent Ambo <mail@tazj.in> | 2022-10-06T11·35+0300 |
---|---|---|
committer | tazjin <tazjin@tvl.su> | 2022-10-08T10·58+0000 |
commit | 70113407d2a30ab9ac71e933662f722f6dd1f149 (patch) | |
tree | 73cf23554ab238365f01b66b94f3653b01b6c1a6 /tvix | |
parent | 50baf0bcfc5ce29f7eed114535e7bb27ffd06cb6 (diff) |
refactor(tvix/eval): implement ToSpan directly for rnix::TextRange r/5058
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 <grfn@gws.fyi>
Diffstat (limited to 'tvix')
-rw-r--r-- | tvix/eval/src/spans.rs | 19 |
1 files changed, 9 insertions, 10 deletions
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) } } |