-
|
code snippet: fn main() {
let source_text = r"import React from 'react';
/**
* A simple counter component
*/
export const Counter: React.FC = () => {
const [count, setCount] = React.useState(0);
return (
<div class='p-2 m-3 w-full hover:bg-red *:text-sm'>
<p class='text-blue'>Count: {count}</p>
<button class='w-1/2 border' onClick={() => setCount(count + 1)}>Increment</button>
<button class={'w-2/3 border border-pink'} onClick={() => setCount(count - 1)}>Decrement</button>
</div>
)
}";
let allocator = Allocator::default();
let source_type = SourceType::from_path("Counter.tsx").unwrap();
let parsed = Parser::new(&allocator, &source_text, source_type).parse();
let mut program = parsed.program;
let mut visitor = MyVisitor::default();
visitor.visit_program(&mut program);
}
#[derive(Default)]
struct MyVisitor {
line_width: u32,
}
impl<'a> VisitMut<'a> for MyVisitor {
fn visit_jsx_attribute(&mut self, it: &mut JSXAttribute<'a>) {
if it.name.get_identifier().name == "class" {
let value = it.value.as_ref().unwrap();
match value {
StringLiteral(string_literal) => {
println!("{}", string_literal.value);
}
ExpressionContainer(jsxexpression_container) => {}
_ => {}
}
}
}
}I want to get every classname offset by line, e.g. I want to get the line offset of |
Beta Was this translation helpful? Give feedback.
Answered by
Sysix
Oct 28, 2025
Replies: 1 comment
-
|
You can use Example from the language_server: oxc/crates/oxc_language_server/src/linter/error_with_position.rs Lines 190 to 193 in 1611b4f |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
liuhq
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use
oxc_data_structureswith the rope feature flag:https://github.com/oxc-project/oxc/blob/main/crates/oxc_data_structures/src/rope.rs#L7
Example from the language_server:
oxc/crates/oxc_language_server/src/linter/error_with_position.rs
Lines 190 to 193 in 1611b4f