nocturne 0.0.1

Code analyzer
Documentation
use judge::rust::RustJudge;
use judge::{Judge, Position};

fn main() {
    let judge = RustJudge::new();

    // Example 1: Parse valid Rust code
    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);
        }
    }

    // Example 2: Find all symbols
    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),
    }

    // Example 3: Parse invalid Rust code
    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);
        }
    }

    // Example 4: Get completions
    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),
    }

    // Example 5: Find symbol at position
    println!("\nExample 5: Symbol at Position");
    let position = Position {
        line: 2,
        column: 15,
    }; // Should be around "Person"
    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),
    }
}