use judge::rust::RustJudge;
use judge::{Judge, Position};
fn main() {
let judge = RustJudge::new();
println!("Example 1: Valid Rust Code");
let valid_source = r#"
struct Person {
name: String,
age: u32,
}
impl Person {
fn new(name: String, age: u32) -> Self {
Self { name, age }
}
fn greet(&self) {
println!("Hello, I'm {} and I'm {} years old!", self.name, self.age);
}
}
fn main() {
let person = Person::new("Alice".to_string(), 30);
person.greet();
}
"#;
let diagnostics = judge.diagnostics(valid_source);
if diagnostics.is_empty() {
println!("✓ No errors found!");
} else {
println!("✗ Errors:");
for diag in &diagnostics {
println!(" {}", diag);
}
}
println!("\nExample 2: Find Symbols");
match judge.symbols(valid_source) {
Ok(symbols) => {
println!("Found {} symbols:", symbols.len());
for symbol in &symbols {
println!(
" {:?} '{}' at {}:{} - {}:{}",
symbol.kind,
symbol.name,
symbol.range.start.line,
symbol.range.start.column,
symbol.range.end.line,
symbol.range.end.column
);
if let Some(detail) = &symbol.detail {
println!(" Detail: {}", detail);
}
}
}
Err(e) => println!("Error: {}", e),
}
println!("\nExample 3: Invalid Rust Code");
let invalid_source = r#"
fn broken_function( {
println!("This won't compile");
}
"#;
let diagnostics = judge.diagnostics(invalid_source);
if diagnostics.is_empty() {
println!("✓ No errors found!");
} else {
println!("✗ Errors:");
for diag in &diagnostics {
println!(" {}", diag);
}
}
println!("\nExample 4: Completions");
match judge.completions(valid_source, Position { line: 1, column: 0 }) {
Ok(completions) => {
println!("Available completions:");
for item in &completions {
println!(" {} - {:?}", item.label, item.kind);
if let Some(detail) = &item.detail {
println!(" {}", detail);
}
}
}
Err(e) => println!("Error: {}", e),
}
println!("\nExample 5: Symbol at Position");
let position = Position {
line: 2,
column: 15,
}; match judge.symbol_at_position(valid_source, position) {
Ok(Some(symbol)) => {
println!(
"Symbol at {}:{}: {:?} '{}'",
position.line, position.column, symbol.kind, symbol.name
);
}
Ok(None) => println!("No symbol found at {}:{}", position.line, position.column),
Err(e) => println!("Error: {}", e),
}
}