fn run_diff(args: &Args, config: &Config) -> Result<()> {
    let file_type = args.file_type.as_deref();
    let path_a = args.old.as_ref().unwrap();
    let path_b = args.new.as_ref().unwrap();

    // This looks a bit weird because the ast vectors and some other data reference data in the
    // AstVectorData structs. Because of that, we can't make a function that generates the ast
    // vectors in one shot.

    let ast_data_a = generate_ast_vector_data(path_a.to_path_buf(), file_type, &config.grammar)?;
    let ast_data_b = generate_ast_vector_data(path_b.to_path_buf(), file_type, &config.grammar)?;

    let diff_vec_a = generate_ast_vector(&ast_data_a);
    let diff_vec_b = generate_ast_vector(&ast_data_b);

    let (old_hunks, new_hunks) = ast::compute_edit_script(&diff_vec_a, &diff_vec_b);
    let params = DisplayParameters {
        old: DocumentDiffData {
            filename: &ast_data_a.path.to_string_lossy(),
            hunks: &old_hunks,
            text: &ast_data_a.text,
        },
        new: DocumentDiffData {
            filename: &ast_data_b.path.to_string_lossy(),
            hunks: &new_hunks,
            text: &ast_data_b.text,
        },
    };
    // Use a buffered terminal instead of a normal unbuffered terminal so we can amortize the cost of printing. It
    // doesn't really how frequently the terminal prints to stdout because the user just cares about the output at the
    // end, we don't care about how frequently the terminal does partial updates or anything like that. If the user is
    // curious about progress, they can enable logging and see when hunks are processed and written to the buffer.
    let mut buf_writer = BufWriter::new(Term::stdout());
    config.formatting.print(&mut buf_writer, &params)?;
    // Just in case we forgot to flush anything in the `print` function
    buf_writer.flush()?;
    Ok(())
}
/// Take the diff of two files
Take the diff of two files
Take the diff of two files
fn run_diff(args: &Args, config: &Config) -> Result<()> {
    let file_type = args.file_type.as_deref();
    let path_a = args.old.as_ref().unwrap();
    let path_b = args.new.as_ref().unwrap();
    // This looks a bit weird because the ast vectors and some other data reference data in the
    // AstVectorData structs. Because of that, we can't make a function that generates the ast
    // vectors in one shot.
    let ast_data_a = generate_ast_vector_data(path_a.to_path_buf(), file_type, &config.grammar)?;
    let ast_data_b = generate_ast_vector_data(path_b.to_path_buf(), file_type, &config.grammar)?;
    let diff_vec_a = generate_ast_vector(&ast_data_a);
    let diff_vec_b = generate_ast_vector(&ast_data_b);
    let (old_hunks, new_hunks) = ast::compute_edit_script(&diff_vec_a, &diff_vec_b);
    let params = DisplayParameters {
        old: DocumentDiffData {
            filename: &ast_data_a.path.to_string_lossy(),
            hunks: &old_hunks,
            text: &ast_data_a.text,
        },
        new: DocumentDiffData {
            filename: &ast_data_b.path.to_string_lossy(),
            hunks: &new_hunks,
            text: &ast_data_b.text,
        },
    };
    // Use a buffered terminal instead of a normal unbuffered terminal so we can amortize the cost of printing. It
    // doesn't really how frequently the terminal prints to stdout because the user just cares about the output at the
    // end, we don't care about how frequently the terminal does partial updates or anything like that. If the user is
    // curious about progress, they can enable logging and see when hunks are processed and written to the buffer.
    let mut buf_writer = BufWriter::new(Term::stdout());
    config.formatting.print(&mut buf_writer, &params)?;
    // Just in case we forgot to flush anything in the `print` function
    buf_writer.flush()?;
    Ok(())
}
fn run_diff ( args : & Args , config : & Config ) -> Result < ( ) > { let file_type = args . file_type . as_deref ( ) ; let path_a = args . old . as_ref ( ) . unwrap ( ) ; let path_b = args . new . as_ref ( ) . unwrap ( ) ; // This looks a bit weird because the ast vectors and some other data reference data in the // AstVectorData structs. Because of that, we can't make a function that generates the ast // vectors in one shot. let ast_data_a = generate_ast_vector_data ( path_a . to_path_buf ( ) , file_type , & config . grammar ) ? ; let ast_data_b = generate_ast_vector_data ( path_b . to_path_buf ( ) , file_type , & config . grammar ) ? ; let diff_vec_a = generate_ast_vector ( & ast_data_a ) ; let diff_vec_b = generate_ast_vector ( & ast_data_b ) ; let ( old_hunks , new_hunks ) = ast :: compute_edit_script ( & diff_vec_a , & diff_vec_b ) ; let params = DisplayParameters { old : DocumentDiffData { filename : & ast_data_a . path . to_string_lossy ( ) , hunks : & old_hunks , text : & ast_data_a . text , } , new : DocumentDiffData { filename : & ast_data_b . path . to_string_lossy ( ) , hunks : & new_hunks , text : & ast_data_b . text , } , } ; // Use a buffered terminal instead of a normal unbuffered terminal so we can amortize the cost of printing. It // doesn't really how frequently the terminal prints to stdout because the user just cares about the output at the // end, we don't care about how frequently the terminal does partial updates or anything like that. If the user is // curious about progress, they can enable logging and see when hunks are processed and written to the buffer. let mut buf_writer = BufWriter :: new ( Term :: stdout ( ) ) ; config . formatting . print ( & mut buf_writer , & params ) ? ; // Just in case we forgot to flush anything in the `print` function buf_writer . flush ( ) ? ; Ok ( ( ) ) }
Take the diff of two files
Take the diff of two files
args
&Args
config
&Config
args
&Args
config
&Config