Getting line numbers from Span
#2734
Closed
liangchunn
started this conversation in
Feature Request
Replies: 2 comments
-
Hi, my approach to this problem fn get_line_number(source_text: &str, offset: usize) -> usize {
source_text[..offset].lines().count()
} And use this like this fn visit_call_expression(&mut self, it: &mut CallExpression<'a>) {
let line = get_line_number(&self.source_text, it.span.start.try_into().unwrap());
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
Please also see #7764 - something that helps with this was merged today. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I'm writing a program uses
oxc_ast::Visit::enter_node
to visit the AST, and filters out nodes that I want and gets its respectiveSpan
s. How do I correlate theSpan
s back to the source code's line number?I've tried using
oxc_codegen
, but the returningSourceMap
doesn't have any functions that acceptSpan.start
and/orSpan.end
s.Minimal example:
The program outputs:
Beta Was this translation helpful? Give feedback.
All reactions