Release Notes: - N/A *or* Added/Fixed/Improved ... Co-authored by: Kate <kate@zed.dev>
Unified · Split
| @@ -12711,6 +12711,12 @@ version = "0.2.5" · 12710 unmodified lines | ||
| 12711 | 12711 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 12712 | 12712 | checksum = "5da3b0203fd7ee5720aa0b5e790b591aa5d3f41c3ed2c34a3a393382198af2f7" |
| 12713 | 12713 | |
| 12714 | +[[package]] | |
| 12715 | +name = "pollster" | |
| 12716 | +version = "0.4.0" | |
| 12717 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 12718 | +checksum = "2f3a9f18d041e6d0e102a0a46750538147e5e8992d3b4873aaafee2520b00ce3" | |
| 12719 | + | |
| 12714 | 12720 | [[package]] |
| 12715 | 12721 | name = "portable-atomic" |
| 12716 | 12722 | version = "1.11.1" |
| @@ -12759,7 +12765,7 @@ dependencies = [ · 42 unmodified lines | ||
| 12759 | 12765 | "log", |
| 12760 | 12766 | "parking_lot", |
| 12761 | 12767 | "pin-project", |
| 12762 | − "pollster", | |
| 12768 | + "pollster 0.2.5", | |
| 12763 | 12769 | "static_assertions", |
| 12764 | 12770 | "thiserror 1.0.69", |
| 12765 | 12771 | ] |
| @@ -14311,7 +14317,6 @@ dependencies = [ · 1545 unmodified lines | ||
| 14311 | 14317 | "gpui", |
| 14312 | 14318 | "log", |
| 14313 | 14319 | "rand 0.9.2", |
| 14314 | − "rayon", | |
| 14315 | 14320 | "sum_tree", |
| 14316 | 14321 | "unicode-segmentation", |
| 14317 | 14322 | "util", |
| @@ -16237,6 +16242,7 @@ checksum = "2b2231b7c3057d5e4ad0156fb3dc807d900806020c5ffa3ee6ff2c8c76fb8520" · 1919 unmodified lines | ||
| 16237 | 16242 | name = "streaming_diff" |
| 16238 | 16243 | version = "0.1.0" |
| 16239 | 16244 | dependencies = [ |
| 16245 | + "gpui", | |
| 16240 | 16246 | "ordered-float 2.10.1", |
| 16241 | 16247 | "rand 0.9.2", |
| 16242 | 16248 | "rope", |
| @@ -16355,9 +16361,11 @@ version = "0.1.0" · 112 unmodified lines | ||
| 16355 | 16361 | dependencies = [ |
| 16356 | 16362 | "arrayvec", |
| 16357 | 16363 | "ctor", |
| 16364 | + "futures 0.3.31", | |
| 16365 | + "itertools 0.14.0", | |
| 16358 | 16366 | "log", |
| 16367 | + "pollster 0.4.0", | |
| 16359 | 16368 | "rand 0.9.2", |
| 16360 | − "rayon", | |
| 16361 | 16369 | "zlog", |
| 16362 | 16370 | ] |
| 16363 | 16371 | |
| @@ -361,10 +361,12 @@ async fn build_buffer_diff( · 360 unmodified lines | ||
| 361 | 361 | ) -> Result<Entity<BufferDiff>> { |
| 362 | 362 | let buffer = cx.update(|cx| buffer.read(cx).snapshot())?; |
| 363 | 363 | |
| 364 | + let executor = cx.background_executor().clone(); | |
| 364 | 365 | let old_text_rope = cx |
| 365 | 366 | .background_spawn({ |
| 366 | 367 | let old_text = old_text.clone(); |
| 367 | − async move { Rope::from(old_text.as_str()) } | |
| 368 | + let executor = executor.clone(); | |
| 369 | + async move { Rope::from_str(old_text.as_str(), &executor) } | |
| 368 | 370 | }) |
| 369 | 371 | .await; |
| 370 | 372 | let base_buffer = cx |
| @@ -3,7 +3,9 @@ use buffer_diff::BufferDiff; · 2 unmodified lines | ||
| 3 | 3 | use clock; |
| 4 | 4 | use collections::BTreeMap; |
| 5 | 5 | use futures::{FutureExt, StreamExt, channel::mpsc}; |
| 6 | −use gpui::{App, AppContext, AsyncApp, Context, Entity, Subscription, Task, WeakEntity}; | |
| 6 | +use gpui::{ | |
| 7 | + App, AppContext, AsyncApp, BackgroundExecutor, Context, Entity, Subscription, Task, WeakEntity, | |
| 8 | +}; | |
| 7 | 9 | use language::{Anchor, Buffer, BufferEvent, DiskState, Point, ToPoint}; |
| 8 | 10 | use project::{Project, ProjectItem, lsp_store::OpenLspBufferHandle}; |
| 9 | 11 | use std::{cmp, ops::Range, sync::Arc}; |
| @@ -321,6 +323,7 @@ impl ActionLog { · 311 unmodified lines | ||
| 321 | 323 | let unreviewed_edits = tracked_buffer.unreviewed_edits.clone(); |
| 322 | 324 | let edits = diff_snapshots(&old_snapshot, &new_snapshot); |
| 323 | 325 | let mut has_user_changes = false; |
| 326 | + let executor = cx.background_executor().clone(); | |
| 324 | 327 | async move { |
| 325 | 328 | if let ChangeAuthor::User = author { |
| 326 | 329 | has_user_changes = apply_non_conflicting_edits( |
| @@ -328,6 +331,7 @@ impl ActionLog { · 1 unmodified line | ||
| 328 | 331 | edits, |
| 329 | 332 | &mut base_text, |
| 330 | 333 | new_snapshot.as_rope(), |
| 334 | + &executor, | |
| 331 | 335 | ); |
| 332 | 336 | } |
| 333 | 337 | |
| @@ -382,6 +386,7 @@ impl ActionLog { · 48 unmodified lines | ||
| 382 | 386 | let agent_diff_base = tracked_buffer.diff_base.clone(); |
| 383 | 387 | let git_diff_base = git_diff.read(cx).base_text().as_rope().clone(); |
| 384 | 388 | let buffer_text = tracked_buffer.snapshot.as_rope().clone(); |
| 389 | + let executor = cx.background_executor().clone(); | |
| 385 | 390 | anyhow::Ok(cx.background_spawn(async move { |
| 386 | 391 | let mut old_unreviewed_edits = old_unreviewed_edits.into_iter().peekable(); |
| 387 | 392 | let committed_edits = language::line_diff( |
| @@ -416,8 +421,11 @@ impl ActionLog { · 28 unmodified lines | ||
| 416 | 421 | ), |
| 417 | 422 | new_agent_diff_base.max_point(), |
| 418 | 423 | )); |
| 419 | − new_agent_diff_base | |
| 420 | − .replace(old_byte_start..old_byte_end, &unreviewed_new); | |
| 424 | + new_agent_diff_base.replace( | |
| 425 | + old_byte_start..old_byte_end, | |
| 426 | + &unreviewed_new, | |
| 427 | + &executor, | |
| 428 | + ); | |
| 421 | 429 | row_delta += |
| 422 | 430 | unreviewed.new_len() as i32 - unreviewed.old_len() as i32; |
| 423 | 431 | } |
| @@ -611,6 +619,7 @@ impl ActionLog { · 187 unmodified lines | ||
| 611 | 619 | .snapshot |
| 612 | 620 | .text_for_range(new_range) |
| 613 | 621 | .collect::<String>(), |
| 622 | + cx.background_executor(), | |
| 614 | 623 | ); |
| 615 | 624 | delta += edit.new_len() as i32 - edit.old_len() as i32; |
| 616 | 625 | false |
| @@ -824,6 +833,7 @@ fn apply_non_conflicting_edits( · 207 unmodified lines | ||
| 824 | 833 | edits: Vec<Edit<u32>>, |
| 825 | 834 | old_text: &mut Rope, |
| 826 | 835 | new_text: &Rope, |
| 836 | + executor: &BackgroundExecutor, | |
| 827 | 837 | ) -> bool { |
| 828 | 838 | let mut old_edits = patch.edits().iter().cloned().peekable(); |
| 829 | 839 | let mut new_edits = edits.into_iter().peekable(); |
| @@ -877,6 +887,7 @@ fn apply_non_conflicting_edits( · 47 unmodified lines | ||
| 877 | 887 | old_text.replace( |
| 878 | 888 | old_bytes, |
| 879 | 889 | &new_text.chunks_in_range(new_bytes).collect::<String>(), |
| 890 | + executor, | |
| 880 | 891 | ); |
| 881 | 892 | applied_delta += new_edit.new_len() as i32 - new_edit.old_len() as i32; |
| 882 | 893 | has_made_changes = true; |
| @@ -2282,6 +2293,7 @@ mod tests { · 1399 unmodified lines | ||
| 2282 | 2293 | old_text.replace( |
| 2283 | 2294 | old_start..old_end, |
| 2284 | 2295 | &new_text.slice_rows(edit.new.clone()).to_string(), |
| 2296 | + cx.background_executor(), | |
| 2285 | 2297 | ); |
| 2286 | 2298 | } |
| 2287 | 2299 | pretty_assertions::assert_eq!(old_text.to_string(), new_text.to_string()); |
| @@ -305,18 +305,20 @@ impl SearchMatrix { · 304 unmodified lines | ||
| 305 | 305 | #[cfg(test)] |
| 306 | 306 | mod tests { |
| 307 | 307 | use super::*; |
| 308 | + use gpui::TestAppContext; | |
| 308 | 309 | use indoc::indoc; |
| 309 | 310 | use language::{BufferId, TextBuffer}; |
| 310 | 311 | use rand::prelude::*; |
| 311 | 312 | use text::ReplicaId; |
| 312 | 313 | use util::test::{generate_marked_text, marked_text_ranges}; |
| 313 | 314 | |
| 314 | − #[test] | |
| 315 | − fn test_empty_query() { | |
| 315 | + #[gpui::test] | |
| 316 | + fn test_empty_query(cx: &mut gpui::TestAppContext) { | |
| 316 | 317 | let buffer = TextBuffer::new( |
| 317 | 318 | ReplicaId::LOCAL, |
| 318 | 319 | BufferId::new(1).unwrap(), |
| 319 | 320 | "Hello world\nThis is a test\nFoo bar baz", |
| 321 | + cx.background_executor(), | |
| 320 | 322 | ); |
| 321 | 323 | let snapshot = buffer.snapshot(); |
| 322 | 324 | |
| @@ -325,12 +327,13 @@ mod tests { · 2 unmodified lines | ||
| 325 | 327 | assert_eq!(finish(finder), None); |
| 326 | 328 | } |
| 327 | 329 | |
| 328 | − #[test] | |
| 329 | − fn test_streaming_exact_match() { | |
| 330 | + #[gpui::test] | |
| 331 | + fn test_streaming_exact_match(cx: &mut gpui::TestAppContext) { | |
| 330 | 332 | let buffer = TextBuffer::new( |
| 331 | 333 | ReplicaId::LOCAL, |
| 332 | 334 | BufferId::new(1).unwrap(), |
| 333 | 335 | "Hello world\nThis is a test\nFoo bar baz", |
| 336 | + cx.background_executor(), | |
| 334 | 337 | ); |
| 335 | 338 | let snapshot = buffer.snapshot(); |
| 336 | 339 | |
| @@ -349,8 +352,8 @@ mod tests { · 12 unmodified lines | ||
| 349 | 352 | assert_eq!(finish(finder), Some("This is a test".to_string())); |
| 350 | 353 | } |
| 351 | 354 | |
| 352 | − #[test] | |
| 353 | − fn test_streaming_fuzzy_match() { | |
| 355 | + #[gpui::test] | |
| 356 | + fn test_streaming_fuzzy_match(cx: &mut gpui::TestAppContext) { | |
| 354 | 357 | let buffer = TextBuffer::new( |
| 355 | 358 | ReplicaId::LOCAL, |
| 356 | 359 | BufferId::new(1).unwrap(), |
| @@ -363,6 +366,7 @@ mod tests { · 6 unmodified lines | ||
| 363 | 366 | return x * y; |
| 364 | 367 | } |
| 365 | 368 | "}, |
| 369 | + cx.background_executor(), | |
| 366 | 370 | ); |
| 367 | 371 | let snapshot = buffer.snapshot(); |
| 368 | 372 | |
| @@ -383,12 +387,13 @@ mod tests { · 14 unmodified lines | ||
| 383 | 387 | ); |
| 384 | 388 | } |
| 385 | 389 | |
| 386 | − #[test] | |
| 387 | − fn test_incremental_improvement() { | |
| 390 | + #[gpui::test] | |
| 391 | + fn test_incremental_improvement(cx: &mut gpui::TestAppContext) { | |
| 388 | 392 | let buffer = TextBuffer::new( |
| 389 | 393 | ReplicaId::LOCAL, |
| 390 | 394 | BufferId::new(1).unwrap(), |
| 391 | 395 | "Line 1\nLine 2\nLine 3\nLine 4\nLine 5", |
| 396 | + cx.background_executor(), | |
| 392 | 397 | ); |
| 393 | 398 | let snapshot = buffer.snapshot(); |
| 394 | 399 | |
| @@ -408,8 +413,8 @@ mod tests { · 13 unmodified lines | ||
| 408 | 413 | assert_eq!(finish(finder), Some("Line 3\nLine 4".to_string())); |
| 409 | 414 | } |
| 410 | 415 | |
| 411 | − #[test] | |
| 412 | − fn test_incomplete_lines_buffering() { | |
| 416 | + #[gpui::test] | |
| 417 | + fn test_incomplete_lines_buffering(cx: &mut gpui::TestAppContext) { | |
| 413 | 418 | let buffer = TextBuffer::new( |
| 414 | 419 | ReplicaId::LOCAL, |
| 415 | 420 | BufferId::new(1).unwrap(), |
| @@ -418,6 +423,7 @@ mod tests { · 2 unmodified lines | ||
| 418 | 423 | jumps over the lazy dog |
| 419 | 424 | Pack my box with five dozen liquor jugs |
| 420 | 425 | "}, |
| 426 | + cx.background_executor(), | |
| 421 | 427 | ); |
| 422 | 428 | let snapshot = buffer.snapshot(); |
| 423 | 429 | |
| @@ -435,8 +441,8 @@ mod tests { · 11 unmodified lines | ||
| 435 | 441 | ); |
| 436 | 442 | } |
| 437 | 443 | |
| 438 | − #[test] | |
| 439 | − fn test_multiline_fuzzy_match() { | |
| 444 | + #[gpui::test] | |
| 445 | + fn test_multiline_fuzzy_match(cx: &mut gpui::TestAppContext) { | |
| 440 | 446 | let buffer = TextBuffer::new( |
| 441 | 447 | ReplicaId::LOCAL, |
| 442 | 448 | BufferId::new(1).unwrap(), |
| @@ -456,6 +462,7 @@ mod tests { · 13 unmodified lines | ||
| 456 | 462 | } |
| 457 | 463 | } |
| 458 | 464 | "#}, |
| 465 | + cx.background_executor(), | |
| 459 | 466 | ); |
| 460 | 467 | let snapshot = buffer.snapshot(); |
| 461 | 468 | |
| @@ -509,7 +516,7 @@ mod tests { · 47 unmodified lines | ||
| 509 | 516 | } |
| 510 | 517 | |
| 511 | 518 | #[gpui::test(iterations = 100)] |
| 512 | − fn test_resolve_location_single_line(mut rng: StdRng) { | |
| 519 | + fn test_resolve_location_single_line(mut rng: StdRng, cx: &mut TestAppContext) { | |
| 513 | 520 | assert_location_resolution( |
| 514 | 521 | concat!( |
| 515 | 522 | " Lorem\n", |
| @@ -519,11 +526,12 @@ mod tests { · 3 unmodified lines | ||
| 519 | 526 | ), |
| 520 | 527 | "ipsum", |
| 521 | 528 | &mut rng, |
| 529 | + cx, | |
| 522 | 530 | ); |
| 523 | 531 | } |
| 524 | 532 | |
| 525 | 533 | #[gpui::test(iterations = 100)] |
| 526 | − fn test_resolve_location_multiline(mut rng: StdRng) { | |
| 534 | + fn test_resolve_location_multiline(mut rng: StdRng, cx: &mut TestAppContext) { | |
| 527 | 535 | assert_location_resolution( |
| 528 | 536 | concat!( |
| 529 | 537 | " Lorem\n", |
| @@ -533,11 +541,12 @@ mod tests { · 3 unmodified lines | ||
| 533 | 541 | ), |
| 534 | 542 | "ipsum\ndolor sit amet", |
| 535 | 543 | &mut rng, |
| 544 | + cx, | |
| 536 | 545 | ); |
| 537 | 546 | } |
| 538 | 547 | |
| 539 | 548 | #[gpui::test(iterations = 100)] |
| 540 | − fn test_resolve_location_function_with_typo(mut rng: StdRng) { | |
| 549 | + fn test_resolve_location_function_with_typo(mut rng: StdRng, cx: &mut TestAppContext) { | |
| 541 | 550 | assert_location_resolution( |
| 542 | 551 | indoc! {" |
| 543 | 552 | «fn foo1(a: usize) -> usize { |
| @@ -550,11 +559,12 @@ mod tests { · 6 unmodified lines | ||
| 550 | 559 | "}, |
| 551 | 560 | "fn foo1(a: usize) -> u32 {\n40\n}", |
| 552 | 561 | &mut rng, |
| 562 | + cx, | |
| 553 | 563 | ); |
| 554 | 564 | } |
| 555 | 565 | |
| 556 | 566 | #[gpui::test(iterations = 100)] |
| 557 | − fn test_resolve_location_class_methods(mut rng: StdRng) { | |
| 567 | + fn test_resolve_location_class_methods(mut rng: StdRng, cx: &mut TestAppContext) { | |
| 558 | 568 | assert_location_resolution( |
| 559 | 569 | indoc! {" |
| 560 | 570 | class Something { |
| @@ -575,11 +585,12 @@ mod tests { · 14 unmodified lines | ||
| 575 | 585 | six() { return 6666; } |
| 576 | 586 | "}, |
| 577 | 587 | &mut rng, |
| 588 | + cx, | |
| 578 | 589 | ); |
| 579 | 590 | } |
| 580 | 591 | |
| 581 | 592 | #[gpui::test(iterations = 100)] |
| 582 | − fn test_resolve_location_imports_no_match(mut rng: StdRng) { | |
| 593 | + fn test_resolve_location_imports_no_match(mut rng: StdRng, cx: &mut TestAppContext) { | |
| 583 | 594 | assert_location_resolution( |
| 584 | 595 | indoc! {" |
| 585 | 596 | use std::ops::Range; |
| @@ -609,11 +620,12 @@ mod tests { · 23 unmodified lines | ||
| 609 | 620 | use std::sync::Arc; |
| 610 | 621 | "}, |
| 611 | 622 | &mut rng, |
| 623 | + cx, | |
| 612 | 624 | ); |
| 613 | 625 | } |
| 614 | 626 | |
| 615 | 627 | #[gpui::test(iterations = 100)] |
| 616 | − fn test_resolve_location_nested_closure(mut rng: StdRng) { | |
| 628 | + fn test_resolve_location_nested_closure(mut rng: StdRng, cx: &mut TestAppContext) { | |
| 617 | 629 | assert_location_resolution( |
| 618 | 630 | indoc! {" |
| 619 | 631 | impl Foo { |
| @@ -641,11 +653,12 @@ mod tests { · 21 unmodified lines | ||
| 641 | 653 | " });", |
| 642 | 654 | ), |
| 643 | 655 | &mut rng, |
| 656 | + cx, | |
| 644 | 657 | ); |
| 645 | 658 | } |
| 646 | 659 | |
| 647 | 660 | #[gpui::test(iterations = 100)] |
| 648 | − fn test_resolve_location_tool_invocation(mut rng: StdRng) { | |
| 661 | + fn test_resolve_location_tool_invocation(mut rng: StdRng, cx: &mut TestAppContext) { | |
| 649 | 662 | assert_location_resolution( |
| 650 | 663 | indoc! {r#" |
| 651 | 664 | let tool = cx |
| @@ -673,11 +686,12 @@ mod tests { · 21 unmodified lines | ||
| 673 | 686 | " .output;", |
| 674 | 687 | ), |
| 675 | 688 | &mut rng, |
| 689 | + cx, | |
| 676 | 690 | ); |
| 677 | 691 | } |
| 678 | 692 | |
| 679 | 693 | #[gpui::test] |
| 680 | − fn test_line_hint_selection() { | |
| 694 | + fn test_line_hint_selection(cx: &mut TestAppContext) { | |
| 681 | 695 | let text = indoc! {r#" |
| 682 | 696 | fn first_function() { |
| 683 | 697 | return 42; |
| @@ -696,6 +710,7 @@ mod tests { · 12 unmodified lines | ||
| 696 | 710 | ReplicaId::LOCAL, |
| 697 | 711 | BufferId::new(1).unwrap(), |
| 698 | 712 | text.to_string(), |
| 713 | + cx.background_executor(), | |
| 699 | 714 | ); |
| 700 | 715 | let snapshot = buffer.snapshot(); |
| 701 | 716 | let mut matcher = StreamingFuzzyMatcher::new(snapshot.clone()); |
| @@ -727,9 +742,19 @@ mod tests { · 25 unmodified lines | ||
| 727 | 742 | } |
| 728 | 743 | |
| 729 | 744 | #[track_caller] |
| 730 | − fn assert_location_resolution(text_with_expected_range: &str, query: &str, rng: &mut StdRng) { | |
| 745 | + fn assert_location_resolution( | |
| 746 | + text_with_expected_range: &str, | |
| 747 | + query: &str, | |
| 748 | + rng: &mut StdRng, | |
| 749 | + cx: &mut TestAppContext, | |
| 750 | + ) { | |
| 731 | 751 | let (text, expected_ranges) = marked_text_ranges(text_with_expected_range, false); |
| 732 | − let buffer = TextBuffer::new(ReplicaId::LOCAL, BufferId::new(1).unwrap(), text.clone()); | |
| 752 | + let buffer = TextBuffer::new( | |
| 753 | + ReplicaId::LOCAL, | |
| 754 | + BufferId::new(1).unwrap(), | |
| 755 | + text.clone(), | |
| 756 | + cx.background_executor(), | |
| 757 | + ); | |
| 733 | 758 | let snapshot = buffer.snapshot(); |
| 734 | 759 | |
| 735 | 760 | let mut matcher = StreamingFuzzyMatcher::new(snapshot); |
| @@ -569,6 +569,7 @@ mod tests { · 568 unmodified lines | ||
| 569 | 569 | use prompt_store::ProjectContext; |
| 570 | 570 | use serde_json::json; |
| 571 | 571 | use settings::SettingsStore; |
| 572 | + use text::Rope; | |
| 572 | 573 | use util::{path, rel_path::rel_path}; |
| 573 | 574 | |
| 574 | 575 | #[gpui::test] |
| @@ -741,7 +742,7 @@ mod tests { · 166 unmodified lines | ||
| 741 | 742 | // Create the file |
| 742 | 743 | fs.save( |
| 743 | 744 | path!("/root/src/main.rs").as_ref(), |
| 744 | − &"initial content".into(), | |
| 745 | + &Rope::from_str_small("initial content"), | |
| 745 | 746 | language::LineEnding::Unix, |
| 746 | 747 | ) |
| 747 | 748 | .await |
| @@ -908,7 +909,7 @@ mod tests { · 160 unmodified lines | ||
| 908 | 909 | // Create a simple file with trailing whitespace |
| 909 | 910 | fs.save( |
| 910 | 911 | path!("/root/src/main.rs").as_ref(), |
| 911 | − &"initial content".into(), | |
| 912 | + &Rope::from_str_small("initial content"), | |
| 912 | 913 | language::LineEnding::Unix, |
| 913 | 914 | ) |
| 914 | 915 | .await |
| @@ -28,6 +28,7 @@ use project::{ · 27 unmodified lines | ||
| 28 | 28 | agent_server_store::{AgentServerStore, CLAUDE_CODE_NAME, CODEX_NAME, GEMINI_NAME}, |
| 29 | 29 | context_server_store::{ContextServerConfiguration, ContextServerStatus, ContextServerStore}, |
| 30 | 30 | }; |
| 31 | +use rope::Rope; | |
| 31 | 32 | use settings::{SettingsStore, update_settings_file}; |
| 32 | 33 | use ui::{ |
| 33 | 34 | Chip, CommonAnimationExt, ContextMenu, Disclosure, Divider, DividerColor, ElevationIndex, |
| @@ -1114,8 +1115,11 @@ async fn open_new_agent_servers_entry_in_settings_editor( · 1080 unmodified lines | ||
| 1114 | 1115 | ) -> Result<()> { |
| 1115 | 1116 | let settings_editor = workspace |
| 1116 | 1117 | .update_in(cx, |_, window, cx| { |
| 1117 | − create_and_open_local_file(paths::settings_file(), window, cx, || { | |
| 1118 | − settings::initial_user_settings_content().as_ref().into() | |
| 1118 | + create_and_open_local_file(paths::settings_file(), window, cx, |cx| { | |
| 1119 | + Rope::from_str( | |
| 1120 | + &settings::initial_user_settings_content(), | |
| 1121 | + cx.background_executor(), | |
| 1122 | + ) | |
| 1119 | 1123 | }) |
| 1120 | 1124 | })? |
| 1121 | 1125 | .await? |
| @@ -487,9 +487,10 @@ impl CodegenAlternative { · 486 unmodified lines | ||
| 487 | 487 | ) { |
| 488 | 488 | let start_time = Instant::now(); |
| 489 | 489 | let snapshot = self.snapshot.clone(); |
| 490 | − let selected_text = snapshot | |
| 491 | − .text_for_range(self.range.start..self.range.end) | |
| 492 | − .collect::<Rope>(); | |
| 490 | + let selected_text = Rope::from_iter( | |
| 491 | + snapshot.text_for_range(self.range.start..self.range.end), | |
| 492 | + cx.background_executor(), | |
| 493 | + ); | |
| 493 | 494 | |
| 494 | 495 | let selection_start = self.range.start.to_point(&snapshot); |
| 495 | 496 | |
| @@ -744,12 +744,13 @@ impl TextThread { · 743 unmodified lines | ||
| 744 | 744 | telemetry: Option<Arc<Telemetry>>, |
| 745 | 745 | cx: &mut Context<Self>, |
| 746 | 746 | ) -> Self { |
| 747 | − let buffer = cx.new(|_cx| { | |
| 747 | + let buffer = cx.new(|cx| { | |
| 748 | 748 | let buffer = Buffer::remote( |
| 749 | 749 | language::BufferId::new(1).unwrap(), |
| 750 | 750 | replica_id, |
| 751 | 751 | capability, |
| 752 | 752 | "", |
| 753 | + cx.background_executor(), | |
| 753 | 754 | ); |
| 754 | 755 | buffer.set_language_registry(language_registry.clone()); |
| 755 | 756 | buffer |
| @@ -1,6 +1,9 @@ | ||
| 1 | 1 | use futures::channel::oneshot; |
| 2 | 2 | use git2::{DiffLineType as GitDiffLineType, DiffOptions as GitOptions, Patch as GitPatch}; |
| 3 | −use gpui::{App, AppContext as _, AsyncApp, Context, Entity, EventEmitter, Task, TaskLabel}; | |
| 3 | +use gpui::{ | |
| 4 | + App, AppContext as _, AsyncApp, BackgroundExecutor, Context, Entity, EventEmitter, Task, | |
| 5 | + TaskLabel, | |
| 6 | +}; | |
| 4 | 7 | use language::{Language, LanguageRegistry}; |
| 5 | 8 | use rope::Rope; |
| 6 | 9 | use std::{ |
| @@ -191,7 +194,7 @@ impl BufferDiffSnapshot { · 184 unmodified lines | ||
| 191 | 194 | let base_text_exists; |
| 192 | 195 | let base_text_snapshot; |
| 193 | 196 | if let Some(text) = &base_text { |
| 194 | − let base_text_rope = Rope::from(text.as_str()); | |
| 197 | + let base_text_rope = Rope::from_str(text.as_str(), cx.background_executor()); | |
| 195 | 198 | base_text_pair = Some((text.clone(), base_text_rope.clone())); |
| 196 | 199 | let snapshot = |
| 197 | 200 | language::Buffer::build_snapshot(base_text_rope, language, language_registry, cx); |
| @@ -311,6 +314,7 @@ impl BufferDiffInner { · 113 unmodified lines | ||
| 311 | 314 | hunks: &[DiffHunk], |
| 312 | 315 | buffer: &text::BufferSnapshot, |
| 313 | 316 | file_exists: bool, |
| 317 | + cx: &BackgroundExecutor, | |
| 314 | 318 | ) -> Option<Rope> { |
| 315 | 319 | let head_text = self |
| 316 | 320 | .base_text_exists |
| @@ -505,7 +509,7 @@ impl BufferDiffInner { · 188 unmodified lines | ||
| 505 | 509 | for (old_range, replacement_text) in edits { |
| 506 | 510 | new_index_text.append(index_cursor.slice(old_range.start)); |
| 507 | 511 | index_cursor.seek_forward(old_range.end); |
| 508 | − new_index_text.push(&replacement_text); | |
| 512 | + new_index_text.push(&replacement_text, cx); | |
| 509 | 513 | } |
| 510 | 514 | new_index_text.append(index_cursor.suffix()); |
| 511 | 515 | Some(new_index_text) |
| @@ -962,6 +966,7 @@ impl BufferDiff { · 450 unmodified lines | ||
| 962 | 966 | hunks, |
| 963 | 967 | buffer, |
| 964 | 968 | file_exists, |
| 969 | + cx.background_executor(), | |
| 965 | 970 | ); |
| 966 | 971 | |
| 967 | 972 | cx.emit(BufferDiffEvent::HunksStagedOrUnstaged( |
| @@ -1385,7 +1390,12 @@ mod tests { · 417 unmodified lines | ||
| 1385 | 1390 | " |
| 1386 | 1391 | .unindent(); |
| 1387 | 1392 | |
| 1388 | − let mut buffer = Buffer::new(ReplicaId::LOCAL, BufferId::new(1).unwrap(), buffer_text); | |
| 1393 | + let mut buffer = Buffer::new( | |
| 1394 | + ReplicaId::LOCAL, | |
| 1395 | + BufferId::new(1).unwrap(), | |
| 1396 | + buffer_text, | |
| 1397 | + cx.background_executor(), | |
| 1398 | + ); | |
| 1389 | 1399 | let mut diff = BufferDiffSnapshot::new_sync(buffer.clone(), diff_base.clone(), cx); |
| 1390 | 1400 | assert_hunks( |
| 1391 | 1401 | diff.hunks_intersecting_range(Anchor::MIN..Anchor::MAX, &buffer), |
| @@ -1394,7 +1404,7 @@ mod tests { · 2 unmodified lines | ||
| 1394 | 1404 | &[(1..2, "two\n", "HELLO\n", DiffHunkStatus::modified_none())], |
| 1395 | 1405 | ); |
| 1396 | 1406 | |
| 1397 | − buffer.edit([(0..0, "point five\n")]); | |
| 1407 | + buffer.edit([(0..0, "point five\n")], cx.background_executor()); | |
| 1398 | 1408 | diff = BufferDiffSnapshot::new_sync(buffer.clone(), diff_base.clone(), cx); |
| 1399 | 1409 | assert_hunks( |
| 1400 | 1410 | diff.hunks_intersecting_range(Anchor::MIN..Anchor::MAX, &buffer), |
| @@ -1459,7 +1469,12 @@ mod tests { · 58 unmodified lines | ||
| 1459 | 1469 | " |
| 1460 | 1470 | .unindent(); |
| 1461 | 1471 | |
| 1462 | − let buffer = Buffer::new(ReplicaId::LOCAL, BufferId::new(1).unwrap(), buffer_text); | |
| 1472 | + let buffer = Buffer::new( | |
| 1473 | + ReplicaId::LOCAL, | |
| 1474 | + BufferId::new(1).unwrap(), | |
| 1475 | + buffer_text, | |
| 1476 | + cx.background_executor(), | |
| 1477 | + ); | |
| 1463 | 1478 | let unstaged_diff = BufferDiffSnapshot::new_sync(buffer.clone(), index_text, cx); |
| 1464 | 1479 | let mut uncommitted_diff = |
| 1465 | 1480 | BufferDiffSnapshot::new_sync(buffer.clone(), head_text.clone(), cx); |
| @@ -1528,7 +1543,12 @@ mod tests { · 62 unmodified lines | ||
| 1528 | 1543 | " |
| 1529 | 1544 | .unindent(); |
| 1530 | 1545 | |
| 1531 | − let buffer = Buffer::new(ReplicaId::LOCAL, BufferId::new(1).unwrap(), buffer_text); | |
| 1546 | + let buffer = Buffer::new( | |
| 1547 | + ReplicaId::LOCAL, | |
| 1548 | + BufferId::new(1).unwrap(), | |
| 1549 | + buffer_text, | |
| 1550 | + cx.background_executor(), | |
| 1551 | + ); | |
| 1532 | 1552 | let diff = cx |
| 1533 | 1553 | .update(|cx| { |
| 1534 | 1554 | BufferDiffSnapshot::new_with_base_text( |
| @@ -1791,7 +1811,12 @@ mod tests { · 256 unmodified lines | ||
| 1791 | 1811 | |
| 1792 | 1812 | for example in table { |
| 1793 | 1813 | let (buffer_text, ranges) = marked_text_ranges(&example.buffer_marked_text, false); |
| 1794 | − let buffer = Buffer::new(ReplicaId::LOCAL, BufferId::new(1).unwrap(), buffer_text); | |
| 1814 | + let buffer = Buffer::new( | |
| 1815 | + ReplicaId::LOCAL, | |
| 1816 | + BufferId::new(1).unwrap(), | |
| 1817 | + buffer_text, | |
| 1818 | + cx.background_executor(), | |
| 1819 | + ); | |
| 1795 | 1820 | let hunk_range = |
| 1796 | 1821 | buffer.anchor_before(ranges[0].start)..buffer.anchor_before(ranges[0].end); |
| 1797 | 1822 | |
| @@ -1868,6 +1893,7 @@ mod tests { · 70 unmodified lines | ||
| 1868 | 1893 | ReplicaId::LOCAL, |
| 1869 | 1894 | BufferId::new(1).unwrap(), |
| 1870 | 1895 | buffer_text.clone(), |
| 1896 | + cx.background_executor(), | |
| 1871 | 1897 | ); |
| 1872 | 1898 | let unstaged = BufferDiffSnapshot::new_sync(buffer.clone(), index_text, cx); |
| 1873 | 1899 | let uncommitted = BufferDiffSnapshot::new_sync(buffer.clone(), head_text.clone(), cx); |
| @@ -1941,7 +1967,12 @@ mod tests { · 67 unmodified lines | ||
| 1941 | 1967 | " |
| 1942 | 1968 | .unindent(); |
| 1943 | 1969 | |
| 1944 | − let mut buffer = Buffer::new(ReplicaId::LOCAL, BufferId::new(1).unwrap(), buffer_text_1); | |
| 1970 | + let mut buffer = Buffer::new( | |
| 1971 | + ReplicaId::LOCAL, | |
| 1972 | + BufferId::new(1).unwrap(), | |
| 1973 | + buffer_text_1, | |
| 1974 | + cx.background_executor(), | |
| 1975 | + ); | |
| 1945 | 1976 | |
| 1946 | 1977 | let empty_diff = cx.update(|cx| BufferDiffSnapshot::empty(&buffer, cx)); |
| 1947 | 1978 | let diff_1 = BufferDiffSnapshot::new_sync(buffer.clone(), base_text.clone(), cx); |
| @@ -1961,6 +1992,7 @@ mod tests { · 13 unmodified lines | ||
| 1961 | 1992 | NINE |
| 1962 | 1993 | " |
| 1963 | 1994 | .unindent(), |
| 1995 | + cx.background_executor(), | |
| 1964 | 1996 | ); |
| 1965 | 1997 | let diff_2 = BufferDiffSnapshot::new_sync(buffer.clone(), base_text.clone(), cx); |
| 1966 | 1998 | assert_eq!(None, diff_2.inner.compare(&diff_1.inner, &buffer)); |
| @@ -1978,6 +2010,7 @@ mod tests { · 11 unmodified lines | ||
| 1978 | 2010 | NINE |
| 1979 | 2011 | " |
| 1980 | 2012 | .unindent(), |
| 2013 | + cx.background_executor(), | |
| 1981 | 2014 | ); |
| 1982 | 2015 | let diff_3 = BufferDiffSnapshot::new_sync(buffer.clone(), base_text.clone(), cx); |
| 1983 | 2016 | let range = diff_3.inner.compare(&diff_2.inner, &buffer).unwrap(); |
| @@ -1995,6 +2028,7 @@ mod tests { · 11 unmodified lines | ||
| 1995 | 2028 | NINE |
| 1996 | 2029 | " |
| 1997 | 2030 | .unindent(), |
| 2031 | + cx.background_executor(), | |
| 1998 | 2032 | ); |
| 1999 | 2033 | let diff_4 = BufferDiffSnapshot::new_sync(buffer.clone(), base_text.clone(), cx); |
| 2000 | 2034 | let range = diff_4.inner.compare(&diff_3.inner, &buffer).unwrap(); |
| @@ -2013,6 +2047,7 @@ mod tests { · 12 unmodified lines | ||
| 2013 | 2047 | NINE |
| 2014 | 2048 | " |
| 2015 | 2049 | .unindent(), |
| 2050 | + cx.background_executor(), | |
| 2016 | 2051 | ); |
| 2017 | 2052 | let diff_5 = BufferDiffSnapshot::new_sync(buffer.snapshot(), base_text.clone(), cx); |
| 2018 | 2053 | let range = diff_5.inner.compare(&diff_4.inner, &buffer).unwrap(); |
| @@ -2031,6 +2066,7 @@ mod tests { · 12 unmodified lines | ||
| 2031 | 2066 | «nine» |
| 2032 | 2067 | " |
| 2033 | 2068 | .unindent(), |
| 2069 | + cx.background_executor(), | |
| 2034 | 2070 | ); |
| 2035 | 2071 | let diff_6 = BufferDiffSnapshot::new_sync(buffer.snapshot(), base_text, cx); |
| 2036 | 2072 | let range = diff_6.inner.compare(&diff_5.inner, &buffer).unwrap(); |
| @@ -2140,14 +2176,14 @@ mod tests { · 103 unmodified lines | ||
| 2140 | 2176 | let working_copy = gen_working_copy(rng, &head_text); |
| 2141 | 2177 | let working_copy = cx.new(|cx| { |
| 2142 | 2178 | language::Buffer::local_normalized( |
| 2143 | − Rope::from(working_copy.as_str()), | |
| 2179 | + Rope::from_str(working_copy.as_str(), cx.background_executor()), | |
| 2144 | 2180 | text::LineEnding::default(), |
| 2145 | 2181 | cx, |
| 2146 | 2182 | ) |
| 2147 | 2183 | }); |
| 2148 | 2184 | let working_copy = working_copy.read_with(cx, |working_copy, _| working_copy.snapshot()); |
| 2149 | 2185 | let mut index_text = if rng.random() { |
| 2150 | − Rope::from(head_text.as_str()) | |
| 2186 | + Rope::from_str(head_text.as_str(), cx.background_executor()) | |
| 2151 | 2187 | } else { |
| 2152 | 2188 | working_copy.as_rope().clone() |
| 2153 | 2189 | }; |
| @@ -70,6 +70,7 @@ impl ChannelBuffer { · 69 unmodified lines | ||
| 70 | 70 | ReplicaId::new(response.replica_id as u16), |
| 71 | 71 | capability, |
| 72 | 72 | base_text, |
| 73 | + cx.background_executor(), | |
| 73 | 74 | ) |
| 74 | 75 | })?; |
| 75 | 76 | buffer.update(cx, |buffer, cx| buffer.apply_ops(operations, cx))?; |
| @@ -701,12 +701,12 @@ impl Database { · 700 unmodified lines | ||
| 701 | 701 | return Ok(()); |
| 702 | 702 | } |
| 703 | 703 | |
| 704 | − let mut text_buffer = text::Buffer::new( | |
| 704 | + let mut text_buffer = text::Buffer::new_slow( | |
| 705 | 705 | clock::ReplicaId::LOCAL, |
| 706 | 706 | text::BufferId::new(1).unwrap(), |
| 707 | 707 | base_text, |
| 708 | 708 | ); |
| 709 | − text_buffer.apply_ops(operations.into_iter().filter_map(operation_from_wire)); | |
| 709 | + text_buffer.apply_ops(operations.into_iter().filter_map(operation_from_wire), None); | |
| 710 | 710 | |
| 711 | 711 | let base_text = text_buffer.text(); |
| 712 | 712 | let epoch = buffer.epoch + 1; |
| @@ -74,11 +74,21 @@ async fn test_channel_buffers(db: &Arc<Database>) { · 73 unmodified lines | ||
| 74 | 74 | ReplicaId::new(0), |
| 75 | 75 | text::BufferId::new(1).unwrap(), |
| 76 | 76 | "".to_string(), |
| 77 | + &db.test_options.as_ref().unwrap().executor, | |
| 77 | 78 | ); |
| 78 | 79 | let operations = vec![ |
| 79 | − buffer_a.edit([(0..0, "hello world")]), | |
| 80 | − buffer_a.edit([(5..5, ", cruel")]), | |
| 81 | − buffer_a.edit([(0..5, "goodbye")]), | |
| 80 | + buffer_a.edit( | |
| 81 | + [(0..0, "hello world")], | |
| 82 | + &db.test_options.as_ref().unwrap().executor, | |
| 83 | + ), | |
| 84 | + buffer_a.edit( | |
| 85 | + [(5..5, ", cruel")], | |
| 86 | + &db.test_options.as_ref().unwrap().executor, | |
| 87 | + ), | |
| 88 | + buffer_a.edit( | |
| 89 | + [(0..5, "goodbye")], | |
| 90 | + &db.test_options.as_ref().unwrap().executor, | |
| 91 | + ), | |
| 82 | 92 | buffer_a.undo().unwrap().1, |
| 83 | 93 | ]; |
| 84 | 94 | assert_eq!(buffer_a.text(), "hello, cruel world"); |
| @@ -102,15 +112,19 @@ async fn test_channel_buffers(db: &Arc<Database>) { · 17 unmodified lines | ||
| 102 | 112 | ReplicaId::new(0), |
| 103 | 113 | text::BufferId::new(1).unwrap(), |
| 104 | 114 | buffer_response_b.base_text, |
| 115 | + &db.test_options.as_ref().unwrap().executor, | |
| 116 | + ); | |
| 117 | + buffer_b.apply_ops( | |
| 118 | + buffer_response_b.operations.into_iter().map(|operation| { | |
| 119 | + let operation = proto::deserialize_operation(operation).unwrap(); | |
| 120 | + if let language::Operation::Buffer(operation) = operation { | |
| 121 | + operation | |
| 122 | + } else { | |
| 123 | + unreachable!() | |
| 124 | + } | |
| 125 | + }), | |
| 126 | + None, | |
| 105 | 127 | ); |
| 106 | − buffer_b.apply_ops(buffer_response_b.operations.into_iter().map(|operation| { | |
| 107 | − let operation = proto::deserialize_operation(operation).unwrap(); | |
| 108 | − if let language::Operation::Buffer(operation) = operation { | |
| 109 | − operation | |
| 110 | − } else { | |
| 111 | − unreachable!() | |
| 112 | − } | |
| 113 | − })); | |
| 114 | 128 | |
| 115 | 129 | assert_eq!(buffer_b.text(), "hello, cruel world"); |
| 116 | 130 | |
| @@ -247,6 +261,7 @@ async fn test_channel_buffers_last_operations(db: &Database) { · 130 unmodified lines | ||
| 247 | 261 | ReplicaId::new(res.replica_id as u16), |
| 248 | 262 | text::BufferId::new(1).unwrap(), |
| 249 | 263 | "".to_string(), |
| 264 | + &db.test_options.as_ref().unwrap().executor, | |
| 250 | 265 | )); |
| 251 | 266 | } |
| 252 | 267 | |
| @@ -255,9 +270,9 @@ async fn test_channel_buffers_last_operations(db: &Database) { · 2 unmodified lines | ||
| 255 | 270 | user_id, |
| 256 | 271 | db, |
| 257 | 272 | vec![ |
| 258 | − text_buffers[0].edit([(0..0, "a")]), | |
| 259 | − text_buffers[0].edit([(0..0, "b")]), | |
| 260 | − text_buffers[0].edit([(0..0, "c")]), | |
| 273 | + text_buffers[0].edit([(0..0, "a")], &db.test_options.as_ref().unwrap().executor), | |
| 274 | + text_buffers[0].edit([(0..0, "b")], &db.test_options.as_ref().unwrap().executor), | |
| 275 | + text_buffers[0].edit([(0..0, "c")], &db.test_options.as_ref().unwrap().executor), | |
| 261 | 276 | ], |
| 262 | 277 | ) |
| 263 | 278 | .await; |
| @@ -267,9 +282,9 @@ async fn test_channel_buffers_last_operations(db: &Database) { · 3 unmodified lines | ||
| 267 | 282 | user_id, |
| 268 | 283 | db, |
| 269 | 284 | vec![ |
| 270 | − text_buffers[1].edit([(0..0, "d")]), | |
| 271 | − text_buffers[1].edit([(1..1, "e")]), | |
| 272 | − text_buffers[1].edit([(2..2, "f")]), | |
| 285 | + text_buffers[1].edit([(0..0, "d")], &db.test_options.as_ref().unwrap().executor), | |
| 286 | + text_buffers[1].edit([(1..1, "e")], &db.test_options.as_ref().unwrap().executor), | |
| 287 | + text_buffers[1].edit([(2..2, "f")], &db.test_options.as_ref().unwrap().executor), | |
| 273 | 288 | ], |
| 274 | 289 | ) |
| 275 | 290 | .await; |
| @@ -286,14 +301,15 @@ async fn test_channel_buffers_last_operations(db: &Database) { · 10 unmodified lines | ||
| 286 | 301 | replica_id, |
| 287 | 302 | text::BufferId::new(1).unwrap(), |
| 288 | 303 | "def".to_string(), |
| 304 | + &db.test_options.as_ref().unwrap().executor, | |
| 289 | 305 | ); |
| 290 | 306 | update_buffer( |
| 291 | 307 | buffers[1].channel_id, |
| 292 | 308 | user_id, |
| 293 | 309 | db, |
| 294 | 310 | vec![ |
| 295 | − text_buffers[1].edit([(0..0, "g")]), | |
| 296 | − text_buffers[1].edit([(0..0, "h")]), | |
| 311 | + text_buffers[1].edit([(0..0, "g")], &db.test_options.as_ref().unwrap().executor), | |
| 312 | + text_buffers[1].edit([(0..0, "h")], &db.test_options.as_ref().unwrap().executor), | |
| 297 | 313 | ], |
| 298 | 314 | ) |
| 299 | 315 | .await; |
| @@ -302,7 +318,7 @@ async fn test_channel_buffers_last_operations(db: &Database) { · 2 unmodified lines | ||
| 302 | 318 | buffers[2].channel_id, |
| 303 | 319 | user_id, |
| 304 | 320 | db, |
| 305 | − vec![text_buffers[2].edit([(0..0, "i")])], | |
| 321 | + vec![text_buffers[2].edit([(0..0, "i")], &db.test_options.as_ref().unwrap().executor)], | |
| 306 | 322 | ) |
| 307 | 323 | .await; |
| 308 | 324 | |
| @@ -3694,7 +3694,7 @@ async fn test_buffer_reloading( · 3693 unmodified lines | ||
| 3694 | 3694 | assert_eq!(buf.line_ending(), LineEnding::Unix); |
| 3695 | 3695 | }); |
| 3696 | 3696 | |
| 3697 | − let new_contents = Rope::from("d\ne\nf"); | |
| 3697 | + let new_contents = Rope::from_str_small("d\ne\nf"); | |
| 3698 | 3698 | client_a |
| 3699 | 3699 | .fs() |
| 3700 | 3700 | .save( |
| @@ -4479,7 +4479,7 @@ async fn test_reloading_buffer_manually( · 778 unmodified lines | ||
| 4479 | 4479 | .fs() |
| 4480 | 4480 | .save( |
| 4481 | 4481 | path!("/a/a.rs").as_ref(), |
| 4482 | − &Rope::from("let seven = 7;"), | |
| 4482 | + &Rope::from_str_small("let seven = 7;"), | |
| 4483 | 4483 | LineEnding::Unix, |
| 4484 | 4484 | ) |
| 4485 | 4485 | .await |
| @@ -27,6 +27,7 @@ use std::{ · 26 unmodified lines | ||
| 27 | 27 | rc::Rc, |
| 28 | 28 | sync::Arc, |
| 29 | 29 | }; |
| 30 | +use text::Rope; | |
| 30 | 31 | use util::{ |
| 31 | 32 | ResultExt, path, |
| 32 | 33 | paths::PathStyle, |
| @@ -938,7 +939,11 @@ impl RandomizedTest for ProjectCollaborationTest { · 905 unmodified lines | ||
| 938 | 939 | |
| 939 | 940 | client |
| 940 | 941 | .fs() |
| 941 | − .save(&path, &content.as_str().into(), text::LineEnding::Unix) | |
| 942 | + .save( | |
| 943 | + &path, | |
| 944 | + &Rope::from_str_small(content.as_str()), | |
| 945 | + text::LineEnding::Unix, | |
| 946 | + ) | |
| 942 | 947 | .await |
| 943 | 948 | .unwrap(); |
| 944 | 949 | } |
| @@ -877,7 +877,7 @@ async fn test_random_diagnostics_with_inlays(cx: &mut TestAppContext, mut rng: S · 876 unmodified lines | ||
| 877 | 877 | vec![Inlay::edit_prediction( |
| 878 | 878 | post_inc(&mut next_inlay_id), |
| 879 | 879 | snapshot.buffer_snapshot().anchor_before(position), |
| 880 | − Rope::from_iter(["Test inlay ", "next_inlay_id"]), | |
| 880 | + Rope::from_iter_small(["Test inlay ", "next_inlay_id"]), | |
| 881 | 881 | )], |
| 882 | 882 | cx, |
| 883 | 883 | ); |
| @@ -2070,7 +2070,7 @@ fn random_lsp_diagnostic( · 1186 unmodified lines | ||
| 2070 | 2070 | const ERROR_MARGIN: usize = 10; |
| 2071 | 2071 | |
| 2072 | 2072 | let file_content = fs.read_file_sync(path).unwrap(); |
| 2073 | − let file_text = Rope::from(String::from_utf8_lossy(&file_content).as_ref()); | |
| 2073 | + let file_text = Rope::from_str_small(String::from_utf8_lossy(&file_content).as_ref()); | |
| 2074 | 2074 | |
| 2075 | 2075 | let start = rng.random_range(0..file_text.len().saturating_add(ERROR_MARGIN)); |
| 2076 | 2076 | let end = rng.random_range(start..file_text.len().saturating_add(ERROR_MARGIN)); |
| @@ -13,7 +13,7 @@ use gpui::{ · 12 unmodified lines | ||
| 13 | 13 | }; |
| 14 | 14 | use indoc::indoc; |
| 15 | 15 | use language::{ |
| 16 | − EditPredictionsMode, File, Language, | |
| 16 | + EditPredictionsMode, File, Language, Rope, | |
| 17 | 17 | language_settings::{self, AllLanguageSettings, EditPredictionProvider, all_language_settings}, |
| 18 | 18 | }; |
| 19 | 19 | use project::DisableAiSettings; |
| @@ -1056,8 +1056,11 @@ async fn open_disabled_globs_setting_in_editor( · 1036 unmodified lines | ||
| 1056 | 1056 | ) -> Result<()> { |
| 1057 | 1057 | let settings_editor = workspace |
| 1058 | 1058 | .update_in(cx, |_, window, cx| { |
| 1059 | − create_and_open_local_file(paths::settings_file(), window, cx, || { | |
| 1060 | − settings::initial_user_settings_content().as_ref().into() | |
| 1059 | + create_and_open_local_file(paths::settings_file(), window, cx, |cx| { | |
| 1060 | + Rope::from_str( | |
| 1061 | + settings::initial_user_settings_content().as_ref(), | |
| 1062 | + cx.background_executor(), | |
| 1063 | + ) | |
| 1061 | 1064 | }) |
| 1062 | 1065 | })? |
| 1063 | 1066 | .await? |
| @@ -1569,6 +1569,7 @@ pub mod tests { · 1568 unmodified lines | ||
| 1569 | 1569 | use lsp::LanguageServerId; |
| 1570 | 1570 | use project::Project; |
| 1571 | 1571 | use rand::{Rng, prelude::*}; |
| 1572 | + use rope::Rope; | |
| 1572 | 1573 | use settings::{SettingsContent, SettingsStore}; |
| 1573 | 1574 | use smol::stream::StreamExt; |
| 1574 | 1575 | use std::{env, sync::Arc}; |
| @@ -2074,7 +2075,7 @@ pub mod tests { · 499 unmodified lines | ||
| 2074 | 2075 | vec![Inlay::edit_prediction( |
| 2075 | 2076 | 0, |
| 2076 | 2077 | buffer_snapshot.anchor_after(0), |
| 2077 | − "\n", | |
| 2078 | + Rope::from_str_small("\n"), | |
| 2078 | 2079 | )], |
| 2079 | 2080 | cx, |
| 2080 | 2081 | ); |
| @@ -700,16 +700,20 @@ impl InlayMap { · 699 unmodified lines | ||
| 700 | 700 | .collect::<String>(); |
| 701 | 701 | |
| 702 | 702 | let next_inlay = if i % 2 == 0 { |
| 703 | + use rope::Rope; | |
| 704 | + | |
| 703 | 705 | Inlay::mock_hint( |
| 704 | 706 | post_inc(next_inlay_id), |
| 705 | 707 | snapshot.buffer.anchor_at(position, bias), |
| 706 | − &text, | |
| 708 | + Rope::from_str_small(&text), | |
| 707 | 709 | ) |
| 708 | 710 | } else { |
| 711 | + use rope::Rope; | |
| 712 | + | |
| 709 | 713 | Inlay::edit_prediction( |
| 710 | 714 | post_inc(next_inlay_id), |
| 711 | 715 | snapshot.buffer.anchor_at(position, bias), |
| 712 | − &text, | |
| 716 | + Rope::from_str_small(&text), | |
| 713 | 717 | ) |
| 714 | 718 | }; |
| 715 | 719 | let inlay_id = next_inlay.id; |
| @@ -1301,7 +1305,7 @@ mod tests { · 585 unmodified lines | ||
| 1301 | 1305 | vec![Inlay::mock_hint( |
| 1302 | 1306 | post_inc(&mut next_inlay_id), |
| 1303 | 1307 | buffer.read(cx).snapshot(cx).anchor_after(3), |
| 1304 | − "|123|", | |
| 1308 | + Rope::from_str_small("|123|"), | |
| 1305 | 1309 | )], |
| 1306 | 1310 | ); |
| 1307 | 1311 | assert_eq!(inlay_snapshot.text(), "abc|123|defghi"); |
| @@ -1378,12 +1382,12 @@ mod tests { · 70 unmodified lines | ||
| 1378 | 1382 | Inlay::mock_hint( |
| 1379 | 1383 | post_inc(&mut next_inlay_id), |
| 1380 | 1384 | buffer.read(cx).snapshot(cx).anchor_before(3), |
| 1381 | − "|123|", | |
| 1385 | + Rope::from_str_small("|123|"), | |
| 1382 | 1386 | ), |
| 1383 | 1387 | Inlay::edit_prediction( |
| 1384 | 1388 | post_inc(&mut next_inlay_id), |
| 1385 | 1389 | buffer.read(cx).snapshot(cx).anchor_after(3), |
| 1386 | − "|456|", | |
| 1390 | + Rope::from_str_small("|456|"), | |
| 1387 | 1391 | ), |
| 1388 | 1392 | ], |
| 1389 | 1393 | ); |
| @@ -1593,17 +1597,17 @@ mod tests { · 203 unmodified lines | ||
| 1593 | 1597 | Inlay::mock_hint( |
| 1594 | 1598 | post_inc(&mut next_inlay_id), |
| 1595 | 1599 | buffer.read(cx).snapshot(cx).anchor_before(0), |
| 1596 | − "|123|\n", | |
| 1600 | + Rope::from_str_small("|123|\n"), | |
| 1597 | 1601 | ), |
| 1598 | 1602 | Inlay::mock_hint( |
| 1599 | 1603 | post_inc(&mut next_inlay_id), |
| 1600 | 1604 | buffer.read(cx).snapshot(cx).anchor_before(4), |
| 1601 | − "|456|", | |
| 1605 | + Rope::from_str_small("|456|"), | |
| 1602 | 1606 | ), |
| 1603 | 1607 | Inlay::edit_prediction( |
| 1604 | 1608 | post_inc(&mut next_inlay_id), |
| 1605 | 1609 | buffer.read(cx).snapshot(cx).anchor_before(7), |
| 1606 | − "\n|567|\n", | |
| 1610 | + Rope::from_str_small("\n|567|\n"), | |
| 1607 | 1611 | ), |
| 1608 | 1612 | ], |
| 1609 | 1613 | ); |
| @@ -1677,9 +1681,14 @@ mod tests { · 67 unmodified lines | ||
| 1677 | 1681 | (offset, inlay.clone()) |
| 1678 | 1682 | }) |
| 1679 | 1683 | .collect::<Vec<_>>(); |
| 1680 | − let mut expected_text = Rope::from(&buffer_snapshot.text()); | |
| 1684 | + let mut expected_text = | |
| 1685 | + Rope::from_str(&buffer_snapshot.text(), cx.background_executor()); | |
| 1681 | 1686 | for (offset, inlay) in inlays.iter().rev() { |
| 1682 | − expected_text.replace(*offset..*offset, &inlay.text().to_string()); | |
| 1687 | + expected_text.replace( | |
| 1688 | + *offset..*offset, | |
| 1689 | + &inlay.text().to_string(), | |
| 1690 | + cx.background_executor(), | |
| 1691 | + ); | |
| 1683 | 1692 | } |
| 1684 | 1693 | assert_eq!(inlay_snapshot.text(), expected_text.to_string()); |
| 1685 | 1694 | |
| @@ -2067,7 +2076,7 @@ mod tests { · 381 unmodified lines | ||
| 2067 | 2076 | let inlay = Inlay { |
| 2068 | 2077 | id: InlayId::Hint(0), |
| 2069 | 2078 | position, |
| 2070 | − content: InlayContent::Text(text::Rope::from(inlay_text)), | |
| 2079 | + content: InlayContent::Text(text::Rope::from_str(inlay_text, cx.background_executor())), | |
| 2071 | 2080 | }; |
| 2072 | 2081 | |
| 2073 | 2082 | let (inlay_snapshot, _) = inlay_map.splice(&[], vec![inlay]); |
| @@ -2181,7 +2190,10 @@ mod tests { · 107 unmodified lines | ||
| 2181 | 2190 | let inlay = Inlay { |
| 2182 | 2191 | id: InlayId::Hint(0), |
| 2183 | 2192 | position, |
| 2184 | − content: InlayContent::Text(text::Rope::from(test_case.inlay_text)), | |
| 2193 | + content: InlayContent::Text(text::Rope::from_str( | |
| 2194 | + test_case.inlay_text, | |
| 2195 | + cx.background_executor(), | |
| 2196 | + )), | |
| 2185 | 2197 | }; |
| 2186 | 2198 | |
| 2187 | 2199 | let (inlay_snapshot, _) = inlay_map.splice(&[], vec![inlay]); |
| @@ -1042,7 +1042,7 @@ mod tests { · 1041 unmodified lines | ||
| 1042 | 1042 | let (mut tab_map, _) = TabMap::new(fold_snapshot, tab_size); |
| 1043 | 1043 | let tabs_snapshot = tab_map.set_max_expansion_column(32); |
| 1044 | 1044 | |
| 1045 | − let text = text::Rope::from(tabs_snapshot.text().as_str()); | |
| 1045 | + let text = text::Rope::from_str(tabs_snapshot.text().as_str(), cx.background_executor()); | |
| 1046 | 1046 | log::info!( |
| 1047 | 1047 | "TabMap text (tab size: {}): {:?}", |
| 1048 | 1048 | tab_size, |
| @@ -863,7 +863,7 @@ impl WrapSnapshot { · 862 unmodified lines | ||
| 863 | 863 | } |
| 864 | 864 | } |
| 865 | 865 | |
| 866 | − let text = language::Rope::from(self.text().as_str()); | |
| 866 | + let text = language::Rope::from_str_small(self.text().as_str()); | |
| 867 | 867 | let mut input_buffer_rows = self.tab_snapshot.rows(0); |
| 868 | 868 | let mut expected_buffer_rows = Vec::new(); |
| 869 | 869 | let mut prev_tab_row = 0; |
| @@ -1413,9 +1413,10 @@ mod tests { · 543 unmodified lines | ||
| 1413 | 1413 | } |
| 1414 | 1414 | } |
| 1415 | 1415 | |
| 1416 | − let mut initial_text = Rope::from(initial_snapshot.text().as_str()); | |
| 1416 | + let mut initial_text = | |
| 1417 | + Rope::from_str(initial_snapshot.text().as_str(), cx.background_executor()); | |
| 1417 | 1418 | for (snapshot, patch) in edits { |
| 1418 | − let snapshot_text = Rope::from(snapshot.text().as_str()); | |
| 1419 | + let snapshot_text = Rope::from_str(snapshot.text().as_str(), cx.background_executor()); | |
| 1419 | 1420 | for edit in &patch { |
| 1420 | 1421 | let old_start = initial_text.point_to_offset(Point::new(edit.new.start, 0)); |
| 1421 | 1422 | let old_end = initial_text.point_to_offset(cmp::min( |
| @@ -1431,7 +1432,7 @@ mod tests { · 9 unmodified lines | ||
| 1431 | 1432 | .chunks_in_range(new_start..new_end) |
| 1432 | 1433 | .collect::<String>(); |
| 1433 | 1434 | |
| 1434 | − initial_text.replace(old_start..old_end, &new_text); | |
| 1435 | + initial_text.replace(old_start..old_end, &new_text, cx.background_executor()); | |
| 1435 | 1436 | } |
| 1436 | 1437 | assert_eq!(initial_text.to_string(), snapshot_text.to_string()); |
| 1437 | 1438 | } |
| @@ -7852,7 +7852,7 @@ impl Editor { · 7851 unmodified lines | ||
| 7852 | 7852 | let inlay = Inlay::edit_prediction( |
| 7853 | 7853 | post_inc(&mut self.next_inlay_id), |
| 7854 | 7854 | range.start, |
| 7855 | − new_text.as_str(), | |
| 7855 | + Rope::from_str_small(new_text.as_str()), | |
| 7856 | 7856 | ); |
| 7857 | 7857 | inlay_ids.push(inlay.id); |
| 7858 | 7858 | inlays.push(inlay); |
| @@ -1115,18 +1115,19 @@ mod tests { · 1114 unmodified lines | ||
| 1115 | 1115 | |
| 1116 | 1116 | let fs = FakeFs::new(cx.executor()); |
| 1117 | 1117 | let buffer_initial_text_len = rng.random_range(5..15); |
| 1118 | − let mut buffer_initial_text = Rope::from( | |
| 1118 | + let mut buffer_initial_text = Rope::from_str( | |
| 1119 | 1119 | RandomCharIter::new(&mut rng) |
| 1120 | 1120 | .take(buffer_initial_text_len) |
| 1121 | 1121 | .collect::<String>() |
| 1122 | 1122 | .as_str(), |
| 1123 | + cx.background_executor(), | |
| 1123 | 1124 | ); |
| 1124 | 1125 | |
| 1125 | 1126 | let mut newline_ixs = (0..buffer_initial_text_len).choose_multiple(&mut rng, 5); |
| 1126 | 1127 | newline_ixs.sort_unstable(); |
| 1127 | 1128 | for newline_ix in newline_ixs.into_iter().rev() { |
| 1128 | 1129 | let newline_ix = buffer_initial_text.clip_offset(newline_ix, Bias::Right); |
| 1129 | − buffer_initial_text.replace(newline_ix..newline_ix, "\n"); | |
| 1130 | + buffer_initial_text.replace(newline_ix..newline_ix, "\n", cx.background_executor()); | |
| 1130 | 1131 | } |
| 1131 | 1132 | log::info!("initial buffer text: {:?}", buffer_initial_text); |
| 1132 | 1133 | |
| @@ -59,10 +59,10 @@ impl Inlay { · 58 unmodified lines | ||
| 59 | 59 | pub fn hint(id: InlayId, position: Anchor, hint: &InlayHint) -> Self { |
| 60 | 60 | let mut text = hint.text(); |
| 61 | 61 | if hint.padding_right && text.reversed_chars_at(text.len()).next() != Some(' ') { |
| 62 | − text.push(" "); | |
| 62 | + text.push_small(" "); | |
| 63 | 63 | } |
| 64 | 64 | if hint.padding_left && text.chars_at(0).next() != Some(' ') { |
| 65 | − text.push_front(" "); | |
| 65 | + text.push_front_small(" "); | |
| 66 | 66 | } |
| 67 | 67 | Self { |
| 68 | 68 | id, |
| @@ -72,11 +72,11 @@ impl Inlay { · 3 unmodified lines | ||
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | #[cfg(any(test, feature = "test-support"))] |
| 75 | − pub fn mock_hint(id: usize, position: Anchor, text: impl Into<Rope>) -> Self { | |
| 75 | + pub fn mock_hint(id: usize, position: Anchor, text: Rope) -> Self { | |
| 76 | 76 | Self { |
| 77 | 77 | id: InlayId::Hint(id), |
| 78 | 78 | position, |
| 79 | − content: InlayContent::Text(text.into()), | |
| 79 | + content: InlayContent::Text(text), | |
| 80 | 80 | } |
| 81 | 81 | } |
| 82 | 82 | |
| @@ -88,19 +88,19 @@ impl Inlay { · 5 unmodified lines | ||
| 88 | 88 | } |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | − pub fn edit_prediction<T: Into<Rope>>(id: usize, position: Anchor, text: T) -> Self { | |
| 91 | + pub fn edit_prediction(id: usize, position: Anchor, text: Rope) -> Self { | |
| 92 | 92 | Self { |
| 93 | 93 | id: InlayId::EditPrediction(id), |
| 94 | 94 | position, |
| 95 | − content: InlayContent::Text(text.into()), | |
| 95 | + content: InlayContent::Text(text), | |
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | − pub fn debugger<T: Into<Rope>>(id: usize, position: Anchor, text: T) -> Self { | |
| 99 | + pub fn debugger(id: usize, position: Anchor, text: Rope) -> Self { | |
| 100 | 100 | Self { |
| 101 | 101 | id: InlayId::DebuggerValue(id), |
| 102 | 102 | position, |
| 103 | − content: InlayContent::Text(text.into()), | |
| 103 | + content: InlayContent::Text(text), | |
| 104 | 104 | } |
| 105 | 105 | } |
| 106 | 106 | |
| @@ -108,7 +108,7 @@ impl Inlay { · 1 unmodified line | ||
| 108 | 108 | static COLOR_TEXT: OnceLock<Rope> = OnceLock::new(); |
| 109 | 109 | match &self.content { |
| 110 | 110 | InlayContent::Text(text) => text, |
| 111 | − InlayContent::Color(_) => COLOR_TEXT.get_or_init(|| Rope::from("◼")), | |
| 111 | + InlayContent::Color(_) => COLOR_TEXT.get_or_init(|| Rope::from_str_small("◼")), | |
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | |
| @@ -878,6 +878,7 @@ mod tests { · 877 unmodified lines | ||
| 878 | 878 | use gpui::{AppContext as _, font, px}; |
| 879 | 879 | use language::Capability; |
| 880 | 880 | use project::{Project, project_settings::DiagnosticSeverity}; |
| 881 | + use rope::Rope; | |
| 881 | 882 | use settings::SettingsStore; |
| 882 | 883 | use util::post_inc; |
| 883 | 884 | |
| @@ -1024,22 +1025,22 @@ mod tests { · 140 unmodified lines | ||
| 1024 | 1025 | Inlay::edit_prediction( |
| 1025 | 1026 | post_inc(&mut id), |
| 1026 | 1027 | buffer_snapshot.anchor_before(offset), |
| 1027 | − "test", | |
| 1028 | + Rope::from_str_small("test"), | |
| 1028 | 1029 | ), |
| 1029 | 1030 | Inlay::edit_prediction( |
| 1030 | 1031 | post_inc(&mut id), |
| 1031 | 1032 | buffer_snapshot.anchor_after(offset), |
| 1032 | − "test", | |
| 1033 | + Rope::from_str_small("test"), | |
| 1033 | 1034 | ), |
| 1034 | 1035 | Inlay::mock_hint( |
| 1035 | 1036 | post_inc(&mut id), |
| 1036 | 1037 | buffer_snapshot.anchor_before(offset), |
| 1037 | − "test", | |
| 1038 | + Rope::from_str_small("test"), | |
| 1038 | 1039 | ), |
| 1039 | 1040 | Inlay::mock_hint( |
| 1040 | 1041 | post_inc(&mut id), |
| 1041 | 1042 | buffer_snapshot.anchor_after(offset), |
| 1042 | − "test", | |
| 1043 | + Rope::from_str_small("test"), | |
| 1043 | 1044 | ), |
| 1044 | 1045 | ] |
| 1045 | 1046 | }) |
| @@ -193,7 +193,7 @@ impl Editor { · 192 unmodified lines | ||
| 193 | 193 | |
| 194 | 194 | if let Some(language) = language { |
| 195 | 195 | for signature in &mut signature_help.signatures { |
| 196 | − let text = Rope::from(signature.label.as_ref()); | |
| 196 | + let text = Rope::from_str_small(signature.label.as_ref()); | |
| 197 | 197 | let highlights = language |
| 198 | 198 | .highlight_text(&text, 0..signature.label.len()) |
| 199 | 199 | .into_iter() |
| @@ -1468,6 +1468,7 @@ impl ExtensionStore { · 1467 unmodified lines | ||
| 1468 | 1468 | let extensions_dir = self.installed_dir.clone(); |
| 1469 | 1469 | let index_path = self.index_path.clone(); |
| 1470 | 1470 | let proxy = self.proxy.clone(); |
| 1471 | + let executor = cx.background_executor().clone(); | |
| 1471 | 1472 | cx.background_spawn(async move { |
| 1472 | 1473 | let start_time = Instant::now(); |
| 1473 | 1474 | let mut index = ExtensionIndex::default(); |
| @@ -1501,10 +1502,14 @@ impl ExtensionStore { · 27 unmodified lines | ||
| 1501 | 1502 | } |
| 1502 | 1503 | |
| 1503 | 1504 | if let Ok(index_json) = serde_json::to_string_pretty(&index) { |
| 1504 | − fs.save(&index_path, &index_json.as_str().into(), Default::default()) | |
| 1505 | − .await | |
| 1506 | − .context("failed to save extension index") | |
| 1507 | − .log_err(); | |
| 1505 | + fs.save( | |
| 1506 | + &index_path, | |
| 1507 | + &Rope::from_str(&index_json, &executor), | |
| 1508 | + Default::default(), | |
| 1509 | + ) | |
| 1510 | + .await | |
| 1511 | + .context("failed to save extension index") | |
| 1512 | + .log_err(); | |
| 1508 | 1513 | } |
| 1509 | 1514 | |
| 1510 | 1515 | log::info!("rebuilt extension index in {:?}", start_time.elapsed()); |
| @@ -1671,7 +1676,7 @@ impl ExtensionStore { · 160 unmodified lines | ||
| 1671 | 1676 | let manifest_toml = toml::to_string(&loaded_extension.manifest)?; |
| 1672 | 1677 | fs.save( |
| 1673 | 1678 | &tmp_dir.join(EXTENSION_TOML), |
| 1674 | − &Rope::from(manifest_toml), | |
| 1679 | + &Rope::from_str_small(&manifest_toml), | |
| 1675 | 1680 | language::LineEnding::Unix, |
| 1676 | 1681 | ) |
| 1677 | 1682 | .await?; |
| @@ -170,7 +170,10 @@ impl CommitView { · 169 unmodified lines | ||
| 170 | 170 | ReplicaId::LOCAL, |
| 171 | 171 | cx.entity_id().as_non_zero_u64().into(), |
| 172 | 172 | LineEnding::default(), |
| 173 | − format_commit(&commit, stash.is_some()).into(), | |
| 173 | + Rope::from_str( | |
| 174 | + &format_commit(&commit, stash.is_some()), | |
| 175 | + cx.background_executor(), | |
| 176 | + ), | |
| 174 | 177 | ); |
| 175 | 178 | metadata_buffer_id = Some(buffer.remote_id()); |
| 176 | 179 | Buffer::build(buffer, Some(file.clone()), Capability::ReadWrite) |
| @@ -336,7 +339,7 @@ async fn build_buffer( · 159 unmodified lines | ||
| 336 | 339 | ) -> Result<Entity<Buffer>> { |
| 337 | 340 | let line_ending = LineEnding::detect(&text); |
| 338 | 341 | LineEnding::normalize(&mut text); |
| 339 | − let text = Rope::from(text); | |
| 342 | + let text = Rope::from_str(&text, cx.background_executor()); | |
| 340 | 343 | let language = cx.update(|cx| language_registry.language_for_file(&blob, Some(&text), cx))?; |
| 341 | 344 | let language = if let Some(language) = language { |
| 342 | 345 | language_registry |
| @@ -376,7 +379,7 @@ async fn build_buffer_diff( · 33 unmodified lines | ||
| 376 | 379 | let base_buffer = cx |
| 377 | 380 | .update(|cx| { |
| 378 | 381 | Buffer::build_snapshot( |
| 379 | − old_text.as_deref().unwrap_or("").into(), | |
| 382 | + Rope::from_str(old_text.as_deref().unwrap_or(""), cx.background_executor()), | |
| 380 | 383 | buffer.language().cloned(), |
| 381 | 384 | Some(language_registry.clone()), |
| 382 | 385 | cx, |
| @@ -359,6 +359,7 @@ mod tests { · 358 unmodified lines | ||
| 359 | 359 | use super::*; |
| 360 | 360 | use editor::test::editor_test_context::assert_state_with_diff; |
| 361 | 361 | use gpui::TestAppContext; |
| 362 | + use language::Rope; | |
| 362 | 363 | use project::{FakeFs, Fs, Project}; |
| 363 | 364 | use settings::SettingsStore; |
| 364 | 365 | use std::path::PathBuf; |
| @@ -429,7 +430,7 @@ mod tests { · 64 unmodified lines | ||
| 429 | 430 | // Modify the new file on disk |
| 430 | 431 | fs.save( |
| 431 | 432 | path!("/test/new_file.txt").as_ref(), |
| 432 | − &unindent( | |
| 433 | + &Rope::from_str_small(&unindent( | |
| 433 | 434 | " |
| 434 | 435 | new line 1 |
| 435 | 436 | line 2 |
| @@ -437,8 +438,7 @@ mod tests { · 1 unmodified line | ||
| 437 | 438 | line 4 |
| 438 | 439 | new line 5 |
| 439 | 440 | ", |
| 440 | − ) | |
| 441 | − .into(), | |
| 441 | + )), | |
| 442 | 442 | Default::default(), |
| 443 | 443 | ) |
| 444 | 444 | .await |
| @@ -465,15 +465,14 @@ mod tests { · 20 unmodified lines | ||
| 465 | 465 | // Modify the old file on disk |
| 466 | 466 | fs.save( |
| 467 | 467 | path!("/test/old_file.txt").as_ref(), |
| 468 | − &unindent( | |
| 468 | + &Rope::from_str_small(&unindent( | |
| 469 | 469 | " |
| 470 | 470 | new line 1 |
| 471 | 471 | line 2 |
| 472 | 472 | old line 3 |
| 473 | 473 | line 4 |
| 474 | 474 | ", |
| 475 | − ) | |
| 476 | − .into(), | |
| 475 | + )), | |
| 477 | 476 | Default::default(), |
| 478 | 477 | ) |
| 479 | 478 | .await |
| @@ -260,6 +260,19 @@ impl AsyncApp { · 259 unmodified lines | ||
| 260 | 260 | } |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | +impl sum_tree::BackgroundSpawn for BackgroundExecutor { | |
| 264 | + type Task<R> | |
| 265 | + = Task<R> | |
| 266 | + where | |
| 267 | + R: Send + Sync; | |
| 268 | + fn background_spawn<R>(&self, future: impl Future<Output = R> + Send + 'static) -> Self::Task<R> | |
| 269 | + where | |
| 270 | + R: Send + Sync + 'static, | |
| 271 | + { | |
| 272 | + self.spawn(future) | |
| 273 | + } | |
| 274 | +} | |
| 275 | + | |
| 263 | 276 | /// A cloneable, owned handle to the application context, |
| 264 | 277 | /// composed with the window associated with the current task. |
| 265 | 278 | #[derive(Clone, Deref, DerefMut)] |
| @@ -393,6 +393,11 @@ impl TestAppContext { · 392 unmodified lines | ||
| 393 | 393 | } |
| 394 | 394 | } |
| 395 | 395 | |
| 396 | + /// Returns the background executor for this context. | |
| 397 | + pub fn background_executor(&self) -> &BackgroundExecutor { | |
| 398 | + &self.background_executor | |
| 399 | + } | |
| 400 | + | |
| 396 | 401 | /// Wait until there are no more pending tasks. |
| 397 | 402 | pub fn run_until_parked(&mut self) { |
| 398 | 403 | self.background_executor.run_until_parked() |
| @@ -342,7 +342,7 @@ impl BackgroundExecutor { · 341 unmodified lines | ||
| 342 | 342 | /// for all of them to complete before returning. |
| 343 | 343 | pub async fn scoped<'scope, F>(&self, scheduler: F) |
| 344 | 344 | where |
| 345 | − F: FnOnce(&mut Scope<'scope>), | |
| 345 | + F: for<'a> FnOnce(&'a mut Scope<'scope>), | |
| 346 | 346 | { |
| 347 | 347 | let mut scope = Scope::new(self.clone()); |
| 348 | 348 | (scheduler)(&mut scope); |
| @@ -22,7 +22,7 @@ use gpui::{ · 21 unmodified lines | ||
| 22 | 22 | ScrollWheelEvent, Stateful, StyledText, Subscription, Task, TextStyleRefinement, WeakEntity, |
| 23 | 23 | actions, anchored, deferred, div, |
| 24 | 24 | }; |
| 25 | −use language::{Language, LanguageConfig, ToOffset as _}; | |
| 25 | +use language::{Language, LanguageConfig, Rope, ToOffset as _}; | |
| 26 | 26 | use notifications::status_toast::{StatusToast, ToastIcon}; |
| 27 | 27 | use project::{CompletionDisplayOptions, Project}; |
| 28 | 28 | use settings::{ |
| @@ -2119,7 +2119,7 @@ impl RenderOnce for SyntaxHighlightedText { · 2090 unmodified lines | ||
| 2119 | 2119 | |
| 2120 | 2120 | let highlights = self |
| 2121 | 2121 | .language |
| 2122 | − .highlight_text(&text.as_ref().into(), 0..text.len()); | |
| 2122 | + .highlight_text(&Rope::from_str_small(text.as_ref()), 0..text.len()); | |
| 2123 | 2123 | let mut runs = Vec::with_capacity(highlights.len()); |
| 2124 | 2124 | let mut offset = 0; |
| 2125 | 2125 | |
| @@ -24,8 +24,8 @@ use collections::HashMap; · 23 unmodified lines | ||
| 24 | 24 | use fs::MTime; |
| 25 | 25 | use futures::channel::oneshot; |
| 26 | 26 | use gpui::{ |
| 27 | − App, AppContext as _, Context, Entity, EventEmitter, HighlightStyle, SharedString, StyledText, | |
| 28 | − Task, TaskLabel, TextStyle, | |
| 27 | + App, AppContext as _, BackgroundExecutor, Context, Entity, EventEmitter, HighlightStyle, | |
| 28 | + SharedString, StyledText, Task, TaskLabel, TextStyle, | |
| 29 | 29 | }; |
| 30 | 30 | |
| 31 | 31 | use lsp::{LanguageServerId, NumberOrString}; |
| @@ -832,6 +832,7 @@ impl Buffer { · 800 unmodified lines | ||
| 832 | 832 | ReplicaId::LOCAL, |
| 833 | 833 | cx.entity_id().as_non_zero_u64().into(), |
| 834 | 834 | base_text.into(), |
| 835 | + &cx.background_executor(), | |
| 835 | 836 | ), |
| 836 | 837 | None, |
| 837 | 838 | Capability::ReadWrite, |
| @@ -862,9 +863,10 @@ impl Buffer { · 24 unmodified lines | ||
| 862 | 863 | replica_id: ReplicaId, |
| 863 | 864 | capability: Capability, |
| 864 | 865 | base_text: impl Into<String>, |
| 866 | + cx: &BackgroundExecutor, | |
| 865 | 867 | ) -> Self { |
| 866 | 868 | Self::build( |
| 867 | − TextBuffer::new(replica_id, remote_id, base_text.into()), | |
| 869 | + TextBuffer::new(replica_id, remote_id, base_text.into(), cx), | |
| 868 | 870 | None, |
| 869 | 871 | capability, |
| 870 | 872 | ) |
| @@ -877,9 +879,10 @@ impl Buffer { · 6 unmodified lines | ||
| 877 | 879 | capability: Capability, |
| 878 | 880 | message: proto::BufferState, |
| 879 | 881 | file: Option<Arc<dyn File>>, |
| 882 | + cx: &BackgroundExecutor, | |
| 880 | 883 | ) -> Result<Self> { |
| 881 | 884 | let buffer_id = BufferId::new(message.id).context("Could not deserialize buffer_id")?; |
| 882 | − let buffer = TextBuffer::new(replica_id, buffer_id, message.base_text); | |
| 885 | + let buffer = TextBuffer::new(replica_id, buffer_id, message.base_text, cx); | |
| 883 | 886 | let mut this = Self::build(buffer, file, capability); |
| 884 | 887 | this.text.set_line_ending(proto::deserialize_line_ending( |
| 885 | 888 | rpc::proto::LineEnding::from_i32(message.line_ending).context("missing line_ending")?, |
| @@ -1138,13 +1141,14 @@ impl Buffer { · 252 unmodified lines | ||
| 1138 | 1141 | let old_snapshot = self.text.snapshot(); |
| 1139 | 1142 | let mut branch_buffer = self.text.branch(); |
| 1140 | 1143 | let mut syntax_snapshot = self.syntax_map.lock().snapshot(); |
| 1144 | + let executor = cx.background_executor().clone(); | |
| 1141 | 1145 | cx.background_spawn(async move { |
| 1142 | 1146 | if !edits.is_empty() { |
| 1143 | 1147 | if let Some(language) = language.clone() { |
| 1144 | 1148 | syntax_snapshot.reparse(&old_snapshot, registry.clone(), language); |
| 1145 | 1149 | } |
| 1146 | 1150 | |
| 1147 | − branch_buffer.edit(edits.iter().cloned()); | |
| 1151 | + branch_buffer.edit(edits.iter().cloned(), &executor); | |
| 1148 | 1152 | let snapshot = branch_buffer.snapshot(); |
| 1149 | 1153 | syntax_snapshot.interpolate(&snapshot); |
| 1150 | 1154 | |
| @@ -2361,7 +2365,9 @@ impl Buffer { · 1210 unmodified lines | ||
| 2361 | 2365 | let autoindent_request = autoindent_mode |
| 2362 | 2366 | .and_then(|mode| self.language.as_ref().map(|_| (self.snapshot(), mode))); |
| 2363 | 2367 | |
| 2364 | − let edit_operation = self.text.edit(edits.iter().cloned()); | |
| 2368 | + let edit_operation = self | |
| 2369 | + .text | |
| 2370 | + .edit(edits.iter().cloned(), cx.background_executor()); | |
| 2365 | 2371 | let edit_id = edit_operation.timestamp(); |
| 2366 | 2372 | |
| 2367 | 2373 | if let Some((before_edit, mode)) = autoindent_request { |
| @@ -2592,7 +2598,8 @@ impl Buffer { · 224 unmodified lines | ||
| 2592 | 2598 | for operation in buffer_ops.iter() { |
| 2593 | 2599 | self.send_operation(Operation::Buffer(operation.clone()), false, cx); |
| 2594 | 2600 | } |
| 2595 | − self.text.apply_ops(buffer_ops); | |
| 2601 | + self.text | |
| 2602 | + .apply_ops(buffer_ops, Some(cx.background_executor())); | |
| 2596 | 2603 | self.deferred_ops.insert(deferred_ops); |
| 2597 | 2604 | self.flush_deferred_ops(cx); |
| 2598 | 2605 | self.did_edit(&old_version, was_dirty, cx); |
| @@ -75,6 +75,7 @@ fn test_set_line_ending(cx: &mut TestAppContext) { · 74 unmodified lines | ||
| 75 | 75 | Capability::ReadWrite, |
| 76 | 76 | base.read(cx).to_proto(cx), |
| 77 | 77 | None, |
| 78 | + cx.background_executor(), | |
| 78 | 79 | ) |
| 79 | 80 | .unwrap() |
| 80 | 81 | }); |
| @@ -255,14 +256,18 @@ async fn test_first_line_pattern(cx: &mut TestAppContext) { · 174 unmodified lines | ||
| 255 | 256 | .is_none() |
| 256 | 257 | ); |
| 257 | 258 | assert!( |
| 258 | − cx.read(|cx| languages.language_for_file(&file("the/script"), Some(&"nothing".into()), cx)) | |
| 259 | − .is_none() | |
| 259 | + cx.read(|cx| languages.language_for_file( | |
| 260 | + &file("the/script"), | |
| 261 | + Some(&Rope::from_str("nothing", cx.background_executor())), | |
| 262 | + cx | |
| 263 | + )) | |
| 264 | + .is_none() | |
| 260 | 265 | ); |
| 261 | 266 | |
| 262 | 267 | assert_eq!( |
| 263 | 268 | cx.read(|cx| languages.language_for_file( |
| 264 | 269 | &file("the/script"), |
| 265 | − Some(&"#!/bin/env node".into()), | |
| 270 | + Some(&Rope::from_str("#!/bin/env node", cx.background_executor())), | |
| 266 | 271 | cx |
| 267 | 272 | )) |
| 268 | 273 | .unwrap() |
| @@ -406,6 +411,7 @@ fn test_edit_events(cx: &mut gpui::App) { · 137 unmodified lines | ||
| 406 | 411 | ReplicaId::new(1), |
| 407 | 412 | Capability::ReadWrite, |
| 408 | 413 | "abcdef", |
| 414 | + cx.background_executor(), | |
| 409 | 415 | ) |
| 410 | 416 | }); |
| 411 | 417 | let buffer1_ops = Arc::new(Mutex::new(Vec::new())); |
| @@ -2781,8 +2787,14 @@ fn test_serialization(cx: &mut gpui::App) { · 2369 unmodified lines | ||
| 2781 | 2787 | .background_executor() |
| 2782 | 2788 | .block(buffer1.read(cx).serialize_ops(None, cx)); |
| 2783 | 2789 | let buffer2 = cx.new(|cx| { |
| 2784 | − let mut buffer = | |
| 2785 | − Buffer::from_proto(ReplicaId::new(1), Capability::ReadWrite, state, None).unwrap(); | |
| 2790 | + let mut buffer = Buffer::from_proto( | |
| 2791 | + ReplicaId::new(1), | |
| 2792 | + Capability::ReadWrite, | |
| 2793 | + state, | |
| 2794 | + None, | |
| 2795 | + cx.background_executor(), | |
| 2796 | + ) | |
| 2797 | + .unwrap(); | |
| 2786 | 2798 | buffer.apply_ops( |
| 2787 | 2799 | ops.into_iter() |
| 2788 | 2800 | .map(|op| proto::deserialize_operation(op).unwrap()), |
| @@ -2806,6 +2818,7 @@ fn test_branch_and_merge(cx: &mut TestAppContext) { · 17 unmodified lines | ||
| 2806 | 2818 | Capability::ReadWrite, |
| 2807 | 2819 | base.read(cx).to_proto(cx), |
| 2808 | 2820 | None, |
| 2821 | + cx.background_executor(), | |
| 2809 | 2822 | ) |
| 2810 | 2823 | .unwrap() |
| 2811 | 2824 | }); |
| @@ -3120,9 +3133,14 @@ fn test_random_collaboration(cx: &mut App, mut rng: StdRng) { · 308 unmodified lines | ||
| 3120 | 3133 | let ops = cx |
| 3121 | 3134 | .background_executor() |
| 3122 | 3135 | .block(base_buffer.read(cx).serialize_ops(None, cx)); |
| 3123 | − let mut buffer = | |
| 3124 | − Buffer::from_proto(ReplicaId::new(i as u16), Capability::ReadWrite, state, None) | |
| 3125 | − .unwrap(); | |
| 3136 | + let mut buffer = Buffer::from_proto( | |
| 3137 | + ReplicaId::new(i as u16), | |
| 3138 | + Capability::ReadWrite, | |
| 3139 | + state, | |
| 3140 | + None, | |
| 3141 | + cx.background_executor(), | |
| 3142 | + ) | |
| 3143 | + .unwrap(); | |
| 3126 | 3144 | buffer.apply_ops( |
| 3127 | 3145 | ops.into_iter() |
| 3128 | 3146 | .map(|op| proto::deserialize_operation(op).unwrap()), |
| @@ -3251,6 +3269,7 @@ fn test_random_collaboration(cx: &mut App, mut rng: StdRng) { · 122 unmodified lines | ||
| 3251 | 3269 | Capability::ReadWrite, |
| 3252 | 3270 | old_buffer_state, |
| 3253 | 3271 | None, |
| 3272 | + cx.background_executor(), | |
| 3254 | 3273 | ) |
| 3255 | 3274 | .unwrap(); |
| 3256 | 3275 | new_buffer.apply_ops( |
| @@ -3414,7 +3433,7 @@ fn test_contiguous_ranges() { · 157 unmodified lines | ||
| 3414 | 3433 | } |
| 3415 | 3434 | |
| 3416 | 3435 | #[gpui::test(iterations = 500)] |
| 3417 | −fn test_trailing_whitespace_ranges(mut rng: StdRng) { | |
| 3436 | +fn test_trailing_whitespace_ranges(mut rng: StdRng, cx: &mut TestAppContext) { | |
| 3418 | 3437 | // Generate a random multi-line string containing |
| 3419 | 3438 | // some lines with trailing whitespace. |
| 3420 | 3439 | let mut text = String::new(); |
| @@ -3438,7 +3457,7 @@ fn test_trailing_whitespace_ranges(mut rng: StdRng) { · 17 unmodified lines | ||
| 3438 | 3457 | _ => {} |
| 3439 | 3458 | } |
| 3440 | 3459 | |
| 3441 | − let rope = Rope::from(text.as_str()); | |
| 3460 | + let rope = Rope::from_str(text.as_str(), cx.background_executor()); | |
| 3442 | 3461 | let actual_ranges = trailing_whitespace_ranges(&rope); |
| 3443 | 3462 | let expected_ranges = TRAILING_WHITESPACE_REGEX |
| 3444 | 3463 | .find_iter(&text) |
| @@ -100,6 +100,7 @@ fn test_syntax_map_layers_for_range(cx: &mut App) { · 99 unmodified lines | ||
| 100 | 100 | } |
| 101 | 101 | "# |
| 102 | 102 | .unindent(), |
| 103 | + cx.background_executor(), | |
| 103 | 104 | ); |
| 104 | 105 | |
| 105 | 106 | let mut syntax_map = SyntaxMap::new(&buffer); |
| @@ -147,7 +148,7 @@ fn test_syntax_map_layers_for_range(cx: &mut App) { · 41 unmodified lines | ||
| 147 | 148 | |
| 148 | 149 | // Replace a vec! macro invocation with a plain slice, removing a syntactic layer. |
| 149 | 150 | let macro_name_range = range_for_text(&buffer, "vec!"); |
| 150 | − buffer.edit([(macro_name_range, "&")]); | |
| 151 | + buffer.edit([(macro_name_range, "&")], cx.background_executor()); | |
| 151 | 152 | syntax_map.interpolate(&buffer); |
| 152 | 153 | syntax_map.reparse(language.clone(), &buffer); |
| 153 | 154 | |
| @@ -199,6 +200,7 @@ fn test_dynamic_language_injection(cx: &mut App) { · 45 unmodified lines | ||
| 199 | 200 | ``` |
| 200 | 201 | "# |
| 201 | 202 | .unindent(), |
| 203 | + cx.background_executor(), | |
| 202 | 204 | ); |
| 203 | 205 | |
| 204 | 206 | let mut syntax_map = SyntaxMap::new(&buffer); |
| @@ -218,7 +220,10 @@ fn test_dynamic_language_injection(cx: &mut App) { · 13 unmodified lines | ||
| 218 | 220 | |
| 219 | 221 | // Replace `rs` with a path to ending in `.rb` in code block. |
| 220 | 222 | let macro_name_range = range_for_text(&buffer, "rs"); |
| 221 | − buffer.edit([(macro_name_range, "foo/bar/baz.rb")]); | |
| 223 | + buffer.edit( | |
| 224 | + [(macro_name_range, "foo/bar/baz.rb")], | |
| 225 | + cx.background_executor(), | |
| 226 | + ); | |
| 222 | 227 | syntax_map.interpolate(&buffer); |
| 223 | 228 | syntax_map.reparse(markdown.clone(), &buffer); |
| 224 | 229 | syntax_map.reparse(markdown_inline.clone(), &buffer); |
| @@ -235,7 +240,7 @@ fn test_dynamic_language_injection(cx: &mut App) { · 10 unmodified lines | ||
| 235 | 240 | |
| 236 | 241 | // Replace Ruby with a language that hasn't been loaded yet. |
| 237 | 242 | let macro_name_range = range_for_text(&buffer, "foo/bar/baz.rb"); |
| 238 | − buffer.edit([(macro_name_range, "html")]); | |
| 243 | + buffer.edit([(macro_name_range, "html")], cx.background_executor()); | |
| 239 | 244 | syntax_map.interpolate(&buffer); |
| 240 | 245 | syntax_map.reparse(markdown.clone(), &buffer); |
| 241 | 246 | syntax_map.reparse(markdown_inline.clone(), &buffer); |
| @@ -811,7 +816,12 @@ fn test_syntax_map_languages_loading_with_erb(cx: &mut App) { · 569 unmodified lines | ||
| 811 | 816 | .unindent(); |
| 812 | 817 | |
| 813 | 818 | let registry = Arc::new(LanguageRegistry::test(cx.background_executor().clone())); |
| 814 | − let mut buffer = Buffer::new(ReplicaId::LOCAL, BufferId::new(1).unwrap(), text); | |
| 819 | + let mut buffer = Buffer::new( | |
| 820 | + ReplicaId::LOCAL, | |
| 821 | + BufferId::new(1).unwrap(), | |
| 822 | + text, | |
| 823 | + cx.background_executor(), | |
| 824 | + ); | |
| 815 | 825 | |
| 816 | 826 | let mut syntax_map = SyntaxMap::new(&buffer); |
| 817 | 827 | syntax_map.set_language_registry(registry.clone()); |
| @@ -859,7 +869,7 @@ fn test_syntax_map_languages_loading_with_erb(cx: &mut App) { · 41 unmodified lines | ||
| 859 | 869 | .unindent(); |
| 860 | 870 | |
| 861 | 871 | log::info!("editing"); |
| 862 | − buffer.edit_via_marked_text(&text); | |
| 872 | + buffer.edit_via_marked_text(&text, cx.background_executor()); | |
| 863 | 873 | syntax_map.interpolate(&buffer); |
| 864 | 874 | syntax_map.reparse(language, &buffer); |
| 865 | 875 | |
| @@ -903,7 +913,7 @@ fn test_random_syntax_map_edits_rust_macros(rng: StdRng, cx: &mut App) { · 37 unmodified lines | ||
| 903 | 913 | let language = Arc::new(rust_lang()); |
| 904 | 914 | registry.add(language.clone()); |
| 905 | 915 | |
| 906 | − test_random_edits(text, registry, language, rng); | |
| 916 | + test_random_edits(text, registry, language, rng, cx); | |
| 907 | 917 | } |
| 908 | 918 | |
| 909 | 919 | #[gpui::test(iterations = 50)] |
| @@ -932,7 +942,7 @@ fn test_random_syntax_map_edits_with_erb(rng: StdRng, cx: &mut App) { · 22 unmodified lines | ||
| 932 | 942 | registry.add(Arc::new(ruby_lang())); |
| 933 | 943 | registry.add(Arc::new(html_lang())); |
| 934 | 944 | |
| 935 | − test_random_edits(text, registry, language, rng); | |
| 945 | + test_random_edits(text, registry, language, rng, cx); | |
| 936 | 946 | } |
| 937 | 947 | |
| 938 | 948 | #[gpui::test(iterations = 50)] |
| @@ -965,7 +975,7 @@ fn test_random_syntax_map_edits_with_heex(rng: StdRng, cx: &mut App) { · 26 unmodified lines | ||
| 965 | 975 | registry.add(Arc::new(heex_lang())); |
| 966 | 976 | registry.add(Arc::new(html_lang())); |
| 967 | 977 | |
| 968 | − test_random_edits(text, registry, language, rng); | |
| 978 | + test_random_edits(text, registry, language, rng, cx); | |
| 969 | 979 | } |
| 970 | 980 | |
| 971 | 981 | fn test_random_edits( |
| @@ -973,12 +983,18 @@ fn test_random_edits( · 1 unmodified line | ||
| 973 | 983 | registry: Arc<LanguageRegistry>, |
| 974 | 984 | language: Arc<Language>, |
| 975 | 985 | mut rng: StdRng, |
| 986 | + cx: &mut App, | |
| 976 | 987 | ) { |
| 977 | 988 | let operations = env::var("OPERATIONS") |
| 978 | 989 | .map(|i| i.parse().expect("invalid `OPERATIONS` variable")) |
| 979 | 990 | .unwrap_or(10); |
| 980 | 991 | |
| 981 | − let mut buffer = Buffer::new(ReplicaId::LOCAL, BufferId::new(1).unwrap(), text); | |
| 992 | + let mut buffer = Buffer::new( | |
| 993 | + ReplicaId::LOCAL, | |
| 994 | + BufferId::new(1).unwrap(), | |
| 995 | + text, | |
| 996 | + cx.background_executor(), | |
| 997 | + ); | |
| 982 | 998 | |
| 983 | 999 | let mut syntax_map = SyntaxMap::new(&buffer); |
| 984 | 1000 | syntax_map.set_language_registry(registry.clone()); |
| @@ -993,7 +1009,7 @@ fn test_random_edits( · 8 unmodified lines | ||
| 993 | 1009 | let prev_buffer = buffer.snapshot(); |
| 994 | 1010 | let prev_syntax_map = syntax_map.snapshot(); |
| 995 | 1011 | |
| 996 | − buffer.randomly_edit(&mut rng, 3); | |
| 1012 | + buffer.randomly_edit(&mut rng, 3, cx.background_executor()); | |
| 997 | 1013 | log::info!("text:\n{}", buffer.text()); |
| 998 | 1014 | |
| 999 | 1015 | syntax_map.interpolate(&buffer); |
| @@ -1159,7 +1175,12 @@ fn test_edit_sequence(language_name: &str, steps: &[&str], cx: &mut App) -> (Buf · 159 unmodified lines | ||
| 1159 | 1175 | .now_or_never() |
| 1160 | 1176 | .unwrap() |
| 1161 | 1177 | .unwrap(); |
| 1162 | − let mut buffer = Buffer::new(ReplicaId::LOCAL, BufferId::new(1).unwrap(), ""); | |
| 1178 | + let mut buffer = Buffer::new( | |
| 1179 | + ReplicaId::LOCAL, | |
| 1180 | + BufferId::new(1).unwrap(), | |
| 1181 | + "", | |
| 1182 | + cx.background_executor(), | |
| 1183 | + ); | |
| 1163 | 1184 | |
| 1164 | 1185 | let mut mutated_syntax_map = SyntaxMap::new(&buffer); |
| 1165 | 1186 | mutated_syntax_map.set_language_registry(registry.clone()); |
| @@ -1168,7 +1189,7 @@ fn test_edit_sequence(language_name: &str, steps: &[&str], cx: &mut App) -> (Buf · 2 unmodified lines | ||
| 1168 | 1189 | for (i, marked_string) in steps.iter().enumerate() { |
| 1169 | 1190 | let marked_string = marked_string.unindent(); |
| 1170 | 1191 | log::info!("incremental parse {i}: {marked_string:?}"); |
| 1171 | − buffer.edit_via_marked_text(&marked_string); | |
| 1192 | + buffer.edit_via_marked_text(&marked_string, cx.background_executor()); | |
| 1172 | 1193 | |
| 1173 | 1194 | // Reparse the syntax map |
| 1174 | 1195 | mutated_syntax_map.interpolate(&buffer); |
| @@ -11,7 +11,7 @@ use futures::{Future, FutureExt, future::join_all}; · 10 unmodified lines | ||
| 11 | 11 | use gpui::{App, AppContext, AsyncApp, Task}; |
| 12 | 12 | use language::{ |
| 13 | 13 | BinaryStatus, CodeLabel, DynLspInstaller, HighlightId, Language, LanguageName, LspAdapter, |
| 14 | − LspAdapterDelegate, Toolchain, | |
| 14 | + LspAdapterDelegate, Rope, Toolchain, | |
| 15 | 15 | }; |
| 16 | 16 | use lsp::{ |
| 17 | 17 | CodeActionKind, LanguageServerBinary, LanguageServerBinaryOptions, LanguageServerName, |
| @@ -403,7 +403,10 @@ fn labels_from_extension( · 385 unmodified lines | ||
| 403 | 403 | let runs = if label.code.is_empty() { |
| 404 | 404 | Vec::new() |
| 405 | 405 | } else { |
| 406 | − language.highlight_text(&label.code.as_str().into(), 0..label.code.len()) | |
| 406 | + language.highlight_text( | |
| 407 | + &Rope::from_str_small(label.code.as_str()), | |
| 408 | + 0..label.code.len(), | |
| 409 | + ) | |
| 407 | 410 | }; |
| 408 | 411 | build_code_label(&label, &runs, language) |
| 409 | 412 | }) |
| @@ -189,7 +189,7 @@ impl super::LspAdapter for CLspAdapter { · 188 unmodified lines | ||
| 189 | 189 | Some(lsp::CompletionItemKind::FIELD) if completion.detail.is_some() => { |
| 190 | 190 | let detail = completion.detail.as_ref().unwrap(); |
| 191 | 191 | let text = format!("{} {}", detail, label); |
| 192 | − let source = Rope::from(format!("struct S {{ {} }}", text).as_str()); | |
| 192 | + let source = Rope::from_str_small(format!("struct S {{ {} }}", text).as_str()); | |
| 193 | 193 | let runs = language.highlight_text(&source, 11..11 + text.len()); |
| 194 | 194 | let filter_range = completion |
| 195 | 195 | .filter_text |
| @@ -206,7 +206,8 @@ impl super::LspAdapter for CLspAdapter { · 10 unmodified lines | ||
| 206 | 206 | { |
| 207 | 207 | let detail = completion.detail.as_ref().unwrap(); |
| 208 | 208 | let text = format!("{} {}", detail, label); |
| 209 | − let runs = language.highlight_text(&Rope::from(text.as_str()), 0..text.len()); | |
| 209 | + let runs = | |
| 210 | + language.highlight_text(&Rope::from_str_small(text.as_str()), 0..text.len()); | |
| 210 | 211 | let filter_range = completion |
| 211 | 212 | .filter_text |
| 212 | 213 | .as_deref() |
| @@ -222,7 +223,8 @@ impl super::LspAdapter for CLspAdapter { · 9 unmodified lines | ||
| 222 | 223 | { |
| 223 | 224 | let detail = completion.detail.as_ref().unwrap(); |
| 224 | 225 | let text = format!("{} {}", detail, label); |
| 225 | − let runs = language.highlight_text(&Rope::from(text.as_str()), 0..text.len()); | |
| 226 | + let runs = | |
| 227 | + language.highlight_text(&Rope::from_str_small(text.as_str()), 0..text.len()); | |
| 226 | 228 | let filter_range = completion |
| 227 | 229 | .filter_text |
| 228 | 230 | .as_deref() |
| @@ -326,7 +328,7 @@ impl super::LspAdapter for CLspAdapter { · 97 unmodified lines | ||
| 326 | 328 | Some(CodeLabel::new( |
| 327 | 329 | text[display_range.clone()].to_string(), |
| 328 | 330 | filter_range, |
| 329 | − language.highlight_text(&text.as_str().into(), display_range), | |
| 331 | + language.highlight_text(&Rope::from_str_small(text.as_str()), display_range), | |
| 330 | 332 | )) |
| 331 | 333 | } |
| 332 | 334 | |
| @@ -221,7 +221,7 @@ impl LspAdapter for GoLspAdapter { · 220 unmodified lines | ||
| 221 | 221 | match completion.kind.zip(completion.detail.as_ref()) { |
| 222 | 222 | Some((lsp::CompletionItemKind::MODULE, detail)) => { |
| 223 | 223 | let text = format!("{label} {detail}"); |
| 224 | − let source = Rope::from(format!("import {text}").as_str()); | |
| 224 | + let source = Rope::from_str_small(format!("import {text}").as_str()); | |
| 225 | 225 | let runs = language.highlight_text(&source, 7..7 + text[name_offset..].len()); |
| 226 | 226 | let filter_range = completion |
| 227 | 227 | .filter_text |
| @@ -238,8 +238,9 @@ impl LspAdapter for GoLspAdapter { · 10 unmodified lines | ||
| 238 | 238 | detail, |
| 239 | 239 | )) => { |
| 240 | 240 | let text = format!("{label} {detail}"); |
| 241 | − let source = | |
| 242 | − Rope::from(format!("var {} {}", &text[name_offset..], detail).as_str()); | |
| 241 | + let source = Rope::from_str_small( | |
| 242 | + format!("var {} {}", &text[name_offset..], detail).as_str(), | |
| 243 | + ); | |
| 243 | 244 | let runs = adjust_runs( |
| 244 | 245 | name_offset, |
| 245 | 246 | language.highlight_text(&source, 4..4 + text[name_offset..].len()), |
| @@ -256,7 +257,8 @@ impl LspAdapter for GoLspAdapter { · 10 unmodified lines | ||
| 256 | 257 | } |
| 257 | 258 | Some((lsp::CompletionItemKind::STRUCT, _)) => { |
| 258 | 259 | let text = format!("{label} struct {{}}"); |
| 259 | − let source = Rope::from(format!("type {}", &text[name_offset..]).as_str()); | |
| 260 | + let source = | |
| 261 | + Rope::from_str_small(format!("type {}", &text[name_offset..]).as_str()); | |
| 260 | 262 | let runs = adjust_runs( |
| 261 | 263 | name_offset, |
| 262 | 264 | language.highlight_text(&source, 5..5 + text[name_offset..].len()), |
| @@ -273,7 +275,8 @@ impl LspAdapter for GoLspAdapter { · 10 unmodified lines | ||
| 273 | 275 | } |
| 274 | 276 | Some((lsp::CompletionItemKind::INTERFACE, _)) => { |
| 275 | 277 | let text = format!("{label} interface {{}}"); |
| 276 | − let source = Rope::from(format!("type {}", &text[name_offset..]).as_str()); | |
| 278 | + let source = | |
| 279 | + Rope::from_str_small(format!("type {}", &text[name_offset..]).as_str()); | |
| 277 | 280 | let runs = adjust_runs( |
| 278 | 281 | name_offset, |
| 279 | 282 | language.highlight_text(&source, 5..5 + text[name_offset..].len()), |
| @@ -290,8 +293,9 @@ impl LspAdapter for GoLspAdapter { · 10 unmodified lines | ||
| 290 | 293 | } |
| 291 | 294 | Some((lsp::CompletionItemKind::FIELD, detail)) => { |
| 292 | 295 | let text = format!("{label} {detail}"); |
| 293 | − let source = | |
| 294 | − Rope::from(format!("type T struct {{ {} }}", &text[name_offset..]).as_str()); | |
| 296 | + let source = Rope::from_str_small( | |
| 297 | + format!("type T struct {{ {} }}", &text[name_offset..]).as_str(), | |
| 298 | + ); | |
| 295 | 299 | let runs = adjust_runs( |
| 296 | 300 | name_offset, |
| 297 | 301 | language.highlight_text(&source, 16..16 + text[name_offset..].len()), |
| @@ -309,7 +313,9 @@ impl LspAdapter for GoLspAdapter { · 11 unmodified lines | ||
| 309 | 313 | Some((lsp::CompletionItemKind::FUNCTION | lsp::CompletionItemKind::METHOD, detail)) => { |
| 310 | 314 | if let Some(signature) = detail.strip_prefix("func") { |
| 311 | 315 | let text = format!("{label}{signature}"); |
| 312 | − let source = Rope::from(format!("func {} {{}}", &text[name_offset..]).as_str()); | |
| 316 | + let source = Rope::from_str_small( | |
| 317 | + format!("func {} {{}}", &text[name_offset..]).as_str(), | |
| 318 | + ); | |
| 313 | 319 | let runs = adjust_runs( |
| 314 | 320 | name_offset, |
| 315 | 321 | language.highlight_text(&source, 5..5 + text[name_offset..].len()), |
| @@ -385,7 +391,7 @@ impl LspAdapter for GoLspAdapter { · 69 unmodified lines | ||
| 385 | 391 | Some(CodeLabel::new( |
| 386 | 392 | text[display_range.clone()].to_string(), |
| 387 | 393 | filter_range, |
| 388 | − language.highlight_text(&text.as_str().into(), display_range), | |
| 394 | + language.highlight_text(&Rope::from_str_small(text.as_str()), display_range), | |
| 389 | 395 | )) |
| 390 | 396 | } |
| 391 | 397 | |
| @@ -19,6 +19,7 @@ use pet_core::python_environment::{PythonEnvironment, PythonEnvironmentKind}; · 18 unmodified lines | ||
| 19 | 19 | use pet_virtualenv::is_virtualenv_dir; |
| 20 | 20 | use project::Fs; |
| 21 | 21 | use project::lsp_store::language_server_settings; |
| 22 | +use rope::Rope; | |
| 22 | 23 | use serde::{Deserialize, Serialize}; |
| 23 | 24 | use serde_json::{Value, json}; |
| 24 | 25 | use smol::lock::OnceCell; |
| @@ -466,7 +467,7 @@ impl LspAdapter for PyrightLspAdapter { · 441 unmodified lines | ||
| 466 | 467 | Some(language::CodeLabel::new( |
| 467 | 468 | text[display_range.clone()].to_string(), |
| 468 | 469 | filter_range, |
| 469 | − language.highlight_text(&text.as_str().into(), display_range), | |
| 470 | + language.highlight_text(&Rope::from_str_small(text.as_str()), display_range), | |
| 470 | 471 | )) |
| 471 | 472 | } |
| 472 | 473 | |
| @@ -1511,7 +1512,7 @@ impl LspAdapter for PyLspAdapter { · 1038 unmodified lines | ||
| 1511 | 1512 | Some(language::CodeLabel::new( |
| 1512 | 1513 | text[display_range.clone()].to_string(), |
| 1513 | 1514 | filter_range, |
| 1514 | − language.highlight_text(&text.as_str().into(), display_range), | |
| 1515 | + language.highlight_text(&Rope::from_str_small(text.as_str()), display_range), | |
| 1515 | 1516 | )) |
| 1516 | 1517 | } |
| 1517 | 1518 | |
| @@ -1800,7 +1801,7 @@ impl LspAdapter for BasedPyrightLspAdapter { · 282 unmodified lines | ||
| 1800 | 1801 | Some(language::CodeLabel::new( |
| 1801 | 1802 | text[display_range.clone()].to_string(), |
| 1802 | 1803 | filter_range, |
| 1803 | − language.highlight_text(&text.as_str().into(), display_range), | |
| 1804 | + language.highlight_text(&Rope::from_str_small(text.as_str()), display_range), | |
| 1804 | 1805 | )) |
| 1805 | 1806 | } |
| 1806 | 1807 | |
| @@ -252,7 +252,7 @@ impl LspAdapter for RustLspAdapter { · 251 unmodified lines | ||
| 252 | 252 | let name = &completion.label; |
| 253 | 253 | let text = format!("{name}: {signature}"); |
| 254 | 254 | let prefix = "struct S { "; |
| 255 | − let source = Rope::from_iter([prefix, &text, " }"]); | |
| 255 | + let source = Rope::from_iter_small([prefix, &text, " }"]); | |
| 256 | 256 | let runs = |
| 257 | 257 | language.highlight_text(&source, prefix.len()..prefix.len() + text.len()); |
| 258 | 258 | mk_label(text, &|| 0..completion.label.len(), runs) |
| @@ -264,7 +264,7 @@ impl LspAdapter for RustLspAdapter { · 5 unmodified lines | ||
| 264 | 264 | let name = &completion.label; |
| 265 | 265 | let text = format!("{name}: {signature}",); |
| 266 | 266 | let prefix = "let "; |
| 267 | − let source = Rope::from_iter([prefix, &text, " = ();"]); | |
| 267 | + let source = Rope::from_iter_small([prefix, &text, " = ();"]); | |
| 268 | 268 | let runs = |
| 269 | 269 | language.highlight_text(&source, prefix.len()..prefix.len() + text.len()); |
| 270 | 270 | mk_label(text, &|| 0..completion.label.len(), runs) |
| @@ -302,7 +302,7 @@ impl LspAdapter for RustLspAdapter { · 31 unmodified lines | ||
| 302 | 302 | .filter(|it| it.contains(&label)) |
| 303 | 303 | .and_then(|it| Some((it, FULL_SIGNATURE_REGEX.find(it)?))) |
| 304 | 304 | { |
| 305 | − let source = Rope::from(function_signature); | |
| 305 | + let source = Rope::from_str_small(function_signature); | |
| 306 | 306 | let runs = language.highlight_text(&source, 0..function_signature.len()); |
| 307 | 307 | mk_label( |
| 308 | 308 | function_signature.to_owned(), |
| @@ -311,7 +311,7 @@ impl LspAdapter for RustLspAdapter { · 2 unmodified lines | ||
| 311 | 311 | ) |
| 312 | 312 | } else if let Some((prefix, suffix)) = fn_prefixed { |
| 313 | 313 | let text = format!("{label}{suffix}"); |
| 314 | − let source = Rope::from_iter([prefix, " ", &text, " {}"]); | |
| 314 | + let source = Rope::from_iter_small([prefix, " ", &text, " {}"]); | |
| 315 | 315 | let run_start = prefix.len() + 1; |
| 316 | 316 | let runs = language.highlight_text(&source, run_start..run_start + text.len()); |
| 317 | 317 | mk_label(text, &|| 0..label.len(), runs) |
| @@ -322,7 +322,7 @@ impl LspAdapter for RustLspAdapter { · 4 unmodified lines | ||
| 322 | 322 | { |
| 323 | 323 | let text = completion.label.clone(); |
| 324 | 324 | let len = text.len(); |
| 325 | − let source = Rope::from(text.as_str()); | |
| 325 | + let source = Rope::from_str_small(text.as_str()); | |
| 326 | 326 | let runs = language.highlight_text(&source, 0..len); |
| 327 | 327 | mk_label(text, &|| 0..completion.label.len(), runs) |
| 328 | 328 | } else if detail_left.is_none() { |
| @@ -399,7 +399,10 @@ impl LspAdapter for RustLspAdapter { · 70 unmodified lines | ||
| 399 | 399 | Some(CodeLabel::new( |
| 400 | 400 | format!("{prefix}{name}"), |
| 401 | 401 | filter_range, |
| 402 | − language.highlight_text(&Rope::from_iter([prefix, name, suffix]), display_range), | |
| 402 | + language.highlight_text( | |
| 403 | + &Rope::from_iter_small([prefix, name, suffix]), | |
| 404 | + display_range, | |
| 405 | + ), | |
| 403 | 406 | )) |
| 404 | 407 | } |
| 405 | 408 | |
| @@ -1558,7 +1558,9 @@ impl MarkdownElementBuilder { · 1557 unmodified lines | ||
| 1558 | 1558 | |
| 1559 | 1559 | if let Some(Some(language)) = self.code_block_stack.last() { |
| 1560 | 1560 | let mut offset = 0; |
| 1561 | − for (range, highlight_id) in language.highlight_text(&Rope::from(text), 0..text.len()) { | |
| 1561 | + for (range, highlight_id) in | |
| 1562 | + language.highlight_text(&Rope::from_str_small(text), 0..text.len()) | |
| 1563 | + { | |
| 1562 | 1564 | if range.start > offset { |
| 1563 | 1565 | self.pending_line |
| 1564 | 1566 | .runs |
| @@ -779,7 +779,7 @@ impl<'a> MarkdownParser<'a> { · 778 unmodified lines | ||
| 779 | 779 | |
| 780 | 780 | let highlights = if let Some(language) = &language { |
| 781 | 781 | if let Some(registry) = &self.language_registry { |
| 782 | − let rope: language::Rope = code.as_str().into(); | |
| 782 | + let rope = language::Rope::from_str_small(code.as_str()); | |
| 783 | 783 | registry |
| 784 | 784 | .language_for_name_or_extension(language) |
| 785 | 785 | .await |
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | use super::*; |
| 2 | 2 | use buffer_diff::{DiffHunkStatus, DiffHunkStatusKind}; |
| 3 | −use gpui::{App, TestAppContext}; | |
| 3 | +use gpui::{App, BackgroundExecutor, TestAppContext}; | |
| 4 | 4 | use indoc::indoc; |
| 5 | 5 | use language::{Buffer, Rope}; |
| 6 | 6 | use parking_lot::RwLock; |
| @@ -79,9 +79,14 @@ fn test_remote(cx: &mut App) { · 72 unmodified lines | ||
| 79 | 79 | let ops = cx |
| 80 | 80 | .background_executor() |
| 81 | 81 | .block(host_buffer.read(cx).serialize_ops(None, cx)); |
| 82 | − let mut buffer = | |
| 83 | − Buffer::from_proto(ReplicaId::REMOTE_SERVER, Capability::ReadWrite, state, None) | |
| 84 | − .unwrap(); | |
| 82 | + let mut buffer = Buffer::from_proto( | |
| 83 | + ReplicaId::REMOTE_SERVER, | |
| 84 | + Capability::ReadWrite, | |
| 85 | + state, | |
| 86 | + None, | |
| 87 | + cx.background_executor(), | |
| 88 | + ) | |
| 89 | + .unwrap(); | |
| 85 | 90 | buffer.apply_ops( |
| 86 | 91 | ops.into_iter() |
| 87 | 92 | .map(|op| language::proto::deserialize_operation(op).unwrap()), |
| @@ -1224,7 +1229,7 @@ fn test_basic_diff_hunks(cx: &mut TestAppContext) { · 1136 unmodified lines | ||
| 1224 | 1229 | assert_chunks_in_ranges(&snapshot); |
| 1225 | 1230 | assert_consistent_line_numbers(&snapshot); |
| 1226 | 1231 | assert_position_translation(&snapshot); |
| 1227 | − assert_line_indents(&snapshot); | |
| 1232 | + assert_line_indents(&snapshot, cx.background_executor()); | |
| 1228 | 1233 | |
| 1229 | 1234 | multibuffer.update(cx, |multibuffer, cx| { |
| 1230 | 1235 | multibuffer.collapse_diff_hunks(vec![Anchor::min()..Anchor::max()], cx) |
| @@ -1248,7 +1253,7 @@ fn test_basic_diff_hunks(cx: &mut TestAppContext) { · 17 unmodified lines | ||
| 1248 | 1253 | assert_chunks_in_ranges(&snapshot); |
| 1249 | 1254 | assert_consistent_line_numbers(&snapshot); |
| 1250 | 1255 | assert_position_translation(&snapshot); |
| 1251 | − assert_line_indents(&snapshot); | |
| 1256 | + assert_line_indents(&snapshot, cx.background_executor()); | |
| 1252 | 1257 | |
| 1253 | 1258 | // Expand the first diff hunk |
| 1254 | 1259 | multibuffer.update(cx, |multibuffer, cx| { |
| @@ -1300,7 +1305,7 @@ fn test_basic_diff_hunks(cx: &mut TestAppContext) { · 45 unmodified lines | ||
| 1300 | 1305 | assert_chunks_in_ranges(&snapshot); |
| 1301 | 1306 | assert_consistent_line_numbers(&snapshot); |
| 1302 | 1307 | assert_position_translation(&snapshot); |
| 1303 | − assert_line_indents(&snapshot); | |
| 1308 | + assert_line_indents(&snapshot, cx.background_executor()); | |
| 1304 | 1309 | |
| 1305 | 1310 | // Edit the buffer before the first hunk |
| 1306 | 1311 | buffer.update(cx, |buffer, cx| { |
| @@ -1342,7 +1347,7 @@ fn test_basic_diff_hunks(cx: &mut TestAppContext) { · 35 unmodified lines | ||
| 1342 | 1347 | assert_chunks_in_ranges(&snapshot); |
| 1343 | 1348 | assert_consistent_line_numbers(&snapshot); |
| 1344 | 1349 | assert_position_translation(&snapshot); |
| 1345 | − assert_line_indents(&snapshot); | |
| 1350 | + assert_line_indents(&snapshot, cx.background_executor()); | |
| 1346 | 1351 | |
| 1347 | 1352 | // Recalculate the diff, changing the first diff hunk. |
| 1348 | 1353 | diff.update(cx, |diff, cx| { |
| @@ -2067,7 +2072,7 @@ fn test_diff_hunks_with_multiple_excerpts(cx: &mut TestAppContext) { · 718 unmodified lines | ||
| 2067 | 2072 | } |
| 2068 | 2073 | |
| 2069 | 2074 | assert_position_translation(&snapshot); |
| 2070 | − assert_line_indents(&snapshot); | |
| 2075 | + assert_line_indents(&snapshot, cx.background_executor()); | |
| 2071 | 2076 | |
| 2072 | 2077 | assert_eq!( |
| 2073 | 2078 | snapshot |
| @@ -2118,7 +2123,7 @@ fn test_diff_hunks_with_multiple_excerpts(cx: &mut TestAppContext) { · 44 unmodified lines | ||
| 2118 | 2123 | ), |
| 2119 | 2124 | ); |
| 2120 | 2125 | |
| 2121 | − assert_line_indents(&snapshot); | |
| 2126 | + assert_line_indents(&snapshot, cx.background_executor()); | |
| 2122 | 2127 | } |
| 2123 | 2128 | |
| 2124 | 2129 | /// A naive implementation of a multi-buffer that does not maintain |
| @@ -2888,7 +2893,7 @@ async fn test_random_multibuffer(cx: &mut TestAppContext, mut rng: StdRng) { · 763 unmodified lines | ||
| 2888 | 2893 | ); |
| 2889 | 2894 | } |
| 2890 | 2895 | |
| 2891 | − let text_rope = Rope::from(expected_text.as_str()); | |
| 2896 | + let text_rope = Rope::from_str(expected_text.as_str(), cx.background_executor()); | |
| 2892 | 2897 | for _ in 0..10 { |
| 2893 | 2898 | let end_ix = text_rope.clip_offset(rng.random_range(0..=text_rope.len()), Bias::Right); |
| 2894 | 2899 | let start_ix = text_rope.clip_offset(rng.random_range(0..=end_ix), Bias::Left); |
| @@ -3512,7 +3517,7 @@ fn assert_consistent_line_numbers(snapshot: &MultiBufferSnapshot) { · 617 unmodified lines | ||
| 3512 | 3517 | |
| 3513 | 3518 | #[track_caller] |
| 3514 | 3519 | fn assert_position_translation(snapshot: &MultiBufferSnapshot) { |
| 3515 | − let text = Rope::from(snapshot.text()); | |
| 3520 | + let text = Rope::from_str_small(&snapshot.text()); | |
| 3516 | 3521 | |
| 3517 | 3522 | let mut left_anchors = Vec::new(); |
| 3518 | 3523 | let mut right_anchors = Vec::new(); |
| @@ -3636,10 +3641,10 @@ fn assert_position_translation(snapshot: &MultiBufferSnapshot) { · 117 unmodified lines | ||
| 3636 | 3641 | } |
| 3637 | 3642 | } |
| 3638 | 3643 | |
| 3639 | −fn assert_line_indents(snapshot: &MultiBufferSnapshot) { | |
| 3644 | +fn assert_line_indents(snapshot: &MultiBufferSnapshot, executor: &BackgroundExecutor) { | |
| 3640 | 3645 | let max_row = snapshot.max_point().row; |
| 3641 | 3646 | let buffer_id = snapshot.excerpts().next().unwrap().1.remote_id(); |
| 3642 | − let text = text::Buffer::new(ReplicaId::LOCAL, buffer_id, snapshot.text()); | |
| 3647 | + let text = text::Buffer::new(ReplicaId::LOCAL, buffer_id, snapshot.text(), executor); | |
| 3643 | 3648 | let mut line_indents = text |
| 3644 | 3649 | .line_indents_in_row_range(0..max_row + 1) |
| 3645 | 3650 | .collect::<Vec<_>>(); |
| @@ -180,7 +180,13 @@ impl RemoteBufferStore { · 179 unmodified lines | ||
| 180 | 180 | buffer_file = Some(Arc::new(File::from_proto(file, worktree, cx)?) |
| 181 | 181 | as Arc<dyn language::File>); |
| 182 | 182 | } |
| 183 | − Buffer::from_proto(replica_id, capability, state, buffer_file) | |
| 183 | + Buffer::from_proto( | |
| 184 | + replica_id, | |
| 185 | + capability, | |
| 186 | + state, | |
| 187 | + buffer_file, | |
| 188 | + cx.background_executor(), | |
| 189 | + ) | |
| 184 | 190 | }); |
| 185 | 191 | |
| 186 | 192 | match buffer_result { |
| @@ -628,9 +634,10 @@ impl LocalBufferStore { · 441 unmodified lines | ||
| 628 | 634 | Ok(loaded) => { |
| 629 | 635 | let reservation = cx.reserve_entity::<Buffer>()?; |
| 630 | 636 | let buffer_id = BufferId::from(reservation.entity_id().as_non_zero_u64()); |
| 637 | + let executor = cx.background_executor().clone(); | |
| 631 | 638 | let text_buffer = cx |
| 632 | 639 | .background_spawn(async move { |
| 633 | − text::Buffer::new(ReplicaId::LOCAL, buffer_id, loaded.text) | |
| 640 | + text::Buffer::new(ReplicaId::LOCAL, buffer_id, loaded.text, &executor) | |
| 634 | 641 | }) |
| 635 | 642 | .await; |
| 636 | 643 | cx.insert_entity(reservation, |_| { |
| @@ -639,7 +646,12 @@ impl LocalBufferStore { · 2 unmodified lines | ||
| 639 | 646 | } |
| 640 | 647 | Err(error) if is_not_found_error(&error) => cx.new(|cx| { |
| 641 | 648 | let buffer_id = BufferId::from(cx.entity_id().as_non_zero_u64()); |
| 642 | − let text_buffer = text::Buffer::new(ReplicaId::LOCAL, buffer_id, ""); | |
| 649 | + let text_buffer = text::Buffer::new( | |
| 650 | + ReplicaId::LOCAL, | |
| 651 | + buffer_id, | |
| 652 | + "", | |
| 653 | + cx.background_executor(), | |
| 654 | + ); | |
| 643 | 655 | Buffer::build( |
| 644 | 656 | text_buffer, |
| 645 | 657 | Some(Arc::new(File { |
| @@ -276,8 +276,8 @@ mod tests { · 275 unmodified lines | ||
| 276 | 276 | use util::{path, rel_path::rel_path}; |
| 277 | 277 | use worktree::WorktreeSettings; |
| 278 | 278 | |
| 279 | − #[test] | |
| 280 | − fn test_parse_conflicts_in_buffer() { | |
| 279 | + #[gpui::test] | |
| 280 | + fn test_parse_conflicts_in_buffer(cx: &mut TestAppContext) { | |
| 281 | 281 | // Create a buffer with conflict markers |
| 282 | 282 | let test_content = r#" |
| 283 | 283 | This is some text before the conflict. |
| @@ -299,7 +299,12 @@ mod tests { · 15 unmodified lines | ||
| 299 | 299 | .unindent(); |
| 300 | 300 | |
| 301 | 301 | let buffer_id = BufferId::new(1).unwrap(); |
| 302 | − let buffer = Buffer::new(ReplicaId::LOCAL, buffer_id, test_content); | |
| 302 | + let buffer = Buffer::new( | |
| 303 | + ReplicaId::LOCAL, | |
| 304 | + buffer_id, | |
| 305 | + test_content, | |
| 306 | + cx.background_executor(), | |
| 307 | + ); | |
| 303 | 308 | let snapshot = buffer.snapshot(); |
| 304 | 309 | |
| 305 | 310 | let conflict_snapshot = ConflictSet::parse(&snapshot); |
| @@ -355,8 +360,8 @@ mod tests { · 49 unmodified lines | ||
| 355 | 360 | assert_eq!(conflicts_in_range.len(), 0); |
| 356 | 361 | } |
| 357 | 362 | |
| 358 | − #[test] | |
| 359 | − fn test_nested_conflict_markers() { | |
| 363 | + #[gpui::test] | |
| 364 | + fn test_nested_conflict_markers(cx: &mut TestAppContext) { | |
| 360 | 365 | // Create a buffer with nested conflict markers |
| 361 | 366 | let test_content = r#" |
| 362 | 367 | This is some text before the conflict. |
| @@ -374,7 +379,12 @@ mod tests { · 11 unmodified lines | ||
| 374 | 379 | .unindent(); |
| 375 | 380 | |
| 376 | 381 | let buffer_id = BufferId::new(1).unwrap(); |
| 377 | − let buffer = Buffer::new(ReplicaId::LOCAL, buffer_id, test_content); | |
| 382 | + let buffer = Buffer::new( | |
| 383 | + ReplicaId::LOCAL, | |
| 384 | + buffer_id, | |
| 385 | + test_content, | |
| 386 | + cx.background_executor(), | |
| 387 | + ); | |
| 378 | 388 | let snapshot = buffer.snapshot(); |
| 379 | 389 | |
| 380 | 390 | let conflict_snapshot = ConflictSet::parse(&snapshot); |
| @@ -396,8 +406,8 @@ mod tests { · 15 unmodified lines | ||
| 396 | 406 | assert_eq!(their_text, "This is their version in a nested conflict\n"); |
| 397 | 407 | } |
| 398 | 408 | |
| 399 | − #[test] | |
| 400 | − fn test_conflict_markers_at_eof() { | |
| 409 | + #[gpui::test] | |
| 410 | + fn test_conflict_markers_at_eof(cx: &mut TestAppContext) { | |
| 401 | 411 | let test_content = r#" |
| 402 | 412 | <<<<<<< ours |
| 403 | 413 | ======= |
| @@ -405,15 +415,20 @@ mod tests { · 1 unmodified line | ||
| 405 | 415 | >>>>>>> "# |
| 406 | 416 | .unindent(); |
| 407 | 417 | let buffer_id = BufferId::new(1).unwrap(); |
| 408 | − let buffer = Buffer::new(ReplicaId::LOCAL, buffer_id, test_content); | |
| 418 | + let buffer = Buffer::new( | |
| 419 | + ReplicaId::LOCAL, | |
| 420 | + buffer_id, | |
| 421 | + test_content, | |
| 422 | + cx.background_executor(), | |
| 423 | + ); | |
| 409 | 424 | let snapshot = buffer.snapshot(); |
| 410 | 425 | |
| 411 | 426 | let conflict_snapshot = ConflictSet::parse(&snapshot); |
| 412 | 427 | assert_eq!(conflict_snapshot.conflicts.len(), 1); |
| 413 | 428 | } |
| 414 | 429 | |
| 415 | − #[test] | |
| 416 | − fn test_conflicts_in_range() { | |
| 430 | + #[gpui::test] | |
| 431 | + fn test_conflicts_in_range(cx: &mut TestAppContext) { | |
| 417 | 432 | // Create a buffer with conflict markers |
| 418 | 433 | let test_content = r#" |
| 419 | 434 | one |
| @@ -447,7 +462,12 @@ mod tests { · 27 unmodified lines | ||
| 447 | 462 | .unindent(); |
| 448 | 463 | |
| 449 | 464 | let buffer_id = BufferId::new(1).unwrap(); |
| 450 | − let buffer = Buffer::new(ReplicaId::LOCAL, buffer_id, test_content.clone()); | |
| 465 | + let buffer = Buffer::new( | |
| 466 | + ReplicaId::LOCAL, | |
| 467 | + buffer_id, | |
| 468 | + test_content.clone(), | |
| 469 | + cx.background_executor(), | |
| 470 | + ); | |
| 451 | 471 | let snapshot = buffer.snapshot(); |
| 452 | 472 | |
| 453 | 473 | let conflict_snapshot = ConflictSet::parse(&snapshot); |
| @@ -13,7 +13,9 @@ use futures::{ · 12 unmodified lines | ||
| 13 | 13 | future::{self, Shared}, |
| 14 | 14 | stream::FuturesUnordered, |
| 15 | 15 | }; |
| 16 | −use gpui::{AppContext as _, AsyncApp, Context, Entity, EventEmitter, Task, WeakEntity}; | |
| 16 | +use gpui::{ | |
| 17 | + AppContext as _, AsyncApp, BackgroundExecutor, Context, Entity, EventEmitter, Task, WeakEntity, | |
| 18 | +}; | |
| 17 | 19 | use language::{ |
| 18 | 20 | Buffer, LanguageRegistry, LocalFile, |
| 19 | 21 | language_settings::{Formatter, LanguageSettings}, |
| @@ -558,99 +560,137 @@ impl PrettierStore { · 538 unmodified lines | ||
| 558 | 560 | let plugins_to_install = new_plugins.clone(); |
| 559 | 561 | let fs = Arc::clone(&self.fs); |
| 560 | 562 | let new_installation_task = cx |
| 561 | − .spawn(async move |prettier_store, cx| { | |
| 562 | − cx.background_executor().timer(Duration::from_millis(30)).await; | |
| 563 | + .spawn(async move |prettier_store, cx| { | |
| 564 | + cx.background_executor() | |
| 565 | + .timer(Duration::from_millis(30)) | |
| 566 | + .await; | |
| 563 | 567 | let location_data = prettier_store.update(cx, |prettier_store, cx| { |
| 564 | − worktree.and_then(|worktree_id| { | |
| 565 | − prettier_store.worktree_store | |
| 566 | − .read(cx) | |
| 567 | − .worktree_for_id(worktree_id, cx) | |
| 568 | − .map(|worktree| worktree.read(cx).abs_path()) | |
| 569 | − }).map(|locate_from| { | |
| 570 | − let installed_prettiers = prettier_store.prettier_instances.keys().cloned().collect(); | |
| 571 | − (locate_from, installed_prettiers) | |
| 572 | − }) | |
| 568 | + worktree | |
| 569 | + .and_then(|worktree_id| { | |
| 570 | + prettier_store | |
| 571 | + .worktree_store | |
| 572 | + .read(cx) | |
| 573 | + .worktree_for_id(worktree_id, cx) | |
| 574 | + .map(|worktree| worktree.read(cx).abs_path()) | |
| 575 | + }) | |
| 576 | + .map(|locate_from| { | |
| 577 | + let installed_prettiers = | |
| 578 | + prettier_store.prettier_instances.keys().cloned().collect(); | |
| 579 | + (locate_from, installed_prettiers) | |
| 580 | + }) | |
| 573 | 581 | })?; |
| 574 | 582 | let locate_prettier_installation = match location_data { |
| 575 | − Some((locate_from, installed_prettiers)) => Prettier::locate_prettier_installation( | |
| 576 | − fs.as_ref(), | |
| 577 | − &installed_prettiers, | |
| 578 | − locate_from.as_ref(), | |
| 579 | − ) | |
| 580 | − .await | |
| 581 | − .context("locate prettier installation").map_err(Arc::new)?, | |
| 583 | + Some((locate_from, installed_prettiers)) => { | |
| 584 | + Prettier::locate_prettier_installation( | |
| 585 | + fs.as_ref(), | |
| 586 | + &installed_prettiers, | |
| 587 | + locate_from.as_ref(), | |
| 588 | + ) | |
| 589 | + .await | |
| 590 | + .context("locate prettier installation") | |
| 591 | + .map_err(Arc::new)? | |
| 592 | + } | |
| 582 | 593 | None => ControlFlow::Continue(None), |
| 583 | 594 | }; |
| 584 | 595 | |
| 585 | − match locate_prettier_installation | |
| 586 | − { | |
| 596 | + match locate_prettier_installation { | |
| 587 | 597 | ControlFlow::Break(()) => return Ok(()), |
| 588 | 598 | ControlFlow::Continue(prettier_path) => { |
| 589 | 599 | if prettier_path.is_some() { |
| 590 | 600 | new_plugins.clear(); |
| 591 | 601 | } |
| 592 | − let mut needs_install = should_write_prettier_server_file(fs.as_ref()).await; | |
| 602 | + let mut needs_install = | |
| 603 | + should_write_prettier_server_file(fs.as_ref()).await; | |
| 593 | 604 | if let Some(previous_installation_task) = previous_installation_task |
| 594 | − && let Err(e) = previous_installation_task.await { | |
| 595 | − log::error!("Failed to install default prettier: {e:#}"); | |
| 596 | − prettier_store.update(cx, |prettier_store, _| { | |
| 597 | − if let PrettierInstallation::NotInstalled { attempts, not_installed_plugins, .. } = &mut prettier_store.default_prettier.prettier { | |
| 598 | − *attempts += 1; | |
| 599 | − new_plugins.extend(not_installed_plugins.iter().cloned()); | |
| 600 | − installation_attempt = *attempts; | |
| 601 | − needs_install = true; | |
| 602 | − }; | |
| 603 | − })?; | |
| 604 | − }; | |
| 605 | + && let Err(e) = previous_installation_task.await | |
| 606 | + { | |
| 607 | + log::error!("Failed to install default prettier: {e:#}"); | |
| 608 | + prettier_store.update(cx, |prettier_store, _| { | |
| 609 | + if let PrettierInstallation::NotInstalled { | |
| 610 | + attempts, | |
| 611 | + not_installed_plugins, | |
| 612 | + .. | |
| 613 | + } = &mut prettier_store.default_prettier.prettier | |
| 614 | + { | |
| 615 | + *attempts += 1; | |
| 616 | + new_plugins.extend(not_installed_plugins.iter().cloned()); | |
| 617 | + installation_attempt = *attempts; | |
| 618 | + needs_install = true; | |
| 619 | + }; | |
| 620 | + })?; | |
| 621 | + }; | |
| 605 | 622 | if installation_attempt > prettier::FAIL_THRESHOLD { |
| 606 | 623 | prettier_store.update(cx, |prettier_store, _| { |
| 607 | − if let PrettierInstallation::NotInstalled { installation_task, .. } = &mut prettier_store.default_prettier.prettier { | |
| 624 | + if let PrettierInstallation::NotInstalled { | |
| 625 | + installation_task, | |
| 626 | + .. | |
| 627 | + } = &mut prettier_store.default_prettier.prettier | |
| 628 | + { | |
| 608 | 629 | *installation_task = None; |
| 609 | 630 | }; |
| 610 | 631 | })?; |
| 611 | 632 | log::warn!( |
| 612 | − "Default prettier installation had failed {installation_attempt} times, not attempting again", | |
| 633 | + "Default prettier installation had failed {installation_attempt} \ | |
| 634 | + times, not attempting again", | |
| 613 | 635 | ); |
| 614 | 636 | return Ok(()); |
| 615 | 637 | } |
| 616 | 638 | prettier_store.update(cx, |prettier_store, _| { |
| 617 | 639 | new_plugins.retain(|plugin| { |
| 618 | − !prettier_store.default_prettier.installed_plugins.contains(plugin) | |
| 640 | + !prettier_store | |
| 641 | + .default_prettier | |
| 642 | + .installed_plugins | |
| 643 | + .contains(plugin) | |
| 619 | 644 | }); |
| 620 | − if let PrettierInstallation::NotInstalled { not_installed_plugins, .. } = &mut prettier_store.default_prettier.prettier { | |
| 645 | + if let PrettierInstallation::NotInstalled { | |
| 646 | + not_installed_plugins, | |
| 647 | + .. | |
| 648 | + } = &mut prettier_store.default_prettier.prettier | |
| 649 | + { | |
| 621 | 650 | not_installed_plugins.retain(|plugin| { |
| 622 | − !prettier_store.default_prettier.installed_plugins.contains(plugin) | |
| 651 | + !prettier_store | |
| 652 | + .default_prettier | |
| 653 | + .installed_plugins | |
| 654 | + .contains(plugin) | |
| 623 | 655 | }); |
| 624 | 656 | not_installed_plugins.extend(new_plugins.iter().cloned()); |
| 625 | 657 | } |
| 626 | 658 | needs_install |= !new_plugins.is_empty(); |
| 627 | 659 | })?; |
| 628 | 660 | if needs_install { |
| 629 | − log::info!("Initializing default prettier with plugins {new_plugins:?}"); | |
| 661 | + log::info!( | |
| 662 | + "Initializing default prettier with plugins {new_plugins:?}" | |
| 663 | + ); | |
| 630 | 664 | let installed_plugins = new_plugins.clone(); |
| 665 | + let executor = cx.background_executor().clone(); | |
| 631 | 666 | cx.background_spawn(async move { |
| 632 | 667 | install_prettier_packages(fs.as_ref(), new_plugins, node).await?; |
| 633 | 668 | // Save the server file last, so the reinstall need could be determined by the absence of the file. |
| 634 | − save_prettier_server_file(fs.as_ref()).await?; | |
| 669 | + save_prettier_server_file(fs.as_ref(), &executor).await?; | |
| 635 | 670 | anyhow::Ok(()) |
| 636 | 671 | }) |
| 637 | − .await | |
| 638 | − .context("prettier & plugins install") | |
| 639 | − .map_err(Arc::new)?; | |
| 640 | − log::info!("Initialized default prettier with plugins: {installed_plugins:?}"); | |
| 672 | + .await | |
| 673 | + .context("prettier & plugins install") | |
| 674 | + .map_err(Arc::new)?; | |
| 675 | + log::info!( | |
| 676 | + "Initialized default prettier with plugins: {installed_plugins:?}" | |
| 677 | + ); | |
| 641 | 678 | prettier_store.update(cx, |prettier_store, _| { |
| 642 | 679 | prettier_store.default_prettier.prettier = |
| 643 | 680 | PrettierInstallation::Installed(PrettierInstance { |
| 644 | 681 | attempt: 0, |
| 645 | 682 | prettier: None, |
| 646 | 683 | }); |
| 647 | − prettier_store.default_prettier | |
| 684 | + prettier_store | |
| 685 | + .default_prettier | |
| 648 | 686 | .installed_plugins |
| 649 | 687 | .extend(installed_plugins); |
| 650 | 688 | })?; |
| 651 | 689 | } else { |
| 652 | 690 | prettier_store.update(cx, |prettier_store, _| { |
| 653 | − if let PrettierInstallation::NotInstalled { .. } = &mut prettier_store.default_prettier.prettier { | |
| 691 | + if let PrettierInstallation::NotInstalled { .. } = | |
| 692 | + &mut prettier_store.default_prettier.prettier | |
| 693 | + { | |
| 654 | 694 | prettier_store.default_prettier.prettier = |
| 655 | 695 | PrettierInstallation::Installed(PrettierInstance { |
| 656 | 696 | attempt: 0, |
| @@ -936,11 +976,14 @@ async fn install_prettier_packages( · 279 unmodified lines | ||
| 936 | 976 | anyhow::Ok(()) |
| 937 | 977 | } |
| 938 | 978 | |
| 939 | −async fn save_prettier_server_file(fs: &dyn Fs) -> anyhow::Result<()> { | |
| 979 | +async fn save_prettier_server_file( | |
| 980 | + fs: &dyn Fs, | |
| 981 | + executor: &BackgroundExecutor, | |
| 982 | +) -> anyhow::Result<()> { | |
| 940 | 983 | let prettier_wrapper_path = default_prettier_dir().join(prettier::PRETTIER_SERVER_FILE); |
| 941 | 984 | fs.save( |
| 942 | 985 | &prettier_wrapper_path, |
| 943 | − &text::Rope::from(prettier::PRETTIER_SERVER_JS), | |
| 986 | + &text::Rope::from_str(prettier::PRETTIER_SERVER_JS, executor), | |
| 944 | 987 | text::LineEnding::Unix, |
| 945 | 988 | ) |
| 946 | 989 | .await |
| @@ -712,8 +712,10 @@ pub enum ResolveState { · 711 unmodified lines | ||
| 712 | 712 | impl InlayHint { |
| 713 | 713 | pub fn text(&self) -> Rope { |
| 714 | 714 | match &self.label { |
| 715 | − InlayHintLabel::String(s) => Rope::from(s), | |
| 716 | − InlayHintLabel::LabelParts(parts) => parts.iter().map(|part| &*part.value).collect(), | |
| 715 | + InlayHintLabel::String(s) => Rope::from_str_small(s), | |
| 716 | + InlayHintLabel::LabelParts(parts) => { | |
| 717 | + Rope::from_iter_small(parts.iter().map(|part| &*part.value)) | |
| 718 | + } | |
| 717 | 719 | } |
| 718 | 720 | } |
| 719 | 721 | } |
| @@ -5402,7 +5404,12 @@ impl Project { · 4682 unmodified lines | ||
| 5402 | 5404 | worktree |
| 5403 | 5405 | .update(cx, |worktree, cx| { |
| 5404 | 5406 | let line_ending = text::LineEnding::detect(&new_text); |
| 5405 | − worktree.write_file(rel_path.clone(), new_text.into(), line_ending, cx) | |
| 5407 | + worktree.write_file( | |
| 5408 | + rel_path.clone(), | |
| 5409 | + Rope::from_str(&new_text, cx.background_executor()), | |
| 5410 | + line_ending, | |
| 5411 | + cx, | |
| 5412 | + ) | |
| 5406 | 5413 | })? |
| 5407 | 5414 | .await |
| 5408 | 5415 | .context("Failed to write settings file")?; |
| @@ -1461,21 +1461,21 @@ async fn test_reporting_fs_changes_to_language_servers(cx: &mut gpui::TestAppCon · 1460 unmodified lines | ||
| 1461 | 1461 | .unwrap(); |
| 1462 | 1462 | fs.save( |
| 1463 | 1463 | path!("/the-root/Cargo.lock").as_ref(), |
| 1464 | − &"".into(), | |
| 1464 | + &Rope::default(), | |
| 1465 | 1465 | Default::default(), |
| 1466 | 1466 | ) |
| 1467 | 1467 | .await |
| 1468 | 1468 | .unwrap(); |
| 1469 | 1469 | fs.save( |
| 1470 | 1470 | path!("/the-stdlib/LICENSE").as_ref(), |
| 1471 | − &"".into(), | |
| 1471 | + &Rope::default(), | |
| 1472 | 1472 | Default::default(), |
| 1473 | 1473 | ) |
| 1474 | 1474 | .await |
| 1475 | 1475 | .unwrap(); |
| 1476 | 1476 | fs.save( |
| 1477 | 1477 | path!("/the/stdlib/src/string.rs").as_ref(), |
| 1478 | − &"".into(), | |
| 1478 | + &Rope::default(), | |
| 1479 | 1479 | Default::default(), |
| 1480 | 1480 | ) |
| 1481 | 1481 | .await |
| @@ -4072,7 +4072,7 @@ async fn test_file_changes_multiple_times_on_disk(cx: &mut gpui::TestAppContext) · 2590 unmodified lines | ||
| 4072 | 4072 | // to be detected by the worktree, so that the buffer starts reloading. |
| 4073 | 4073 | fs.save( |
| 4074 | 4074 | path!("/dir/file1").as_ref(), |
| 4075 | − &"the first contents".into(), | |
| 4075 | + &Rope::from_str("the first contents", cx.background_executor()), | |
| 4076 | 4076 | Default::default(), |
| 4077 | 4077 | ) |
| 4078 | 4078 | .await |
| @@ -4083,7 +4083,7 @@ async fn test_file_changes_multiple_times_on_disk(cx: &mut gpui::TestAppContext) · 4 unmodified lines | ||
| 4083 | 4083 | // previous file change may still be in progress. |
| 4084 | 4084 | fs.save( |
| 4085 | 4085 | path!("/dir/file1").as_ref(), |
| 4086 | − &"the second contents".into(), | |
| 4086 | + &Rope::from_str("the second contents", cx.background_executor()), | |
| 4087 | 4087 | Default::default(), |
| 4088 | 4088 | ) |
| 4089 | 4089 | .await |
| @@ -4127,7 +4127,7 @@ async fn test_edit_buffer_while_it_reloads(cx: &mut gpui::TestAppContext) { · 37 unmodified lines | ||
| 4127 | 4127 | // to be detected by the worktree, so that the buffer starts reloading. |
| 4128 | 4128 | fs.save( |
| 4129 | 4129 | path!("/dir/file1").as_ref(), |
| 4130 | − &"the first contents".into(), | |
| 4130 | + &Rope::from_str("the first contents", cx.background_executor()), | |
| 4131 | 4131 | Default::default(), |
| 4132 | 4132 | ) |
| 4133 | 4133 | .await |
| @@ -4805,7 +4805,7 @@ async fn test_buffer_file_changes_on_disk(cx: &mut gpui::TestAppContext) { · 671 unmodified lines | ||
| 4805 | 4805 | marked_text_offsets("oneˇ\nthree ˇFOURˇ five\nsixtyˇ seven\n"); |
| 4806 | 4806 | fs.save( |
| 4807 | 4807 | path!("/dir/the-file").as_ref(), |
| 4808 | − &new_contents.as_str().into(), | |
| 4808 | + &Rope::from_str(new_contents.as_str(), cx.background_executor()), | |
| 4809 | 4809 | LineEnding::Unix, |
| 4810 | 4810 | ) |
| 4811 | 4811 | .await |
| @@ -4837,7 +4837,7 @@ async fn test_buffer_file_changes_on_disk(cx: &mut gpui::TestAppContext) { · 25 unmodified lines | ||
| 4837 | 4837 | // Change the file on disk again, adding blank lines to the beginning. |
| 4838 | 4838 | fs.save( |
| 4839 | 4839 | path!("/dir/the-file").as_ref(), |
| 4840 | − &"\n\n\nAAAA\naaa\nBB\nbbbbb\n".into(), | |
| 4840 | + &Rope::from_str("\n\n\nAAAA\naaa\nBB\nbbbbb\n", cx.background_executor()), | |
| 4841 | 4841 | LineEnding::Unix, |
| 4842 | 4842 | ) |
| 4843 | 4843 | .await |
| @@ -4889,7 +4889,7 @@ async fn test_buffer_line_endings(cx: &mut gpui::TestAppContext) { · 45 unmodified lines | ||
| 4889 | 4889 | // state updates correctly. |
| 4890 | 4890 | fs.save( |
| 4891 | 4891 | path!("/dir/file1").as_ref(), |
| 4892 | − &"aaa\nb\nc\n".into(), | |
| 4892 | + &Rope::from_str("aaa\nb\nc\n", cx.background_executor()), | |
| 4893 | 4893 | LineEnding::Windows, |
| 4894 | 4894 | ) |
| 4895 | 4895 | .await |
| @@ -13,7 +13,7 @@ use fs::{FakeFs, Fs}; · 12 unmodified lines | ||
| 13 | 13 | use gpui::{AppContext as _, Entity, SemanticVersion, SharedString, TestAppContext}; |
| 14 | 14 | use http_client::{BlockedHttpClient, FakeHttpClient}; |
| 15 | 15 | use language::{ |
| 16 | − Buffer, FakeLspAdapter, LanguageConfig, LanguageMatcher, LanguageRegistry, LineEnding, | |
| 16 | + Buffer, FakeLspAdapter, LanguageConfig, LanguageMatcher, LanguageRegistry, LineEnding, Rope, | |
| 17 | 17 | language_settings::{AllLanguageSettings, language_settings}, |
| 18 | 18 | }; |
| 19 | 19 | use lsp::{CompletionContext, CompletionResponse, CompletionTriggerKind, LanguageServerName}; |
| @@ -120,7 +120,7 @@ async fn test_basic_remote_editing(cx: &mut TestAppContext, server_cx: &mut Test · 100 unmodified lines | ||
| 120 | 120 | // sees the new file. |
| 121 | 121 | fs.save( |
| 122 | 122 | path!("/code/project1/src/main.rs").as_ref(), |
| 123 | − &"fn main() {}".into(), | |
| 123 | + &Rope::from_str_small("fn main() {}"), | |
| 124 | 124 | Default::default(), |
| 125 | 125 | ) |
| 126 | 126 | .await |
| @@ -766,7 +766,7 @@ async fn test_remote_reload(cx: &mut TestAppContext, server_cx: &mut TestAppCont · 639 unmodified lines | ||
| 766 | 766 | |
| 767 | 767 | fs.save( |
| 768 | 768 | &PathBuf::from(path!("/code/project1/src/lib.rs")), |
| 769 | − &("bangles".to_string().into()), | |
| 769 | + &Rope::from_str_small("bangles"), | |
| 770 | 770 | LineEnding::Unix, |
| 771 | 771 | ) |
| 772 | 772 | .await |
| @@ -781,7 +781,7 @@ async fn test_remote_reload(cx: &mut TestAppContext, server_cx: &mut TestAppCont · 8 unmodified lines | ||
| 781 | 781 | |
| 782 | 782 | fs.save( |
| 783 | 783 | &PathBuf::from(path!("/code/project1/src/lib.rs")), |
| 784 | − &("bloop".to_string().into()), | |
| 784 | + &Rope::from_str_small("bloop"), | |
| 785 | 785 | LineEnding::Unix, |
| 786 | 786 | ) |
| 787 | 787 | .await |
| @@ -1,9 +1,10 @@ | ||
| 1 | 1 | use futures::FutureExt; |
| 2 | 2 | use gpui::{ |
| 3 | − AnyElement, AnyView, App, ElementId, FontStyle, FontWeight, HighlightStyle, InteractiveText, | |
| 4 | − IntoElement, SharedString, StrikethroughStyle, StyledText, UnderlineStyle, Window, | |
| 3 | + AnyElement, AnyView, App, BackgroundExecutor, ElementId, FontStyle, FontWeight, HighlightStyle, | |
| 4 | + InteractiveText, IntoElement, SharedString, StrikethroughStyle, StyledText, UnderlineStyle, | |
| 5 | + Window, | |
| 5 | 6 | }; |
| 6 | −use language::{HighlightId, Language, LanguageRegistry}; | |
| 7 | +use language::{HighlightId, Language, LanguageRegistry, Rope}; | |
| 7 | 8 | use std::{ops::Range, sync::Arc}; |
| 8 | 9 | use theme::ActiveTheme; |
| 9 | 10 | use ui::LinkPreview; |
| @@ -56,6 +57,7 @@ impl RichText { · 46 unmodified lines | ||
| 56 | 57 | block: String, |
| 57 | 58 | mentions: &[Mention], |
| 58 | 59 | language_registry: &Arc<LanguageRegistry>, |
| 60 | + executor: &BackgroundExecutor, | |
| 59 | 61 | ) -> Self { |
| 60 | 62 | let mut text = String::new(); |
| 61 | 63 | let mut highlights = Vec::new(); |
| @@ -70,6 +72,7 @@ impl RichText { · 8 unmodified lines | ||
| 70 | 72 | &mut highlights, |
| 71 | 73 | &mut link_ranges, |
| 72 | 74 | &mut link_urls, |
| 75 | + executor, | |
| 73 | 76 | ); |
| 74 | 77 | text.truncate(text.trim_end().len()); |
| 75 | 78 | |
| @@ -184,6 +187,7 @@ pub fn render_markdown_mut( · 108 unmodified lines | ||
| 184 | 187 | highlights: &mut Vec<(Range<usize>, Highlight)>, |
| 185 | 188 | link_ranges: &mut Vec<Range<usize>>, |
| 186 | 189 | link_urls: &mut Vec<String>, |
| 190 | + executor: &BackgroundExecutor, | |
| 187 | 191 | ) { |
| 188 | 192 | use pulldown_cmark::{CodeBlockKind, Event, Options, Parser, Tag, TagEnd}; |
| 189 | 193 | |
| @@ -202,7 +206,7 @@ pub fn render_markdown_mut( · 12 unmodified lines | ||
| 202 | 206 | match event { |
| 203 | 207 | Event::Text(t) => { |
| 204 | 208 | if let Some(language) = ¤t_language { |
| 205 | − render_code(text, highlights, t.as_ref(), language); | |
| 209 | + render_code(text, highlights, t.as_ref(), language, executor); | |
| 206 | 210 | } else { |
| 207 | 211 | while let Some(mention) = mentions.first() { |
| 208 | 212 | if !source_range.contains_inclusive(&mention.range) { |
| @@ -373,11 +377,14 @@ pub fn render_code( · 164 unmodified lines | ||
| 373 | 377 | highlights: &mut Vec<(Range<usize>, Highlight)>, |
| 374 | 378 | content: &str, |
| 375 | 379 | language: &Arc<Language>, |
| 380 | + executor: &BackgroundExecutor, | |
| 376 | 381 | ) { |
| 377 | 382 | let prev_len = text.len(); |
| 378 | 383 | text.push_str(content); |
| 379 | 384 | let mut offset = 0; |
| 380 | − for (range, highlight_id) in language.highlight_text(&content.into(), 0..content.len()) { | |
| 385 | + for (range, highlight_id) in | |
| 386 | + language.highlight_text(&Rope::from_str(content, executor), 0..content.len()) | |
| 387 | + { | |
| 381 | 388 | if range.start > offset { |
| 382 | 389 | highlights.push((prev_len + offset..prev_len + range.start, Highlight::Code)); |
| 383 | 390 | } |
| @@ -14,10 +14,10 @@ path = "src/rope.rs" · 13 unmodified lines | ||
| 14 | 14 | [dependencies] |
| 15 | 15 | arrayvec = "0.7.1" |
| 16 | 16 | log.workspace = true |
| 17 | −rayon.workspace = true | |
| 18 | 17 | sum_tree.workspace = true |
| 19 | 18 | unicode-segmentation.workspace = true |
| 20 | 19 | util.workspace = true |
| 20 | +gpui.workspace = true | |
| 21 | 21 | |
| 22 | 22 | [dev-dependencies] |
| 23 | 23 | ctor.workspace = true |
| @@ -3,6 +3,7 @@ use std::ops::Range; · 2 unmodified lines | ||
| 3 | 3 | use criterion::{ |
| 4 | 4 | BatchSize, BenchmarkId, Criterion, Throughput, black_box, criterion_group, criterion_main, |
| 5 | 5 | }; |
| 6 | +use gpui::{AsyncApp, TestAppContext}; | |
| 6 | 7 | use rand::prelude::*; |
| 7 | 8 | use rand::rngs::StdRng; |
| 8 | 9 | use rope::{Point, Rope}; |
| @@ -26,10 +27,10 @@ fn generate_random_text(rng: &mut StdRng, len: usize) -> String { · 17 unmodified lines | ||
| 26 | 27 | str |
| 27 | 28 | } |
| 28 | 29 | |
| 29 | −fn generate_random_rope(rng: &mut StdRng, text_len: usize) -> Rope { | |
| 30 | +fn generate_random_rope(rng: &mut StdRng, text_len: usize, cx: &AsyncApp) -> Rope { | |
| 30 | 31 | let text = generate_random_text(rng, text_len); |
| 31 | 32 | let mut rope = Rope::new(); |
| 32 | − rope.push(&text); | |
| 33 | + rope.push(&text, cx.background_executor()); | |
| 33 | 34 | rope |
| 34 | 35 | } |
| 35 | 36 | |
| @@ -82,11 +83,13 @@ fn rope_benchmarks(c: &mut Criterion) { · 46 unmodified lines | ||
| 82 | 83 | group.bench_with_input(BenchmarkId::from_parameter(size), &size, |b, &size| { |
| 83 | 84 | let mut rng = StdRng::seed_from_u64(SEED); |
| 84 | 85 | let text = generate_random_text(&mut rng, *size); |
| 86 | + let cx = TestAppContext::single(); | |
| 87 | + let cx = cx.to_async(); | |
| 85 | 88 | |
| 86 | 89 | b.iter(|| { |
| 87 | 90 | let mut rope = Rope::new(); |
| 88 | 91 | for _ in 0..10 { |
| 89 | − rope.push(&text); | |
| 92 | + rope.push(&text, cx.background_executor()); | |
| 90 | 93 | } |
| 91 | 94 | }); |
| 92 | 95 | }); |
| @@ -99,8 +102,10 @@ fn rope_benchmarks(c: &mut Criterion) { · 6 unmodified lines | ||
| 99 | 102 | group.bench_with_input(BenchmarkId::from_parameter(size), &size, |b, &size| { |
| 100 | 103 | let mut rng = StdRng::seed_from_u64(SEED); |
| 101 | 104 | let mut random_ropes = Vec::new(); |
| 105 | + let cx = TestAppContext::single(); | |
| 106 | + let cx = cx.to_async(); | |
| 102 | 107 | for _ in 0..5 { |
| 103 | − let rope = generate_random_rope(&mut rng, *size); | |
| 108 | + let rope = generate_random_rope(&mut rng, *size, &cx); | |
| 104 | 109 | random_ropes.push(rope); |
| 105 | 110 | } |
| 106 | 111 | |
| @@ -119,7 +124,9 @@ fn rope_benchmarks(c: &mut Criterion) { · 12 unmodified lines | ||
| 119 | 124 | group.throughput(Throughput::Bytes(*size as u64)); |
| 120 | 125 | group.bench_with_input(BenchmarkId::from_parameter(size), &size, |b, &size| { |
| 121 | 126 | let mut rng = StdRng::seed_from_u64(SEED); |
| 122 | − let rope = generate_random_rope(&mut rng, *size); | |
| 127 | + let cx = TestAppContext::single(); | |
| 128 | + let cx = cx.to_async(); | |
| 129 | + let rope = generate_random_rope(&mut rng, *size, &cx); | |
| 123 | 130 | |
| 124 | 131 | b.iter_batched( |
| 125 | 132 | || generate_random_rope_ranges(&mut rng, &rope), |
| @@ -139,7 +146,9 @@ fn rope_benchmarks(c: &mut Criterion) { · 13 unmodified lines | ||
| 139 | 146 | group.throughput(Throughput::Bytes(*size as u64)); |
| 140 | 147 | group.bench_with_input(BenchmarkId::from_parameter(size), &size, |b, &size| { |
| 141 | 148 | let mut rng = StdRng::seed_from_u64(SEED); |
| 142 | − let rope = generate_random_rope(&mut rng, *size); | |
| 149 | + let cx = TestAppContext::single(); | |
| 150 | + let cx = cx.to_async(); | |
| 151 | + let rope = generate_random_rope(&mut rng, *size, &cx); | |
| 143 | 152 | |
| 144 | 153 | b.iter_batched( |
| 145 | 154 | || generate_random_rope_ranges(&mut rng, &rope), |
| @@ -160,7 +169,9 @@ fn rope_benchmarks(c: &mut Criterion) { · 14 unmodified lines | ||
| 160 | 169 | group.throughput(Throughput::Bytes(*size as u64)); |
| 161 | 170 | group.bench_with_input(BenchmarkId::from_parameter(size), &size, |b, &size| { |
| 162 | 171 | let mut rng = StdRng::seed_from_u64(SEED); |
| 163 | − let rope = generate_random_rope(&mut rng, *size); | |
| 172 | + let cx = TestAppContext::single(); | |
| 173 | + let cx = cx.to_async(); | |
| 174 | + let rope = generate_random_rope(&mut rng, *size, &cx); | |
| 164 | 175 | |
| 165 | 176 | b.iter(|| { |
| 166 | 177 | let chars = rope.chars().count(); |
| @@ -175,7 +186,9 @@ fn rope_benchmarks(c: &mut Criterion) { · 8 unmodified lines | ||
| 175 | 186 | group.throughput(Throughput::Bytes(*size as u64)); |
| 176 | 187 | group.bench_with_input(BenchmarkId::from_parameter(size), &size, |b, &size| { |
| 177 | 188 | let mut rng = StdRng::seed_from_u64(SEED); |
| 178 | − let rope = generate_random_rope(&mut rng, *size); | |
| 189 | + let cx = TestAppContext::single(); | |
| 190 | + let cx = cx.to_async(); | |
| 191 | + let rope = generate_random_rope(&mut rng, *size, &cx); | |
| 179 | 192 | |
| 180 | 193 | b.iter_batched( |
| 181 | 194 | || generate_random_rope_points(&mut rng, &rope), |
| @@ -196,7 +209,9 @@ fn rope_benchmarks(c: &mut Criterion) { · 14 unmodified lines | ||
| 196 | 209 | group.throughput(Throughput::Bytes(*size as u64)); |
| 197 | 210 | group.bench_with_input(BenchmarkId::from_parameter(size), &size, |b, &size| { |
| 198 | 211 | let mut rng = StdRng::seed_from_u64(SEED); |
| 199 | − let rope = generate_random_rope(&mut rng, *size); | |
| 212 | + let cx = TestAppContext::single(); | |
| 213 | + let cx = cx.to_async(); | |
| 214 | + let rope = generate_random_rope(&mut rng, *size, &cx); | |
| 200 | 215 | |
| 201 | 216 | b.iter_batched( |
| 202 | 217 | || generate_random_rope_points(&mut rng, &rope), |
| @@ -216,7 +231,9 @@ fn rope_benchmarks(c: &mut Criterion) { · 13 unmodified lines | ||
| 216 | 231 | group.throughput(Throughput::Bytes(*size as u64)); |
| 217 | 232 | group.bench_with_input(BenchmarkId::from_parameter(size), &size, |b, &size| { |
| 218 | 233 | let mut rng = StdRng::seed_from_u64(SEED); |
| 219 | − let rope = generate_random_rope(&mut rng, *size); | |
| 234 | + let cx = TestAppContext::single(); | |
| 235 | + let cx = cx.to_async(); | |
| 236 | + let rope = generate_random_rope(&mut rng, *size, &cx); | |
| 220 | 237 | |
| 221 | 238 | b.iter_batched( |
| 222 | 239 | || { |
| @@ -5,7 +5,7 @@ mod point_utf16; · 4 unmodified lines | ||
| 5 | 5 | mod unclipped; |
| 6 | 6 | |
| 7 | 7 | use arrayvec::ArrayVec; |
| 8 | −use rayon::iter::{IntoParallelIterator, ParallelIterator as _}; | |
| 8 | +use gpui::BackgroundExecutor; | |
| 9 | 9 | use std::{ |
| 10 | 10 | cmp, fmt, io, mem, |
| 11 | 11 | ops::{self, AddAssign, Range}, |
| @@ -31,6 +31,41 @@ impl Rope { · 19 unmodified lines | ||
| 31 | 31 | Self::default() |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | + /// Create a new rope from a string without trying to parallelize the construction for large strings. | |
| 35 | + pub fn from_str_small(text: &str) -> Self { | |
| 36 | + let mut rope = Self::new(); | |
| 37 | + rope.push_small(text); | |
| 38 | + rope | |
| 39 | + } | |
| 40 | + | |
| 41 | + /// Create a new rope from a string. | |
| 42 | + pub fn from_str(text: &str, executor: &BackgroundExecutor) -> Self { | |
| 43 | + let mut rope = Self::new(); | |
| 44 | + rope.push(text, executor); | |
| 45 | + rope | |
| 46 | + } | |
| 47 | + | |
| 48 | + /// Create a new rope from a string without trying to parallelize the construction for large strings. | |
| 49 | + pub fn from_iter_small<'a, T: IntoIterator<Item = &'a str>>(iter: T) -> Self { | |
| 50 | + let mut rope = Rope::new(); | |
| 51 | + for chunk in iter { | |
| 52 | + rope.push_small(chunk); | |
| 53 | + } | |
| 54 | + rope | |
| 55 | + } | |
| 56 | + | |
| 57 | + /// Create a new rope from a string. | |
| 58 | + pub fn from_iter<'a, T: IntoIterator<Item = &'a str>>( | |
| 59 | + iter: T, | |
| 60 | + executor: &BackgroundExecutor, | |
| 61 | + ) -> Self { | |
| 62 | + let mut rope = Rope::new(); | |
| 63 | + for chunk in iter { | |
| 64 | + rope.push(chunk, executor); | |
| 65 | + } | |
| 66 | + rope | |
| 67 | + } | |
| 68 | + | |
| 34 | 69 | /// Checks that `index`-th byte is the first byte in a UTF-8 code point |
| 35 | 70 | /// sequence or the end of the string. |
| 36 | 71 | /// |
| @@ -145,12 +180,12 @@ impl Rope { · 108 unmodified lines | ||
| 145 | 180 | self.check_invariants(); |
| 146 | 181 | } |
| 147 | 182 | |
| 148 | − pub fn replace(&mut self, range: Range<usize>, text: &str) { | |
| 183 | + pub fn replace(&mut self, range: Range<usize>, text: &str, executor: &BackgroundExecutor) { | |
| 149 | 184 | let mut new_rope = Rope::new(); |
| 150 | 185 | let mut cursor = self.cursor(0); |
| 151 | 186 | new_rope.append(cursor.slice(range.start)); |
| 152 | 187 | cursor.seek_forward(range.end); |
| 153 | − new_rope.push(text); | |
| 188 | + new_rope.push(text, executor); | |
| 154 | 189 | new_rope.append(cursor.suffix()); |
| 155 | 190 | *self = new_rope; |
| 156 | 191 | } |
| @@ -168,28 +203,12 @@ impl Rope { · 11 unmodified lines | ||
| 168 | 203 | self.slice(start..end) |
| 169 | 204 | } |
| 170 | 205 | |
| 171 | − pub fn push(&mut self, mut text: &str) { | |
| 172 | − self.chunks.update_last( | |
| 173 | − |last_chunk| { | |
| 174 | − let split_ix = if last_chunk.text.len() + text.len() <= chunk::MAX_BASE { | |
| 175 | − text.len() | |
| 176 | − } else { | |
| 177 | − let mut split_ix = cmp::min( | |
| 178 | − chunk::MIN_BASE.saturating_sub(last_chunk.text.len()), | |
| 179 | − text.len(), | |
| 180 | − ); | |
| 181 | − while !text.is_char_boundary(split_ix) { | |
| 182 | − split_ix += 1; | |
| 183 | − } | |
| 184 | − split_ix | |
| 185 | − }; | |
| 206 | + pub fn push(&mut self, mut text: &str, executor: &BackgroundExecutor) { | |
| 207 | + self.fill_last_chunk(&mut text); | |
| 186 | 208 | |
| 187 | − let (suffix, remainder) = text.split_at(split_ix); | |
| 188 | − last_chunk.push_str(suffix); | |
| 189 | − text = remainder; | |
| 190 | − }, | |
| 191 | − (), | |
| 192 | − ); | |
| 209 | + if text.is_empty() { | |
| 210 | + return; | |
| 211 | + } | |
| 193 | 212 | |
| 194 | 213 | #[cfg(all(test, not(rust_analyzer)))] |
| 195 | 214 | const NUM_CHUNKS: usize = 16; |
| @@ -200,7 +219,8 @@ impl Rope { · 4 unmodified lines | ||
| 200 | 219 | // but given the chunk boundary can land within a character |
| 201 | 220 | // we need to accommodate for the worst case where every chunk gets cut short by up to 4 bytes |
| 202 | 221 | if text.len() > NUM_CHUNKS * chunk::MAX_BASE - NUM_CHUNKS * 4 { |
| 203 | − return self.push_large(text); | |
| 222 | + let future = self.push_large(text, executor.clone()); | |
| 223 | + return executor.block(future); | |
| 204 | 224 | } |
| 205 | 225 | // 16 is enough as otherwise we will hit the branch above |
| 206 | 226 | let mut new_chunks = ArrayVec::<_, NUM_CHUNKS>::new(); |
| @@ -220,8 +240,57 @@ impl Rope { · 13 unmodified lines | ||
| 220 | 240 | self.check_invariants(); |
| 221 | 241 | } |
| 222 | 242 | |
| 243 | + /// Pushes a string into the rope. Unlike [`push`], this method does not parallelize the construction on large strings. | |
| 244 | + pub fn push_small(&mut self, mut text: &str) { | |
| 245 | + self.fill_last_chunk(&mut text); | |
| 246 | + if text.is_empty() { | |
| 247 | + return; | |
| 248 | + } | |
| 249 | + | |
| 250 | + // 16 is enough as otherwise we will hit the branch above | |
| 251 | + let mut new_chunks = Vec::new(); | |
| 252 | + | |
| 253 | + while !text.is_empty() { | |
| 254 | + let mut split_ix = cmp::min(chunk::MAX_BASE, text.len()); | |
| 255 | + while !text.is_char_boundary(split_ix) { | |
| 256 | + split_ix -= 1; | |
| 257 | + } | |
| 258 | + let (chunk, remainder) = text.split_at(split_ix); | |
| 259 | + new_chunks.push(chunk); | |
| 260 | + text = remainder; | |
| 261 | + } | |
| 262 | + self.chunks | |
| 263 | + .extend(new_chunks.into_iter().map(Chunk::new), ()); | |
| 264 | + | |
| 265 | + self.check_invariants(); | |
| 266 | + } | |
| 267 | + | |
| 268 | + fn fill_last_chunk(&mut self, text: &mut &str) { | |
| 269 | + self.chunks.update_last( | |
| 270 | + |last_chunk| { | |
| 271 | + let split_ix = if last_chunk.text.len() + text.len() <= chunk::MAX_BASE { | |
| 272 | + text.len() | |
| 273 | + } else { | |
| 274 | + let mut split_ix = cmp::min( | |
| 275 | + chunk::MIN_BASE.saturating_sub(last_chunk.text.len()), | |
| 276 | + text.len(), | |
| 277 | + ); | |
| 278 | + while !text.is_char_boundary(split_ix) { | |
| 279 | + split_ix += 1; | |
| 280 | + } | |
| 281 | + split_ix | |
| 282 | + }; | |
| 283 | + | |
| 284 | + let (suffix, remainder) = text.split_at(split_ix); | |
| 285 | + last_chunk.push_str(suffix); | |
| 286 | + *text = remainder; | |
| 287 | + }, | |
| 288 | + (), | |
| 289 | + ); | |
| 290 | + } | |
| 291 | + | |
| 223 | 292 | /// A copy of `push` specialized for working with large quantities of text. |
| 224 | − fn push_large(&mut self, mut text: &str) { | |
| 293 | + async fn push_large(&mut self, mut text: &str, executor: BackgroundExecutor) { | |
| 225 | 294 | // To avoid frequent reallocs when loading large swaths of file contents, |
| 226 | 295 | // we estimate worst-case `new_chunks` capacity; |
| 227 | 296 | // Chunk is a fixed-capacity buffer. If a character falls on |
| @@ -254,8 +323,22 @@ impl Rope { · 26 unmodified lines | ||
| 254 | 323 | const PARALLEL_THRESHOLD: usize = 4 * (2 * sum_tree::TREE_BASE); |
| 255 | 324 | |
| 256 | 325 | if new_chunks.len() >= PARALLEL_THRESHOLD { |
| 257 | − self.chunks | |
| 258 | − .par_extend(new_chunks.into_par_iter().map(Chunk::new), ()); | |
| 326 | + let cx2 = executor.clone(); | |
| 327 | + executor | |
| 328 | + .scoped(|scope| { | |
| 329 | + // SAFETY: transmuting to 'static is safe because the future is scoped | |
| 330 | + // and the underlying string data cannot go out of scope because dropping the scope | |
| 331 | + // will wait for the task to finish | |
| 332 | + let new_chunks = | |
| 333 | + unsafe { std::mem::transmute::<Vec<&str>, Vec<&'static str>>(new_chunks) }; | |
| 334 | + | |
| 335 | + let async_extend = self | |
| 336 | + .chunks | |
| 337 | + .async_extend(new_chunks.into_iter().map(Chunk::new), cx2); | |
| 338 | + | |
| 339 | + scope.spawn(async_extend); | |
| 340 | + }) | |
| 341 | + .await; | |
| 259 | 342 | } else { |
| 260 | 343 | self.chunks |
| 261 | 344 | .extend(new_chunks.into_iter().map(Chunk::new), ()); |
| @@ -292,8 +375,13 @@ impl Rope { · 30 unmodified lines | ||
| 292 | 375 | } |
| 293 | 376 | } |
| 294 | 377 | |
| 295 | − pub fn push_front(&mut self, text: &str) { | |
| 296 | − let suffix = mem::replace(self, Rope::from(text)); | |
| 378 | + pub fn push_front(&mut self, text: &str, cx: &BackgroundExecutor) { | |
| 379 | + let suffix = mem::replace(self, Rope::from_str(text, cx)); | |
| 380 | + self.append(suffix); | |
| 381 | + } | |
| 382 | + | |
| 383 | + pub fn push_front_small(&mut self, text: &str) { | |
| 384 | + let suffix = mem::replace(self, Rope::from_str_small(text)); | |
| 297 | 385 | self.append(suffix); |
| 298 | 386 | } |
| 299 | 387 | |
| @@ -577,37 +665,19 @@ impl Rope { · 277 unmodified lines | ||
| 577 | 665 | } |
| 578 | 666 | } |
| 579 | 667 | |
| 580 | −impl<'a> From<&'a str> for Rope { | |
| 581 | − fn from(text: &'a str) -> Self { | |
| 582 | − let mut rope = Self::new(); | |
| 583 | − rope.push(text); | |
| 584 | − rope | |
| 585 | − } | |
| 586 | −} | |
| 668 | +// impl From<String> for Rope { | |
| 669 | +// #[inline(always)] | |
| 670 | +// fn from(text: String) -> Self { | |
| 671 | +// Rope::from(text.as_str()) | |
| 672 | +// } | |
| 673 | +// } | |
| 587 | 674 | |
| 588 | −impl<'a> FromIterator<&'a str> for Rope { | |
| 589 | − fn from_iter<T: IntoIterator<Item = &'a str>>(iter: T) -> Self { | |
| 590 | − let mut rope = Rope::new(); | |
| 591 | − for chunk in iter { | |
| 592 | − rope.push(chunk); | |
| 593 | − } | |
| 594 | − rope | |
| 595 | − } | |
| 596 | −} | |
| 597 | − | |
| 598 | −impl From<String> for Rope { | |
| 599 | − #[inline(always)] | |
| 600 | − fn from(text: String) -> Self { | |
| 601 | − Rope::from(text.as_str()) | |
| 602 | − } | |
| 603 | −} | |
| 604 | − | |
| 605 | −impl From<&String> for Rope { | |
| 606 | − #[inline(always)] | |
| 607 | − fn from(text: &String) -> Self { | |
| 608 | − Rope::from(text.as_str()) | |
| 609 | − } | |
| 610 | −} | |
| 675 | +// impl From<&String> for Rope { | |
| 676 | +// #[inline(always)] | |
| 677 | +// fn from(text: &String) -> Self { | |
| 678 | +// Rope::from(text.as_str()) | |
| 679 | +// } | |
| 680 | +// } | |
| 611 | 681 | |
| 612 | 682 | impl fmt::Display for Rope { |
| 613 | 683 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| @@ -1639,6 +1709,7 @@ where · 1025 unmodified lines | ||
| 1639 | 1709 | mod tests { |
| 1640 | 1710 | use super::*; |
| 1641 | 1711 | use Bias::{Left, Right}; |
| 1712 | + use gpui::TestAppContext; | |
| 1642 | 1713 | use rand::prelude::*; |
| 1643 | 1714 | use std::{cmp::Ordering, env, io::Read}; |
| 1644 | 1715 | use util::RandomCharIter; |
| @@ -1648,17 +1719,17 @@ mod tests { · 3 unmodified lines | ||
| 1648 | 1719 | zlog::init_test(); |
| 1649 | 1720 | } |
| 1650 | 1721 | |
| 1651 | − #[test] | |
| 1652 | − fn test_all_4_byte_chars() { | |
| 1722 | + #[gpui::test] | |
| 1723 | + async fn test_all_4_byte_chars(cx: &mut TestAppContext) { | |
| 1653 | 1724 | let mut rope = Rope::new(); |
| 1654 | 1725 | let text = "🏀".repeat(256); |
| 1655 | − rope.push(&text); | |
| 1726 | + rope.push(&text, cx.background_executor()); | |
| 1656 | 1727 | assert_eq!(rope.text(), text); |
| 1657 | 1728 | } |
| 1658 | 1729 | |
| 1659 | − #[test] | |
| 1660 | − fn test_clip() { | |
| 1661 | − let rope = Rope::from("🧘"); | |
| 1730 | + #[gpui::test] | |
| 1731 | + fn test_clip(cx: &mut TestAppContext) { | |
| 1732 | + let rope = Rope::from_str("🧘", cx.background_executor()); | |
| 1662 | 1733 | |
| 1663 | 1734 | assert_eq!(rope.clip_offset(1, Bias::Left), 0); |
| 1664 | 1735 | assert_eq!(rope.clip_offset(1, Bias::Right), 4); |
| @@ -1704,9 +1775,9 @@ mod tests { · 39 unmodified lines | ||
| 1704 | 1775 | ); |
| 1705 | 1776 | } |
| 1706 | 1777 | |
| 1707 | − #[test] | |
| 1708 | − fn test_prev_next_line() { | |
| 1709 | − let rope = Rope::from("abc\ndef\nghi\njkl"); | |
| 1778 | + #[gpui::test] | |
| 1779 | + fn test_prev_next_line(cx: &mut TestAppContext) { | |
| 1780 | + let rope = Rope::from_str("abc\ndef\nghi\njkl", cx.background_executor()); | |
| 1710 | 1781 | |
| 1711 | 1782 | let mut chunks = rope.chunks(); |
| 1712 | 1783 | assert_eq!(chunks.peek().unwrap().chars().next().unwrap(), 'a'); |
| @@ -1748,16 +1819,16 @@ mod tests { · 35 unmodified lines | ||
| 1748 | 1819 | assert_eq!(chunks.peek(), None); |
| 1749 | 1820 | } |
| 1750 | 1821 | |
| 1751 | − #[test] | |
| 1752 | − fn test_lines() { | |
| 1753 | − let rope = Rope::from("abc\ndefg\nhi"); | |
| 1822 | + #[gpui::test] | |
| 1823 | + fn test_lines(cx: &mut TestAppContext) { | |
| 1824 | + let rope = Rope::from_str("abc\ndefg\nhi", cx.background_executor()); | |
| 1754 | 1825 | let mut lines = rope.chunks().lines(); |
| 1755 | 1826 | assert_eq!(lines.next(), Some("abc")); |
| 1756 | 1827 | assert_eq!(lines.next(), Some("defg")); |
| 1757 | 1828 | assert_eq!(lines.next(), Some("hi")); |
| 1758 | 1829 | assert_eq!(lines.next(), None); |
| 1759 | 1830 | |
| 1760 | − let rope = Rope::from("abc\ndefg\nhi\n"); | |
| 1831 | + let rope = Rope::from_str("abc\ndefg\nhi\n", cx.background_executor()); | |
| 1761 | 1832 | let mut lines = rope.chunks().lines(); |
| 1762 | 1833 | assert_eq!(lines.next(), Some("abc")); |
| 1763 | 1834 | assert_eq!(lines.next(), Some("defg")); |
| @@ -1765,14 +1836,14 @@ mod tests { · 1 unmodified line | ||
| 1765 | 1836 | assert_eq!(lines.next(), Some("")); |
| 1766 | 1837 | assert_eq!(lines.next(), None); |
| 1767 | 1838 | |
| 1768 | − let rope = Rope::from("abc\ndefg\nhi"); | |
| 1839 | + let rope = Rope::from_str("abc\ndefg\nhi", cx.background_executor()); | |
| 1769 | 1840 | let mut lines = rope.reversed_chunks_in_range(0..rope.len()).lines(); |
| 1770 | 1841 | assert_eq!(lines.next(), Some("hi")); |
| 1771 | 1842 | assert_eq!(lines.next(), Some("defg")); |
| 1772 | 1843 | assert_eq!(lines.next(), Some("abc")); |
| 1773 | 1844 | assert_eq!(lines.next(), None); |
| 1774 | 1845 | |
| 1775 | − let rope = Rope::from("abc\ndefg\nhi\n"); | |
| 1846 | + let rope = Rope::from_str("abc\ndefg\nhi\n", cx.background_executor()); | |
| 1776 | 1847 | let mut lines = rope.reversed_chunks_in_range(0..rope.len()).lines(); |
| 1777 | 1848 | assert_eq!(lines.next(), Some("")); |
| 1778 | 1849 | assert_eq!(lines.next(), Some("hi")); |
| @@ -1780,14 +1851,14 @@ mod tests { · 1 unmodified line | ||
| 1780 | 1851 | assert_eq!(lines.next(), Some("abc")); |
| 1781 | 1852 | assert_eq!(lines.next(), None); |
| 1782 | 1853 | |
| 1783 | − let rope = Rope::from("abc\nlonger line test\nhi"); | |
| 1854 | + let rope = Rope::from_str("abc\nlonger line test\nhi", cx.background_executor()); | |
| 1784 | 1855 | let mut lines = rope.chunks().lines(); |
| 1785 | 1856 | assert_eq!(lines.next(), Some("abc")); |
| 1786 | 1857 | assert_eq!(lines.next(), Some("longer line test")); |
| 1787 | 1858 | assert_eq!(lines.next(), Some("hi")); |
| 1788 | 1859 | assert_eq!(lines.next(), None); |
| 1789 | 1860 | |
| 1790 | − let rope = Rope::from("abc\nlonger line test\nhi"); | |
| 1861 | + let rope = Rope::from_str("abc\nlonger line test\nhi", cx.background_executor()); | |
| 1791 | 1862 | let mut lines = rope.reversed_chunks_in_range(0..rope.len()).lines(); |
| 1792 | 1863 | assert_eq!(lines.next(), Some("hi")); |
| 1793 | 1864 | assert_eq!(lines.next(), Some("longer line test")); |
| @@ -1796,7 +1867,7 @@ mod tests { · 2 unmodified lines | ||
| 1796 | 1867 | } |
| 1797 | 1868 | |
| 1798 | 1869 | #[gpui::test(iterations = 100)] |
| 1799 | − fn test_random_rope(mut rng: StdRng) { | |
| 1870 | + async fn test_random_rope(cx: &mut TestAppContext, mut rng: StdRng) { | |
| 1800 | 1871 | let operations = env::var("OPERATIONS") |
| 1801 | 1872 | .map(|i| i.parse().expect("invalid `OPERATIONS` variable")) |
| 1802 | 1873 | .unwrap_or(10); |
| @@ -1812,7 +1883,7 @@ mod tests { · 9 unmodified lines | ||
| 1812 | 1883 | let mut new_actual = Rope::new(); |
| 1813 | 1884 | let mut cursor = actual.cursor(0); |
| 1814 | 1885 | new_actual.append(cursor.slice(start_ix)); |
| 1815 | − new_actual.push(&new_text); | |
| 1886 | + new_actual.push(&new_text, cx.background_executor()); | |
| 1816 | 1887 | cursor.seek_forward(end_ix); |
| 1817 | 1888 | new_actual.append(cursor.suffix()); |
| 1818 | 1889 | actual = new_actual; |
| @@ -2112,10 +2183,10 @@ mod tests { · 293 unmodified lines | ||
| 2112 | 2183 | } |
| 2113 | 2184 | } |
| 2114 | 2185 | |
| 2115 | − #[test] | |
| 2116 | − fn test_chunks_equals_str() { | |
| 2186 | + #[gpui::test] | |
| 2187 | + fn test_chunks_equals_str(cx: &mut TestAppContext) { | |
| 2117 | 2188 | let text = "This is a multi-chunk\n& multi-line test string!"; |
| 2118 | − let rope = Rope::from(text); | |
| 2189 | + let rope = Rope::from_str(text, cx.background_executor()); | |
| 2119 | 2190 | for start in 0..text.len() { |
| 2120 | 2191 | for end in start..text.len() { |
| 2121 | 2192 | let range = start..end; |
| @@ -2158,34 +2229,37 @@ mod tests { · 36 unmodified lines | ||
| 2158 | 2229 | } |
| 2159 | 2230 | } |
| 2160 | 2231 | |
| 2161 | − let rope = Rope::from(""); | |
| 2232 | + let rope = Rope::from_str("", cx.background_executor()); | |
| 2162 | 2233 | assert!(rope.chunks_in_range(0..0).equals_str("")); |
| 2163 | 2234 | assert!(rope.reversed_chunks_in_range(0..0).equals_str("")); |
| 2164 | 2235 | assert!(!rope.chunks_in_range(0..0).equals_str("foo")); |
| 2165 | 2236 | assert!(!rope.reversed_chunks_in_range(0..0).equals_str("foo")); |
| 2166 | 2237 | } |
| 2167 | 2238 | |
| 2168 | − #[test] | |
| 2169 | − fn test_is_char_boundary() { | |
| 2239 | + #[gpui::test] | |
| 2240 | + fn test_is_char_boundary(cx: &mut TestAppContext) { | |
| 2170 | 2241 | let fixture = "地"; |
| 2171 | − let rope = Rope::from("地"); | |
| 2242 | + let rope = Rope::from_str("地", cx.background_executor()); | |
| 2172 | 2243 | for b in 0..=fixture.len() { |
| 2173 | 2244 | assert_eq!(rope.is_char_boundary(b), fixture.is_char_boundary(b)); |
| 2174 | 2245 | } |
| 2175 | 2246 | let fixture = ""; |
| 2176 | − let rope = Rope::from(""); | |
| 2247 | + let rope = Rope::from_str("", cx.background_executor()); | |
| 2177 | 2248 | for b in 0..=fixture.len() { |
| 2178 | 2249 | assert_eq!(rope.is_char_boundary(b), fixture.is_char_boundary(b)); |
| 2179 | 2250 | } |
| 2180 | 2251 | let fixture = "🔴🟠🟡🟢🔵🟣⚫️⚪️🟤\n🏳️⚧️🏁🏳️🌈🏴☠️⛳️📬📭🏴🏳️🚩"; |
| 2181 | − let rope = Rope::from("🔴🟠🟡🟢🔵🟣⚫️⚪️🟤\n🏳️⚧️🏁🏳️🌈🏴☠️⛳️📬📭🏴🏳️🚩"); | |
| 2252 | + let rope = Rope::from_str( | |
| 2253 | + "🔴🟠🟡🟢🔵🟣⚫️⚪️🟤\n🏳️⚧️🏁🏳️🌈🏴☠️⛳️📬📭🏴🏳️🚩", | |
| 2254 | + cx.background_executor(), | |
| 2255 | + ); | |
| 2182 | 2256 | for b in 0..=fixture.len() { |
| 2183 | 2257 | assert_eq!(rope.is_char_boundary(b), fixture.is_char_boundary(b)); |
| 2184 | 2258 | } |
| 2185 | 2259 | } |
| 2186 | 2260 | |
| 2187 | − #[test] | |
| 2188 | − fn test_floor_char_boundary() { | |
| 2261 | + #[gpui::test] | |
| 2262 | + fn test_floor_char_boundary(cx: &mut TestAppContext) { | |
| 2189 | 2263 | // polyfill of str::floor_char_boundary |
| 2190 | 2264 | fn floor_char_boundary(str: &str, index: usize) -> usize { |
| 2191 | 2265 | if index >= str.len() { |
| @@ -2201,7 +2275,7 @@ mod tests { · 9 unmodified lines | ||
| 2201 | 2275 | } |
| 2202 | 2276 | |
| 2203 | 2277 | let fixture = "地"; |
| 2204 | − let rope = Rope::from("地"); | |
| 2278 | + let rope = Rope::from_str("地", cx.background_executor()); | |
| 2205 | 2279 | for b in 0..=fixture.len() { |
| 2206 | 2280 | assert_eq!( |
| 2207 | 2281 | rope.floor_char_boundary(b), |
| @@ -2210,7 +2284,7 @@ mod tests { · 2 unmodified lines | ||
| 2210 | 2284 | } |
| 2211 | 2285 | |
| 2212 | 2286 | let fixture = ""; |
| 2213 | − let rope = Rope::from(""); | |
| 2287 | + let rope = Rope::from_str("", cx.background_executor()); | |
| 2214 | 2288 | for b in 0..=fixture.len() { |
| 2215 | 2289 | assert_eq!( |
| 2216 | 2290 | rope.floor_char_boundary(b), |
| @@ -2219,7 +2293,10 @@ mod tests { · 2 unmodified lines | ||
| 2219 | 2293 | } |
| 2220 | 2294 | |
| 2221 | 2295 | let fixture = "🔴🟠🟡🟢🔵🟣⚫️⚪️🟤\n🏳️⚧️🏁🏳️🌈🏴☠️⛳️📬📭🏴🏳️🚩"; |
| 2222 | − let rope = Rope::from("🔴🟠🟡🟢🔵🟣⚫️⚪️🟤\n🏳️⚧️🏁🏳️🌈🏴☠️⛳️📬📭🏴🏳️🚩"); | |
| 2296 | + let rope = Rope::from_str( | |
| 2297 | + "🔴🟠🟡🟢🔵🟣⚫️⚪️🟤\n🏳️⚧️🏁🏳️🌈🏴☠️⛳️📬📭🏴🏳️🚩", | |
| 2298 | + cx.background_executor(), | |
| 2299 | + ); | |
| 2223 | 2300 | for b in 0..=fixture.len() { |
| 2224 | 2301 | assert_eq!( |
| 2225 | 2302 | rope.floor_char_boundary(b), |
| @@ -2228,8 +2305,8 @@ mod tests { · 2 unmodified lines | ||
| 2228 | 2305 | } |
| 2229 | 2306 | } |
| 2230 | 2307 | |
| 2231 | − #[test] | |
| 2232 | − fn test_ceil_char_boundary() { | |
| 2308 | + #[gpui::test] | |
| 2309 | + fn test_ceil_char_boundary(cx: &mut TestAppContext) { | |
| 2233 | 2310 | // polyfill of str::ceil_char_boundary |
| 2234 | 2311 | fn ceil_char_boundary(str: &str, index: usize) -> usize { |
| 2235 | 2312 | if index > str.len() { |
| @@ -2244,19 +2321,22 @@ mod tests { · 8 unmodified lines | ||
| 2244 | 2321 | } |
| 2245 | 2322 | |
| 2246 | 2323 | let fixture = "地"; |
| 2247 | − let rope = Rope::from("地"); | |
| 2324 | + let rope = Rope::from_str("地", cx.background_executor()); | |
| 2248 | 2325 | for b in 0..=fixture.len() { |
| 2249 | 2326 | assert_eq!(rope.ceil_char_boundary(b), ceil_char_boundary(&fixture, b)); |
| 2250 | 2327 | } |
| 2251 | 2328 | |
| 2252 | 2329 | let fixture = ""; |
| 2253 | − let rope = Rope::from(""); | |
| 2330 | + let rope = Rope::from_str("", cx.background_executor()); | |
| 2254 | 2331 | for b in 0..=fixture.len() { |
| 2255 | 2332 | assert_eq!(rope.ceil_char_boundary(b), ceil_char_boundary(&fixture, b)); |
| 2256 | 2333 | } |
| 2257 | 2334 | |
| 2258 | 2335 | let fixture = "🔴🟠🟡🟢🔵🟣⚫️⚪️🟤\n🏳️⚧️🏁🏳️🌈🏴☠️⛳️📬📭🏴🏳️🚩"; |
| 2259 | − let rope = Rope::from("🔴🟠🟡🟢🔵🟣⚫️⚪️🟤\n🏳️⚧️🏁🏳️🌈🏴☠️⛳️📬📭🏴🏳️🚩"); | |
| 2336 | + let rope = Rope::from_str( | |
| 2337 | + "🔴🟠🟡🟢🔵🟣⚫️⚪️🟤\n🏳️⚧️🏁🏳️🌈🏴☠️⛳️📬📭🏴🏳️🚩", | |
| 2338 | + cx.background_executor(), | |
| 2339 | + ); | |
| 2260 | 2340 | for b in 0..=fixture.len() { |
| 2261 | 2341 | assert_eq!(rope.ceil_char_boundary(b), ceil_char_boundary(&fixture, b)); |
| 2262 | 2342 | } |
| @@ -554,7 +554,7 @@ impl RulesLibrary { · 553 unmodified lines | ||
| 554 | 554 | |
| 555 | 555 | let prompt_id = PromptId::new(); |
| 556 | 556 | let save = self.store.update(cx, |store, cx| { |
| 557 | − store.save(prompt_id, None, false, "".into(), cx) | |
| 557 | + store.save(prompt_id, None, false, Default::default(), cx) | |
| 558 | 558 | }); |
| 559 | 559 | self.picker |
| 560 | 560 | .update(cx, |picker, cx| picker.refresh(window, cx)); |
| @@ -888,7 +888,13 @@ impl RulesLibrary { · 327 unmodified lines | ||
| 888 | 888 | let new_id = PromptId::new(); |
| 889 | 889 | let body = rule.body_editor.read(cx).text(cx); |
| 890 | 890 | let save = self.store.update(cx, |store, cx| { |
| 891 | − store.save(new_id, Some(title.into()), false, body.into(), cx) | |
| 891 | + store.save( | |
| 892 | + new_id, | |
| 893 | + Some(title.into()), | |
| 894 | + false, | |
| 895 | + Rope::from_str(&body, cx.background_executor()), | |
| 896 | + cx, | |
| 897 | + ) | |
| 892 | 898 | }); |
| 893 | 899 | self.picker |
| 894 | 900 | .update(cx, |picker, cx| picker.refresh(window, cx)); |
| @@ -14,6 +14,7 @@ path = "src/streaming_diff.rs" · 13 unmodified lines | ||
| 14 | 14 | [dependencies] |
| 15 | 15 | ordered-float.workspace = true |
| 16 | 16 | rope.workspace = true |
| 17 | +gpui.workspace = true | |
| 17 | 18 | |
| 18 | 19 | [dev-dependencies] |
| 19 | 20 | rand.workspace = true |
| @@ -503,11 +503,12 @@ fn is_line_end(point: Point, text: &Rope) -> bool { · 502 unmodified lines | ||
| 503 | 503 | #[cfg(test)] |
| 504 | 504 | mod tests { |
| 505 | 505 | use super::*; |
| 506 | + use gpui::BackgroundExecutor; | |
| 506 | 507 | use rand::prelude::*; |
| 507 | 508 | use std::env; |
| 508 | 509 | |
| 509 | − #[test] | |
| 510 | − fn test_delete_first_of_two_lines() { | |
| 510 | + #[gpui::test] | |
| 511 | + fn test_delete_first_of_two_lines(cx: &mut gpui::TestAppContext) { | |
| 511 | 512 | let old_text = "aaaa\nbbbb"; |
| 512 | 513 | let char_ops = vec![ |
| 513 | 514 | CharOperation::Delete { bytes: 5 }, |
| @@ -523,18 +524,18 @@ mod tests { · 9 unmodified lines | ||
| 523 | 524 | apply_line_operations(old_text, &new_text, &expected_line_ops) |
| 524 | 525 | ); |
| 525 | 526 | |
| 526 | − let line_ops = char_ops_to_line_ops(old_text, &char_ops); | |
| 527 | + let line_ops = char_ops_to_line_ops(old_text, &char_ops, cx.background_executor()); | |
| 527 | 528 | assert_eq!(line_ops, expected_line_ops); |
| 528 | 529 | } |
| 529 | 530 | |
| 530 | − #[test] | |
| 531 | − fn test_delete_second_of_two_lines() { | |
| 531 | + #[gpui::test] | |
| 532 | + fn test_delete_second_of_two_lines(cx: &mut gpui::TestAppContext) { | |
| 532 | 533 | let old_text = "aaaa\nbbbb"; |
| 533 | 534 | let char_ops = vec![ |
| 534 | 535 | CharOperation::Keep { bytes: 5 }, |
| 535 | 536 | CharOperation::Delete { bytes: 4 }, |
| 536 | 537 | ]; |
| 537 | − let line_ops = char_ops_to_line_ops(old_text, &char_ops); | |
| 538 | + let line_ops = char_ops_to_line_ops(old_text, &char_ops, cx.background_executor()); | |
| 538 | 539 | assert_eq!( |
| 539 | 540 | line_ops, |
| 540 | 541 | vec![ |
| @@ -550,8 +551,8 @@ mod tests { · 9 unmodified lines | ||
| 550 | 551 | ); |
| 551 | 552 | } |
| 552 | 553 | |
| 553 | − #[test] | |
| 554 | − fn test_add_new_line() { | |
| 554 | + #[gpui::test] | |
| 555 | + fn test_add_new_line(cx: &mut gpui::TestAppContext) { | |
| 555 | 556 | let old_text = "aaaa\nbbbb"; |
| 556 | 557 | let char_ops = vec![ |
| 557 | 558 | CharOperation::Keep { bytes: 9 }, |
| @@ -559,7 +560,7 @@ mod tests { · 1 unmodified line | ||
| 559 | 560 | text: "\ncccc".into(), |
| 560 | 561 | }, |
| 561 | 562 | ]; |
| 562 | − let line_ops = char_ops_to_line_ops(old_text, &char_ops); | |
| 563 | + let line_ops = char_ops_to_line_ops(old_text, &char_ops, cx.background_executor()); | |
| 563 | 564 | assert_eq!( |
| 564 | 565 | line_ops, |
| 565 | 566 | vec![ |
| @@ -574,15 +575,15 @@ mod tests { · 8 unmodified lines | ||
| 574 | 575 | ); |
| 575 | 576 | } |
| 576 | 577 | |
| 577 | − #[test] | |
| 578 | − fn test_delete_line_in_middle() { | |
| 578 | + #[gpui::test] | |
| 579 | + fn test_delete_line_in_middle(cx: &mut gpui::TestAppContext) { | |
| 579 | 580 | let old_text = "aaaa\nbbbb\ncccc"; |
| 580 | 581 | let char_ops = vec![ |
| 581 | 582 | CharOperation::Keep { bytes: 5 }, |
| 582 | 583 | CharOperation::Delete { bytes: 5 }, |
| 583 | 584 | CharOperation::Keep { bytes: 4 }, |
| 584 | 585 | ]; |
| 585 | − let line_ops = char_ops_to_line_ops(old_text, &char_ops); | |
| 586 | + let line_ops = char_ops_to_line_ops(old_text, &char_ops, cx.background_executor()); | |
| 586 | 587 | assert_eq!( |
| 587 | 588 | line_ops, |
| 588 | 589 | vec![ |
| @@ -598,8 +599,8 @@ mod tests { · 9 unmodified lines | ||
| 598 | 599 | ); |
| 599 | 600 | } |
| 600 | 601 | |
| 601 | − #[test] | |
| 602 | − fn test_replace_line() { | |
| 602 | + #[gpui::test] | |
| 603 | + fn test_replace_line(cx: &mut gpui::TestAppContext) { | |
| 603 | 604 | let old_text = "aaaa\nbbbb\ncccc"; |
| 604 | 605 | let char_ops = vec![ |
| 605 | 606 | CharOperation::Keep { bytes: 5 }, |
| @@ -609,7 +610,7 @@ mod tests { · 3 unmodified lines | ||
| 609 | 610 | }, |
| 610 | 611 | CharOperation::Keep { bytes: 5 }, |
| 611 | 612 | ]; |
| 612 | − let line_ops = char_ops_to_line_ops(old_text, &char_ops); | |
| 613 | + let line_ops = char_ops_to_line_ops(old_text, &char_ops, cx.background_executor()); | |
| 613 | 614 | assert_eq!( |
| 614 | 615 | line_ops, |
| 615 | 616 | vec![ |
| @@ -626,8 +627,8 @@ mod tests { · 10 unmodified lines | ||
| 626 | 627 | ); |
| 627 | 628 | } |
| 628 | 629 | |
| 629 | − #[test] | |
| 630 | − fn test_multiple_edits_on_different_lines() { | |
| 630 | + #[gpui::test] | |
| 631 | + fn test_multiple_edits_on_different_lines(cx: &mut gpui::TestAppContext) { | |
| 631 | 632 | let old_text = "aaaa\nbbbb\ncccc\ndddd"; |
| 632 | 633 | let char_ops = vec![ |
| 633 | 634 | CharOperation::Insert { text: "A".into() }, |
| @@ -638,7 +639,7 @@ mod tests { · 4 unmodified lines | ||
| 638 | 639 | text: "\nEEEE".into(), |
| 639 | 640 | }, |
| 640 | 641 | ]; |
| 641 | − let line_ops = char_ops_to_line_ops(old_text, &char_ops); | |
| 642 | + let line_ops = char_ops_to_line_ops(old_text, &char_ops, cx.background_executor()); | |
| 642 | 643 | assert_eq!( |
| 643 | 644 | line_ops, |
| 644 | 645 | vec![ |
| @@ -656,15 +657,15 @@ mod tests { · 11 unmodified lines | ||
| 656 | 657 | ); |
| 657 | 658 | } |
| 658 | 659 | |
| 659 | − #[test] | |
| 660 | − fn test_edit_at_end_of_line() { | |
| 660 | + #[gpui::test] | |
| 661 | + fn test_edit_at_end_of_line(cx: &mut gpui::TestAppContext) { | |
| 661 | 662 | let old_text = "aaaa\nbbbb\ncccc"; |
| 662 | 663 | let char_ops = vec![ |
| 663 | 664 | CharOperation::Keep { bytes: 4 }, |
| 664 | 665 | CharOperation::Insert { text: "A".into() }, |
| 665 | 666 | CharOperation::Keep { bytes: 10 }, |
| 666 | 667 | ]; |
| 667 | − let line_ops = char_ops_to_line_ops(old_text, &char_ops); | |
| 668 | + let line_ops = char_ops_to_line_ops(old_text, &char_ops, cx.background_executor()); | |
| 668 | 669 | assert_eq!( |
| 669 | 670 | line_ops, |
| 670 | 671 | vec![ |
| @@ -680,8 +681,8 @@ mod tests { · 9 unmodified lines | ||
| 680 | 681 | ); |
| 681 | 682 | } |
| 682 | 683 | |
| 683 | − #[test] | |
| 684 | − fn test_insert_newline_character() { | |
| 684 | + #[gpui::test] | |
| 685 | + fn test_insert_newline_character(cx: &mut gpui::TestAppContext) { | |
| 685 | 686 | let old_text = "aaaabbbb"; |
| 686 | 687 | let char_ops = vec![ |
| 687 | 688 | CharOperation::Keep { bytes: 4 }, |
| @@ -689,7 +690,7 @@ mod tests { · 1 unmodified line | ||
| 689 | 690 | CharOperation::Keep { bytes: 4 }, |
| 690 | 691 | ]; |
| 691 | 692 | let new_text = apply_char_operations(old_text, &char_ops); |
| 692 | − let line_ops = char_ops_to_line_ops(old_text, &char_ops); | |
| 693 | + let line_ops = char_ops_to_line_ops(old_text, &char_ops, cx.background_executor()); | |
| 693 | 694 | assert_eq!( |
| 694 | 695 | line_ops, |
| 695 | 696 | vec![ |
| @@ -703,14 +704,14 @@ mod tests { · 7 unmodified lines | ||
| 703 | 704 | ); |
| 704 | 705 | } |
| 705 | 706 | |
| 706 | − #[test] | |
| 707 | − fn test_insert_newline_at_beginning() { | |
| 707 | + #[gpui::test] | |
| 708 | + fn test_insert_newline_at_beginning(cx: &mut gpui::TestAppContext) { | |
| 708 | 709 | let old_text = "aaaa\nbbbb"; |
| 709 | 710 | let char_ops = vec![ |
| 710 | 711 | CharOperation::Insert { text: "\n".into() }, |
| 711 | 712 | CharOperation::Keep { bytes: 9 }, |
| 712 | 713 | ]; |
| 713 | − let line_ops = char_ops_to_line_ops(old_text, &char_ops); | |
| 714 | + let line_ops = char_ops_to_line_ops(old_text, &char_ops, cx.background_executor()); | |
| 714 | 715 | assert_eq!( |
| 715 | 716 | line_ops, |
| 716 | 717 | vec![ |
| @@ -725,15 +726,15 @@ mod tests { · 8 unmodified lines | ||
| 725 | 726 | ); |
| 726 | 727 | } |
| 727 | 728 | |
| 728 | − #[test] | |
| 729 | − fn test_delete_newline() { | |
| 729 | + #[gpui::test] | |
| 730 | + fn test_delete_newline(cx: &mut gpui::TestAppContext) { | |
| 730 | 731 | let old_text = "aaaa\nbbbb"; |
| 731 | 732 | let char_ops = vec![ |
| 732 | 733 | CharOperation::Keep { bytes: 4 }, |
| 733 | 734 | CharOperation::Delete { bytes: 1 }, |
| 734 | 735 | CharOperation::Keep { bytes: 4 }, |
| 735 | 736 | ]; |
| 736 | − let line_ops = char_ops_to_line_ops(old_text, &char_ops); | |
| 737 | + let line_ops = char_ops_to_line_ops(old_text, &char_ops, cx.background_executor()); | |
| 737 | 738 | assert_eq!( |
| 738 | 739 | line_ops, |
| 739 | 740 | vec![ |
| @@ -749,8 +750,8 @@ mod tests { · 9 unmodified lines | ||
| 749 | 750 | ); |
| 750 | 751 | } |
| 751 | 752 | |
| 752 | − #[test] | |
| 753 | − fn test_insert_multiple_newlines() { | |
| 753 | + #[gpui::test] | |
| 754 | + fn test_insert_multiple_newlines(cx: &mut gpui::TestAppContext) { | |
| 754 | 755 | let old_text = "aaaa\nbbbb"; |
| 755 | 756 | let char_ops = vec![ |
| 756 | 757 | CharOperation::Keep { bytes: 5 }, |
| @@ -759,7 +760,7 @@ mod tests { · 2 unmodified lines | ||
| 759 | 760 | }, |
| 760 | 761 | CharOperation::Keep { bytes: 4 }, |
| 761 | 762 | ]; |
| 762 | − let line_ops = char_ops_to_line_ops(old_text, &char_ops); | |
| 763 | + let line_ops = char_ops_to_line_ops(old_text, &char_ops, cx.background_executor()); | |
| 763 | 764 | assert_eq!( |
| 764 | 765 | line_ops, |
| 765 | 766 | vec![ |
| @@ -775,15 +776,15 @@ mod tests { · 9 unmodified lines | ||
| 775 | 776 | ); |
| 776 | 777 | } |
| 777 | 778 | |
| 778 | − #[test] | |
| 779 | − fn test_delete_multiple_newlines() { | |
| 779 | + #[gpui::test] | |
| 780 | + fn test_delete_multiple_newlines(cx: &mut gpui::TestAppContext) { | |
| 780 | 781 | let old_text = "aaaa\n\n\nbbbb"; |
| 781 | 782 | let char_ops = vec![ |
| 782 | 783 | CharOperation::Keep { bytes: 5 }, |
| 783 | 784 | CharOperation::Delete { bytes: 2 }, |
| 784 | 785 | CharOperation::Keep { bytes: 4 }, |
| 785 | 786 | ]; |
| 786 | − let line_ops = char_ops_to_line_ops(old_text, &char_ops); | |
| 787 | + let line_ops = char_ops_to_line_ops(old_text, &char_ops, cx.background_executor()); | |
| 787 | 788 | assert_eq!( |
| 788 | 789 | line_ops, |
| 789 | 790 | vec![ |
| @@ -799,8 +800,8 @@ mod tests { · 9 unmodified lines | ||
| 799 | 800 | ); |
| 800 | 801 | } |
| 801 | 802 | |
| 802 | − #[test] | |
| 803 | − fn test_complex_scenario() { | |
| 803 | + #[gpui::test] | |
| 804 | + fn test_complex_scenario(cx: &mut gpui::TestAppContext) { | |
| 804 | 805 | let old_text = "line1\nline2\nline3\nline4"; |
| 805 | 806 | let char_ops = vec![ |
| 806 | 807 | CharOperation::Keep { bytes: 6 }, |
| @@ -814,7 +815,7 @@ mod tests { · 7 unmodified lines | ||
| 814 | 815 | }, |
| 815 | 816 | CharOperation::Keep { bytes: 6 }, |
| 816 | 817 | ]; |
| 817 | − let line_ops = char_ops_to_line_ops(old_text, &char_ops); | |
| 818 | + let line_ops = char_ops_to_line_ops(old_text, &char_ops, cx.background_executor()); | |
| 818 | 819 | assert_eq!( |
| 819 | 820 | line_ops, |
| 820 | 821 | vec![ |
| @@ -834,8 +835,8 @@ mod tests { · 13 unmodified lines | ||
| 834 | 835 | ); |
| 835 | 836 | } |
| 836 | 837 | |
| 837 | − #[test] | |
| 838 | − fn test_cleaning_up_common_suffix() { | |
| 838 | + #[gpui::test] | |
| 839 | + fn test_cleaning_up_common_suffix(cx: &mut gpui::TestAppContext) { | |
| 839 | 840 | let old_text = concat!( |
| 840 | 841 | " for y in 0..size.y() {\n", |
| 841 | 842 | " let a = 10;\n", |
| @@ -883,7 +884,7 @@ mod tests { · 41 unmodified lines | ||
| 883 | 884 | }, |
| 884 | 885 | CharOperation::Keep { bytes: 1 }, |
| 885 | 886 | ]; |
| 886 | − let line_ops = char_ops_to_line_ops(old_text, &char_ops); | |
| 887 | + let line_ops = char_ops_to_line_ops(old_text, &char_ops, cx.background_executor()); | |
| 887 | 888 | assert_eq!( |
| 888 | 889 | line_ops, |
| 889 | 890 | vec![ |
| @@ -901,8 +902,8 @@ mod tests { · 11 unmodified lines | ||
| 901 | 902 | ); |
| 902 | 903 | } |
| 903 | 904 | |
| 904 | − #[test] | |
| 905 | − fn test_random_diffs() { | |
| 905 | + #[gpui::test] | |
| 906 | + fn test_random_diffs(cx: &mut gpui::TestAppContext) { | |
| 906 | 907 | random_test(|mut rng| { |
| 907 | 908 | let old_text_len = env::var("OLD_TEXT_LEN") |
| 908 | 909 | .map(|i| i.parse().expect("invalid `OLD_TEXT_LEN` variable")) |
| @@ -922,15 +923,19 @@ mod tests { · 13 unmodified lines | ||
| 922 | 923 | assert_eq!(patched, new); |
| 923 | 924 | |
| 924 | 925 | // Test char_ops_to_line_ops |
| 925 | − let line_ops = char_ops_to_line_ops(&old, &char_operations); | |
| 926 | + let line_ops = char_ops_to_line_ops(&old, &char_operations, cx.background_executor()); | |
| 926 | 927 | println!("line operations: {:?}", line_ops); |
| 927 | 928 | let patched = apply_line_operations(&old, &new, &line_ops); |
| 928 | 929 | assert_eq!(patched, new); |
| 929 | 930 | }); |
| 930 | 931 | } |
| 931 | 932 | |
| 932 | − fn char_ops_to_line_ops(old_text: &str, char_ops: &[CharOperation]) -> Vec<LineOperation> { | |
| 933 | − let old_rope = Rope::from(old_text); | |
| 933 | + fn char_ops_to_line_ops( | |
| 934 | + old_text: &str, | |
| 935 | + char_ops: &[CharOperation], | |
| 936 | + executor: &BackgroundExecutor, | |
| 937 | + ) -> Vec<LineOperation> { | |
| 938 | + let old_rope = Rope::from_str(old_text, executor); | |
| 934 | 939 | let mut diff = LineDiff::default(); |
| 935 | 940 | for op in char_ops { |
| 936 | 941 | diff.push_char_operation(op, &old_rope); |
| @@ -15,10 +15,12 @@ doctest = false · 14 unmodified lines | ||
| 15 | 15 | |
| 16 | 16 | [dependencies] |
| 17 | 17 | arrayvec = "0.7.1" |
| 18 | −rayon.workspace = true | |
| 19 | 18 | log.workspace = true |
| 19 | +futures.workspace = true | |
| 20 | +itertools.workspace = true | |
| 20 | 21 | |
| 21 | 22 | [dev-dependencies] |
| 22 | 23 | ctor.workspace = true |
| 23 | 24 | rand.workspace = true |
| 24 | 25 | zlog.workspace = true |
| 26 | +pollster = "0.4.0" | |
| @@ -3,7 +3,8 @@ mod tree_map; · 2 unmodified lines | ||
| 3 | 3 | |
| 4 | 4 | use arrayvec::ArrayVec; |
| 5 | 5 | pub use cursor::{Cursor, FilterCursor, Iter}; |
| 6 | −use rayon::iter::{IndexedParallelIterator, IntoParallelIterator, ParallelIterator as _}; | |
| 6 | +use futures::{StreamExt, stream}; | |
| 7 | +use itertools::Itertools as _; | |
| 7 | 8 | use std::marker::PhantomData; |
| 8 | 9 | use std::mem; |
| 9 | 10 | use std::{cmp::Ordering, fmt, iter::FromIterator, sync::Arc}; |
| @@ -14,6 +15,18 @@ pub const TREE_BASE: usize = 2; · 4 unmodified lines | ||
| 14 | 15 | #[cfg(not(test))] |
| 15 | 16 | pub const TREE_BASE: usize = 6; |
| 16 | 17 | |
| 18 | +pub trait BackgroundSpawn { | |
| 19 | + type Task<R>: Future<Output = R> + Send + Sync | |
| 20 | + where | |
| 21 | + R: Send + Sync; | |
| 22 | + fn background_spawn<R>( | |
| 23 | + &self, | |
| 24 | + future: impl Future<Output = R> + Send + Sync + 'static, | |
| 25 | + ) -> Self::Task<R> | |
| 26 | + where | |
| 27 | + R: Send + Sync + 'static; | |
| 28 | +} | |
| 29 | + | |
| 17 | 30 | /// An item that can be stored in a [`SumTree`] |
| 18 | 31 | /// |
| 19 | 32 | /// Must be summarized by a type that implements [`Summary`] |
| @@ -298,62 +311,71 @@ impl<T: Item> SumTree<T> { · 278 unmodified lines | ||
| 298 | 311 | } |
| 299 | 312 | } |
| 300 | 313 | |
| 301 | − pub fn from_par_iter<I, Iter>(iter: I, cx: <T::Summary as Summary>::Context<'_>) -> Self | |
| 314 | + pub async fn from_iter_async<I, S>(iter: I, spawn: S) -> Self | |
| 302 | 315 | where |
| 303 | − I: IntoParallelIterator<Iter = Iter>, | |
| 304 | − Iter: IndexedParallelIterator<Item = T>, | |
| 305 | − T: Send + Sync, | |
| 306 | − T::Summary: Send + Sync, | |
| 307 | − for<'a> <T::Summary as Summary>::Context<'a>: Sync, | |
| 316 | + T: 'static + Send + Sync, | |
| 317 | + for<'a> T::Summary: Summary<Context<'a> = ()> + Send + Sync, | |
| 318 | + S: BackgroundSpawn, | |
| 319 | + I: IntoIterator<Item = T>, | |
| 308 | 320 | { |
| 309 | − let mut nodes = iter | |
| 310 | − .into_par_iter() | |
| 311 | − .chunks(2 * TREE_BASE) | |
| 312 | − .map(|items| { | |
| 313 | − let items: ArrayVec<T, { 2 * TREE_BASE }> = items.into_iter().collect(); | |
| 321 | + let mut futures = vec![]; | |
| 322 | + let chunks = iter.into_iter().chunks(2 * TREE_BASE); | |
| 323 | + for chunk in chunks.into_iter() { | |
| 324 | + let items: ArrayVec<T, { 2 * TREE_BASE }> = chunk.into_iter().collect(); | |
| 325 | + futures.push(async move { | |
| 314 | 326 | let item_summaries: ArrayVec<T::Summary, { 2 * TREE_BASE }> = |
| 315 | − items.iter().map(|item| item.summary(cx)).collect(); | |
| 327 | + items.iter().map(|item| item.summary(())).collect(); | |
| 316 | 328 | let mut summary = item_summaries[0].clone(); |
| 317 | 329 | for item_summary in &item_summaries[1..] { |
| 318 | − <T::Summary as Summary>::add_summary(&mut summary, item_summary, cx); | |
| 330 | + <T::Summary as Summary>::add_summary(&mut summary, item_summary, ()); | |
| 319 | 331 | } |
| 320 | 332 | SumTree(Arc::new(Node::Leaf { |
| 321 | 333 | summary, |
| 322 | 334 | items, |
| 323 | 335 | item_summaries, |
| 324 | 336 | })) |
| 325 | − }) | |
| 326 | − .collect::<Vec<_>>(); | |
| 337 | + }); | |
| 338 | + } | |
| 339 | + | |
| 340 | + let mut nodes = futures::stream::iter(futures) | |
| 341 | + .map(|future| spawn.background_spawn(future)) | |
| 342 | + .buffered(4) | |
| 343 | + .collect::<Vec<_>>() | |
| 344 | + .await; | |
| 327 | 345 | |
| 328 | 346 | let mut height = 0; |
| 329 | 347 | while nodes.len() > 1 { |
| 330 | 348 | height += 1; |
| 331 | − nodes = nodes | |
| 332 | − .into_par_iter() | |
| 349 | + let current_nodes = mem::take(&mut nodes); | |
| 350 | + nodes = stream::iter(current_nodes) | |
| 333 | 351 | .chunks(2 * TREE_BASE) |
| 334 | − .map(|child_nodes| { | |
| 335 | − let child_trees: ArrayVec<SumTree<T>, { 2 * TREE_BASE }> = | |
| 336 | − child_nodes.into_iter().collect(); | |
| 337 | − let child_summaries: ArrayVec<T::Summary, { 2 * TREE_BASE }> = child_trees | |
| 338 | − .iter() | |
| 339 | − .map(|child_tree| child_tree.summary().clone()) | |
| 340 | − .collect(); | |
| 341 | − let mut summary = child_summaries[0].clone(); | |
| 342 | − for child_summary in &child_summaries[1..] { | |
| 343 | − <T::Summary as Summary>::add_summary(&mut summary, child_summary, cx); | |
| 344 | − } | |
| 345 | − SumTree(Arc::new(Node::Internal { | |
| 346 | − height, | |
| 347 | − summary, | |
| 348 | − child_summaries, | |
| 349 | − child_trees, | |
| 350 | − })) | |
| 352 | + .map(|chunk| { | |
| 353 | + spawn.background_spawn(async move { | |
| 354 | + let child_trees: ArrayVec<SumTree<T>, { 2 * TREE_BASE }> = | |
| 355 | + chunk.into_iter().collect(); | |
| 356 | + let child_summaries: ArrayVec<T::Summary, { 2 * TREE_BASE }> = child_trees | |
| 357 | + .iter() | |
| 358 | + .map(|child_tree| child_tree.summary().clone()) | |
| 359 | + .collect(); | |
| 360 | + let mut summary = child_summaries[0].clone(); | |
| 361 | + for child_summary in &child_summaries[1..] { | |
| 362 | + <T::Summary as Summary>::add_summary(&mut summary, child_summary, ()); | |
| 363 | + } | |
| 364 | + SumTree(Arc::new(Node::Internal { | |
| 365 | + height, | |
| 366 | + summary, | |
| 367 | + child_summaries, | |
| 368 | + child_trees, | |
| 369 | + })) | |
| 370 | + }) | |
| 351 | 371 | }) |
| 352 | − .collect::<Vec<_>>(); | |
| 372 | + .buffered(4) | |
| 373 | + .collect::<Vec<_>>() | |
| 374 | + .await; | |
| 353 | 375 | } |
| 354 | 376 | |
| 355 | 377 | if nodes.is_empty() { |
| 356 | − Self::new(cx) | |
| 378 | + Self::new(()) | |
| 357 | 379 | } else { |
| 358 | 380 | debug_assert_eq!(nodes.len(), 1); |
| 359 | 381 | nodes.pop().unwrap() |
| @@ -597,15 +619,15 @@ impl<T: Item> SumTree<T> { · 237 unmodified lines | ||
| 597 | 619 | self.append(Self::from_iter(iter, cx), cx); |
| 598 | 620 | } |
| 599 | 621 | |
| 600 | − pub fn par_extend<I, Iter>(&mut self, iter: I, cx: <T::Summary as Summary>::Context<'_>) | |
| 622 | + pub async fn async_extend<S, I>(&mut self, iter: I, spawn: S) | |
| 601 | 623 | where |
| 602 | − I: IntoParallelIterator<Iter = Iter>, | |
| 603 | − Iter: IndexedParallelIterator<Item = T>, | |
| 604 | − T: Send + Sync, | |
| 605 | − T::Summary: Send + Sync, | |
| 606 | − for<'a> <T::Summary as Summary>::Context<'a>: Sync, | |
| 624 | + S: BackgroundSpawn, | |
| 625 | + I: IntoIterator<Item = T> + 'static, | |
| 626 | + T: 'static + Send + Sync, | |
| 627 | + for<'b> T::Summary: Summary<Context<'b> = ()> + Send + Sync, | |
| 607 | 628 | { |
| 608 | − self.append(Self::from_par_iter(iter, cx), cx); | |
| 629 | + let other = Self::from_iter_async(iter, spawn); | |
| 630 | + self.append(other.await, ()); | |
| 609 | 631 | } |
| 610 | 632 | |
| 611 | 633 | pub fn push(&mut self, item: T, cx: <T::Summary as Summary>::Context<'_>) { |
| @@ -1070,6 +1092,23 @@ mod tests { · 458 unmodified lines | ||
| 1070 | 1092 | |
| 1071 | 1093 | #[test] |
| 1072 | 1094 | fn test_random() { |
| 1095 | + struct NoSpawn; | |
| 1096 | + impl BackgroundSpawn for NoSpawn { | |
| 1097 | + type Task<R> | |
| 1098 | + = std::pin::Pin<Box<dyn Future<Output = R> + Sync + Send>> | |
| 1099 | + where | |
| 1100 | + R: Send + Sync; | |
| 1101 | + fn background_spawn<R>( | |
| 1102 | + &self, | |
| 1103 | + future: impl Future<Output = R> + Send + Sync + 'static, | |
| 1104 | + ) -> Self::Task<R> | |
| 1105 | + where | |
| 1106 | + R: Send + Sync + 'static, | |
| 1107 | + { | |
| 1108 | + Box::pin(future) | |
| 1109 | + } | |
| 1110 | + } | |
| 1111 | + | |
| 1073 | 1112 | let mut starting_seed = 0; |
| 1074 | 1113 | if let Ok(value) = std::env::var("SEED") { |
| 1075 | 1114 | starting_seed = value.parse().expect("invalid SEED variable"); |
| @@ -1095,7 +1134,7 @@ mod tests { · 19 unmodified lines | ||
| 1095 | 1134 | .sample_iter(StandardUniform) |
| 1096 | 1135 | .take(count) |
| 1097 | 1136 | .collect::<Vec<_>>(); |
| 1098 | − tree.par_extend(items, ()); | |
| 1137 | + pollster::block_on(tree.async_extend(items, NoSpawn)); | |
| 1099 | 1138 | } |
| 1100 | 1139 | |
| 1101 | 1140 | for _ in 0..num_operations { |
| @@ -1117,7 +1156,7 @@ mod tests { · 15 unmodified lines | ||
| 1117 | 1156 | if rng.random() { |
| 1118 | 1157 | new_tree.extend(new_items, ()); |
| 1119 | 1158 | } else { |
| 1120 | − new_tree.par_extend(new_items, ()); | |
| 1159 | + pollster::block_on(new_tree.async_extend(new_items, NoSpawn)); | |
| 1121 | 1160 | } |
| 1122 | 1161 | cursor.seek(&Count(splice_end), Bias::Right); |
| 1123 | 1162 | new_tree.append(cursor.slice(&tree_end, Bias::Right), ()); |
| @@ -28,6 +28,7 @@ rope.workspace = true · 27 unmodified lines | ||
| 28 | 28 | smallvec.workspace = true |
| 29 | 29 | sum_tree.workspace = true |
| 30 | 30 | util.workspace = true |
| 31 | +gpui.workspace = true | |
| 31 | 32 | |
| 32 | 33 | [dev-dependencies] |
| 33 | 34 | collections = { workspace = true, features = ["test-support"] } |
| @@ -14,24 +14,29 @@ fn init_logger() { · 13 unmodified lines | ||
| 14 | 14 | zlog::init_test(); |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | −#[test] | |
| 18 | −fn test_edit() { | |
| 19 | − let mut buffer = Buffer::new(ReplicaId::LOCAL, BufferId::new(1).unwrap(), "abc"); | |
| 17 | +#[gpui::test] | |
| 18 | +fn test_edit(cx: &mut gpui::TestAppContext) { | |
| 19 | + let mut buffer = Buffer::new( | |
| 20 | + ReplicaId::LOCAL, | |
| 21 | + BufferId::new(1).unwrap(), | |
| 22 | + "abc", | |
| 23 | + cx.background_executor(), | |
| 24 | + ); | |
| 20 | 25 | assert_eq!(buffer.text(), "abc"); |
| 21 | − buffer.edit([(3..3, "def")]); | |
| 26 | + buffer.edit([(3..3, "def")], cx.background_executor()); | |
| 22 | 27 | assert_eq!(buffer.text(), "abcdef"); |
| 23 | − buffer.edit([(0..0, "ghi")]); | |
| 28 | + buffer.edit([(0..0, "ghi")], cx.background_executor()); | |
| 24 | 29 | assert_eq!(buffer.text(), "ghiabcdef"); |
| 25 | − buffer.edit([(5..5, "jkl")]); | |
| 30 | + buffer.edit([(5..5, "jkl")], cx.background_executor()); | |
| 26 | 31 | assert_eq!(buffer.text(), "ghiabjklcdef"); |
| 27 | − buffer.edit([(6..7, "")]); | |
| 32 | + buffer.edit([(6..7, "")], cx.background_executor()); | |
| 28 | 33 | assert_eq!(buffer.text(), "ghiabjlcdef"); |
| 29 | − buffer.edit([(4..9, "mno")]); | |
| 34 | + buffer.edit([(4..9, "mno")], cx.background_executor()); | |
| 30 | 35 | assert_eq!(buffer.text(), "ghiamnoef"); |
| 31 | 36 | } |
| 32 | 37 | |
| 33 | 38 | #[gpui::test(iterations = 100)] |
| 34 | −fn test_random_edits(mut rng: StdRng) { | |
| 39 | +fn test_random_edits(cx: &mut gpui::TestAppContext, mut rng: StdRng) { | |
| 35 | 40 | let operations = env::var("OPERATIONS") |
| 36 | 41 | .map(|i| i.parse().expect("invalid `OPERATIONS` variable")) |
| 37 | 42 | .unwrap_or(10); |
| @@ -44,6 +49,7 @@ fn test_random_edits(mut rng: StdRng) { · 6 unmodified lines | ||
| 44 | 49 | ReplicaId::LOCAL, |
| 45 | 50 | BufferId::new(1).unwrap(), |
| 46 | 51 | reference_string.clone(), |
| 52 | + cx.background_executor(), | |
| 47 | 53 | ); |
| 48 | 54 | LineEnding::normalize(&mut reference_string); |
| 49 | 55 | |
| @@ -56,7 +62,7 @@ fn test_random_edits(mut rng: StdRng) { · 6 unmodified lines | ||
| 56 | 62 | ); |
| 57 | 63 | |
| 58 | 64 | for _i in 0..operations { |
| 59 | − let (edits, _) = buffer.randomly_edit(&mut rng, 5); | |
| 65 | + let (edits, _) = buffer.randomly_edit(&mut rng, 5, cx.background_executor()); | |
| 60 | 66 | for (old_range, new_text) in edits.iter().rev() { |
| 61 | 67 | reference_string.replace_range(old_range.clone(), new_text); |
| 62 | 68 | } |
| @@ -106,7 +112,11 @@ fn test_random_edits(mut rng: StdRng) { · 43 unmodified lines | ||
| 106 | 112 | let mut text = old_buffer.visible_text.clone(); |
| 107 | 113 | for edit in edits { |
| 108 | 114 | let new_text: String = buffer.text_for_range(edit.new.clone()).collect(); |
| 109 | − text.replace(edit.new.start..edit.new.start + edit.old.len(), &new_text); | |
| 115 | + text.replace( | |
| 116 | + edit.new.start..edit.new.start + edit.old.len(), | |
| 117 | + &new_text, | |
| 118 | + cx.background_executor(), | |
| 119 | + ); | |
| 110 | 120 | } |
| 111 | 121 | assert_eq!(text.to_string(), buffer.text()); |
| 112 | 122 | |
| @@ -161,14 +171,18 @@ fn test_random_edits(mut rng: StdRng) { · 48 unmodified lines | ||
| 161 | 171 | let mut text = old_buffer.visible_text.clone(); |
| 162 | 172 | for edit in subscription_edits.into_inner() { |
| 163 | 173 | let new_text: String = buffer.text_for_range(edit.new.clone()).collect(); |
| 164 | − text.replace(edit.new.start..edit.new.start + edit.old.len(), &new_text); | |
| 174 | + text.replace( | |
| 175 | + edit.new.start..edit.new.start + edit.old.len(), | |
| 176 | + &new_text, | |
| 177 | + cx.background_executor(), | |
| 178 | + ); | |
| 165 | 179 | } |
| 166 | 180 | assert_eq!(text.to_string(), buffer.text()); |
| 167 | 181 | } |
| 168 | 182 | } |
| 169 | 183 | |
| 170 | −#[test] | |
| 171 | −fn test_line_endings() { | |
| 184 | +#[gpui::test] | |
| 185 | +fn test_line_endings(cx: &mut gpui::TestAppContext) { | |
| 172 | 186 | assert_eq!(LineEnding::detect(&"🍐✅\n".repeat(1000)), LineEnding::Unix); |
| 173 | 187 | assert_eq!(LineEnding::detect(&"abcd\n".repeat(1000)), LineEnding::Unix); |
| 174 | 188 | assert_eq!( |
| @@ -184,25 +198,34 @@ fn test_line_endings() { · 9 unmodified lines | ||
| 184 | 198 | ReplicaId::LOCAL, |
| 185 | 199 | BufferId::new(1).unwrap(), |
| 186 | 200 | "one\r\ntwo\rthree", |
| 201 | + cx.background_executor(), | |
| 187 | 202 | ); |
| 188 | 203 | assert_eq!(buffer.text(), "one\ntwo\nthree"); |
| 189 | 204 | assert_eq!(buffer.line_ending(), LineEnding::Windows); |
| 190 | 205 | buffer.check_invariants(); |
| 191 | 206 | |
| 192 | − buffer.edit([(buffer.len()..buffer.len(), "\r\nfour")]); | |
| 193 | − buffer.edit([(0..0, "zero\r\n")]); | |
| 207 | + buffer.edit( | |
| 208 | + [(buffer.len()..buffer.len(), "\r\nfour")], | |
| 209 | + cx.background_executor(), | |
| 210 | + ); | |
| 211 | + buffer.edit([(0..0, "zero\r\n")], cx.background_executor()); | |
| 194 | 212 | assert_eq!(buffer.text(), "zero\none\ntwo\nthree\nfour"); |
| 195 | 213 | assert_eq!(buffer.line_ending(), LineEnding::Windows); |
| 196 | 214 | buffer.check_invariants(); |
| 197 | 215 | } |
| 198 | 216 | |
| 199 | −#[test] | |
| 200 | −fn test_line_len() { | |
| 201 | − let mut buffer = Buffer::new(ReplicaId::LOCAL, BufferId::new(1).unwrap(), ""); | |
| 202 | − buffer.edit([(0..0, "abcd\nefg\nhij")]); | |
| 203 | − buffer.edit([(12..12, "kl\nmno")]); | |
| 204 | − buffer.edit([(18..18, "\npqrs\n")]); | |
| 205 | − buffer.edit([(18..21, "\nPQ")]); | |
| 217 | +#[gpui::test] | |
| 218 | +fn test_line_len(cx: &mut gpui::TestAppContext) { | |
| 219 | + let mut buffer = Buffer::new( | |
| 220 | + ReplicaId::LOCAL, | |
| 221 | + BufferId::new(1).unwrap(), | |
| 222 | + "", | |
| 223 | + cx.background_executor(), | |
| 224 | + ); | |
| 225 | + buffer.edit([(0..0, "abcd\nefg\nhij")], cx.background_executor()); | |
| 226 | + buffer.edit([(12..12, "kl\nmno")], cx.background_executor()); | |
| 227 | + buffer.edit([(18..18, "\npqrs\n")], cx.background_executor()); | |
| 228 | + buffer.edit([(18..21, "\nPQ")], cx.background_executor()); | |
| 206 | 229 | |
| 207 | 230 | assert_eq!(buffer.line_len(0), 4); |
| 208 | 231 | assert_eq!(buffer.line_len(1), 3); |
| @@ -212,10 +235,15 @@ fn test_line_len() { · 3 unmodified lines | ||
| 212 | 235 | assert_eq!(buffer.line_len(5), 0); |
| 213 | 236 | } |
| 214 | 237 | |
| 215 | −#[test] | |
| 216 | −fn test_common_prefix_at_position() { | |
| 238 | +#[gpui::test] | |
| 239 | +fn test_common_prefix_at_position(cx: &mut gpui::TestAppContext) { | |
| 217 | 240 | let text = "a = str; b = δα"; |
| 218 | − let buffer = Buffer::new(ReplicaId::LOCAL, BufferId::new(1).unwrap(), text); | |
| 241 | + let buffer = Buffer::new( | |
| 242 | + ReplicaId::LOCAL, | |
| 243 | + BufferId::new(1).unwrap(), | |
| 244 | + text, | |
| 245 | + cx.background_executor(), | |
| 246 | + ); | |
| 219 | 247 | |
| 220 | 248 | let offset1 = offset_after(text, "str"); |
| 221 | 249 | let offset2 = offset_after(text, "δα"); |
| @@ -261,12 +289,13 @@ fn test_common_prefix_at_position() { · 39 unmodified lines | ||
| 261 | 289 | } |
| 262 | 290 | } |
| 263 | 291 | |
| 264 | −#[test] | |
| 265 | −fn test_text_summary_for_range() { | |
| 292 | +#[gpui::test] | |
| 293 | +fn test_text_summary_for_range(cx: &mut gpui::TestAppContext) { | |
| 266 | 294 | let buffer = Buffer::new( |
| 267 | 295 | ReplicaId::LOCAL, |
| 268 | 296 | BufferId::new(1).unwrap(), |
| 269 | 297 | "ab\nefg\nhklm\nnopqrs\ntuvwxyz", |
| 298 | + cx.background_executor(), | |
| 270 | 299 | ); |
| 271 | 300 | assert_eq!( |
| 272 | 301 | buffer.text_summary_for_range::<TextSummary, _>(0..2), |
| @@ -354,13 +383,18 @@ fn test_text_summary_for_range() { · 81 unmodified lines | ||
| 354 | 383 | ); |
| 355 | 384 | } |
| 356 | 385 | |
| 357 | −#[test] | |
| 358 | −fn test_chars_at() { | |
| 359 | − let mut buffer = Buffer::new(ReplicaId::LOCAL, BufferId::new(1).unwrap(), ""); | |
| 360 | − buffer.edit([(0..0, "abcd\nefgh\nij")]); | |
| 361 | − buffer.edit([(12..12, "kl\nmno")]); | |
| 362 | − buffer.edit([(18..18, "\npqrs")]); | |
| 363 | − buffer.edit([(18..21, "\nPQ")]); | |
| 386 | +#[gpui::test] | |
| 387 | +fn test_chars_at(cx: &mut gpui::TestAppContext) { | |
| 388 | + let mut buffer = Buffer::new( | |
| 389 | + ReplicaId::LOCAL, | |
| 390 | + BufferId::new(1).unwrap(), | |
| 391 | + "", | |
| 392 | + cx.background_executor(), | |
| 393 | + ); | |
| 394 | + buffer.edit([(0..0, "abcd\nefgh\nij")], cx.background_executor()); | |
| 395 | + buffer.edit([(12..12, "kl\nmno")], cx.background_executor()); | |
| 396 | + buffer.edit([(18..18, "\npqrs")], cx.background_executor()); | |
| 397 | + buffer.edit([(18..21, "\nPQ")], cx.background_executor()); | |
| 364 | 398 | |
| 365 | 399 | let chars = buffer.chars_at(Point::new(0, 0)); |
| 366 | 400 | assert_eq!(chars.collect::<String>(), "abcd\nefgh\nijkl\nmno\nPQrs"); |
| @@ -378,43 +412,53 @@ fn test_chars_at() { · 11 unmodified lines | ||
| 378 | 412 | assert_eq!(chars.collect::<String>(), "PQrs"); |
| 379 | 413 | |
| 380 | 414 | // Regression test: |
| 381 | − let mut buffer = Buffer::new(ReplicaId::LOCAL, BufferId::new(1).unwrap(), ""); | |
| 382 | − buffer.edit([(0..0, "[workspace]\nmembers = [\n \"xray_core\",\n \"xray_server\",\n \"xray_cli\",\n \"xray_wasm\",\n]\n")]); | |
| 383 | − buffer.edit([(60..60, "\n")]); | |
| 415 | + let mut buffer = Buffer::new( | |
| 416 | + ReplicaId::LOCAL, | |
| 417 | + BufferId::new(1).unwrap(), | |
| 418 | + "", | |
| 419 | + cx.background_executor(), | |
| 420 | + ); | |
| 421 | + buffer.edit([(0..0, "[workspace]\nmembers = [\n \"xray_core\",\n \"xray_server\",\n \"xray_cli\",\n \"xray_wasm\",\n]\n")], cx.background_executor()); | |
| 422 | + buffer.edit([(60..60, "\n")], cx.background_executor()); | |
| 384 | 423 | |
| 385 | 424 | let chars = buffer.chars_at(Point::new(6, 0)); |
| 386 | 425 | assert_eq!(chars.collect::<String>(), " \"xray_wasm\",\n]\n"); |
| 387 | 426 | } |
| 388 | 427 | |
| 389 | −#[test] | |
| 390 | −fn test_anchors() { | |
| 391 | − let mut buffer = Buffer::new(ReplicaId::LOCAL, BufferId::new(1).unwrap(), ""); | |
| 392 | − buffer.edit([(0..0, "abc")]); | |
| 428 | +#[gpui::test] | |
| 429 | +fn test_anchors(cx: &mut gpui::TestAppContext) { | |
| 430 | + let mut buffer = Buffer::new( | |
| 431 | + ReplicaId::LOCAL, | |
| 432 | + BufferId::new(1).unwrap(), | |
| 433 | + "", | |
| 434 | + cx.background_executor(), | |
| 435 | + ); | |
| 436 | + buffer.edit([(0..0, "abc")], cx.background_executor()); | |
| 393 | 437 | let left_anchor = buffer.anchor_before(2); |
| 394 | 438 | let right_anchor = buffer.anchor_after(2); |
| 395 | 439 | |
| 396 | − buffer.edit([(1..1, "def\n")]); | |
| 440 | + buffer.edit([(1..1, "def\n")], cx.background_executor()); | |
| 397 | 441 | assert_eq!(buffer.text(), "adef\nbc"); |
| 398 | 442 | assert_eq!(left_anchor.to_offset(&buffer), 6); |
| 399 | 443 | assert_eq!(right_anchor.to_offset(&buffer), 6); |
| 400 | 444 | assert_eq!(left_anchor.to_point(&buffer), Point { row: 1, column: 1 }); |
| 401 | 445 | assert_eq!(right_anchor.to_point(&buffer), Point { row: 1, column: 1 }); |
| 402 | 446 | |
| 403 | − buffer.edit([(2..3, "")]); | |
| 447 | + buffer.edit([(2..3, "")], cx.background_executor()); | |
| 404 | 448 | assert_eq!(buffer.text(), "adf\nbc"); |
| 405 | 449 | assert_eq!(left_anchor.to_offset(&buffer), 5); |
| 406 | 450 | assert_eq!(right_anchor.to_offset(&buffer), 5); |
| 407 | 451 | assert_eq!(left_anchor.to_point(&buffer), Point { row: 1, column: 1 }); |
| 408 | 452 | assert_eq!(right_anchor.to_point(&buffer), Point { row: 1, column: 1 }); |
| 409 | 453 | |
| 410 | − buffer.edit([(5..5, "ghi\n")]); | |
| 454 | + buffer.edit([(5..5, "ghi\n")], cx.background_executor()); | |
| 411 | 455 | assert_eq!(buffer.text(), "adf\nbghi\nc"); |
| 412 | 456 | assert_eq!(left_anchor.to_offset(&buffer), 5); |
| 413 | 457 | assert_eq!(right_anchor.to_offset(&buffer), 9); |
| 414 | 458 | assert_eq!(left_anchor.to_point(&buffer), Point { row: 1, column: 1 }); |
| 415 | 459 | assert_eq!(right_anchor.to_point(&buffer), Point { row: 2, column: 0 }); |
| 416 | 460 | |
| 417 | − buffer.edit([(7..9, "")]); | |
| 461 | + buffer.edit([(7..9, "")], cx.background_executor()); | |
| 418 | 462 | assert_eq!(buffer.text(), "adf\nbghc"); |
| 419 | 463 | assert_eq!(left_anchor.to_offset(&buffer), 5); |
| 420 | 464 | assert_eq!(right_anchor.to_offset(&buffer), 7); |
| @@ -504,13 +548,18 @@ fn test_anchors() { · 83 unmodified lines | ||
| 504 | 548 | ); |
| 505 | 549 | } |
| 506 | 550 | |
| 507 | −#[test] | |
| 508 | −fn test_anchors_at_start_and_end() { | |
| 509 | − let mut buffer = Buffer::new(ReplicaId::LOCAL, BufferId::new(1).unwrap(), ""); | |
| 551 | +#[gpui::test] | |
| 552 | +fn test_anchors_at_start_and_end(cx: &mut gpui::TestAppContext) { | |
| 553 | + let mut buffer = Buffer::new( | |
| 554 | + ReplicaId::LOCAL, | |
| 555 | + BufferId::new(1).unwrap(), | |
| 556 | + "", | |
| 557 | + cx.background_executor(), | |
| 558 | + ); | |
| 510 | 559 | let before_start_anchor = buffer.anchor_before(0); |
| 511 | 560 | let after_end_anchor = buffer.anchor_after(0); |
| 512 | 561 | |
| 513 | − buffer.edit([(0..0, "abc")]); | |
| 562 | + buffer.edit([(0..0, "abc")], cx.background_executor()); | |
| 514 | 563 | assert_eq!(buffer.text(), "abc"); |
| 515 | 564 | assert_eq!(before_start_anchor.to_offset(&buffer), 0); |
| 516 | 565 | assert_eq!(after_end_anchor.to_offset(&buffer), 3); |
| @@ -518,8 +567,8 @@ fn test_anchors_at_start_and_end() { · 1 unmodified line | ||
| 518 | 567 | let after_start_anchor = buffer.anchor_after(0); |
| 519 | 568 | let before_end_anchor = buffer.anchor_before(3); |
| 520 | 569 | |
| 521 | − buffer.edit([(3..3, "def")]); | |
| 522 | − buffer.edit([(0..0, "ghi")]); | |
| 570 | + buffer.edit([(3..3, "def")], cx.background_executor()); | |
| 571 | + buffer.edit([(0..0, "ghi")], cx.background_executor()); | |
| 523 | 572 | assert_eq!(buffer.text(), "ghiabcdef"); |
| 524 | 573 | assert_eq!(before_start_anchor.to_offset(&buffer), 0); |
| 525 | 574 | assert_eq!(after_start_anchor.to_offset(&buffer), 3); |
| @@ -527,15 +576,20 @@ fn test_anchors_at_start_and_end() { · 1 unmodified line | ||
| 527 | 576 | assert_eq!(after_end_anchor.to_offset(&buffer), 9); |
| 528 | 577 | } |
| 529 | 578 | |
| 530 | −#[test] | |
| 531 | −fn test_undo_redo() { | |
| 532 | − let mut buffer = Buffer::new(ReplicaId::LOCAL, BufferId::new(1).unwrap(), "1234"); | |
| 579 | +#[gpui::test] | |
| 580 | +fn test_undo_redo(cx: &mut gpui::TestAppContext) { | |
| 581 | + let mut buffer = Buffer::new( | |
| 582 | + ReplicaId::LOCAL, | |
| 583 | + BufferId::new(1).unwrap(), | |
| 584 | + "1234", | |
| 585 | + cx.background_executor(), | |
| 586 | + ); | |
| 533 | 587 | // Set group interval to zero so as to not group edits in the undo stack. |
| 534 | 588 | buffer.set_group_interval(Duration::from_secs(0)); |
| 535 | 589 | |
| 536 | − buffer.edit([(1..1, "abx")]); | |
| 537 | − buffer.edit([(3..4, "yzef")]); | |
| 538 | − buffer.edit([(3..5, "cd")]); | |
| 590 | + buffer.edit([(1..1, "abx")], cx.background_executor()); | |
| 591 | + buffer.edit([(3..4, "yzef")], cx.background_executor()); | |
| 592 | + buffer.edit([(3..5, "cd")], cx.background_executor()); | |
| 539 | 593 | assert_eq!(buffer.text(), "1abcdef234"); |
| 540 | 594 | |
| 541 | 595 | let entries = buffer.history.undo_stack.clone(); |
| @@ -563,26 +617,31 @@ fn test_undo_redo() { · 21 unmodified lines | ||
| 563 | 617 | assert_eq!(buffer.text(), "1234"); |
| 564 | 618 | } |
| 565 | 619 | |
| 566 | −#[test] | |
| 567 | −fn test_history() { | |
| 620 | +#[gpui::test] | |
| 621 | +fn test_history(cx: &mut gpui::TestAppContext) { | |
| 568 | 622 | let mut now = Instant::now(); |
| 569 | − let mut buffer = Buffer::new(ReplicaId::LOCAL, BufferId::new(1).unwrap(), "123456"); | |
| 623 | + let mut buffer = Buffer::new( | |
| 624 | + ReplicaId::LOCAL, | |
| 625 | + BufferId::new(1).unwrap(), | |
| 626 | + "123456", | |
| 627 | + cx.background_executor(), | |
| 628 | + ); | |
| 570 | 629 | buffer.set_group_interval(Duration::from_millis(300)); |
| 571 | 630 | |
| 572 | 631 | let transaction_1 = buffer.start_transaction_at(now).unwrap(); |
| 573 | − buffer.edit([(2..4, "cd")]); | |
| 632 | + buffer.edit([(2..4, "cd")], cx.background_executor()); | |
| 574 | 633 | buffer.end_transaction_at(now); |
| 575 | 634 | assert_eq!(buffer.text(), "12cd56"); |
| 576 | 635 | |
| 577 | 636 | buffer.start_transaction_at(now); |
| 578 | − buffer.edit([(4..5, "e")]); | |
| 637 | + buffer.edit([(4..5, "e")], cx.background_executor()); | |
| 579 | 638 | buffer.end_transaction_at(now).unwrap(); |
| 580 | 639 | assert_eq!(buffer.text(), "12cde6"); |
| 581 | 640 | |
| 582 | 641 | now += buffer.transaction_group_interval() + Duration::from_millis(1); |
| 583 | 642 | buffer.start_transaction_at(now); |
| 584 | − buffer.edit([(0..1, "a")]); | |
| 585 | − buffer.edit([(1..1, "b")]); | |
| 643 | + buffer.edit([(0..1, "a")], cx.background_executor()); | |
| 644 | + buffer.edit([(1..1, "b")], cx.background_executor()); | |
| 586 | 645 | buffer.end_transaction_at(now).unwrap(); |
| 587 | 646 | assert_eq!(buffer.text(), "ab2cde6"); |
| 588 | 647 | |
| @@ -609,7 +668,7 @@ fn test_history() { · 20 unmodified lines | ||
| 609 | 668 | |
| 610 | 669 | // Redo stack gets cleared after performing an edit. |
| 611 | 670 | buffer.start_transaction_at(now); |
| 612 | − buffer.edit([(0..0, "X")]); | |
| 671 | + buffer.edit([(0..0, "X")], cx.background_executor()); | |
| 613 | 672 | buffer.end_transaction_at(now); |
| 614 | 673 | assert_eq!(buffer.text(), "X12cde6"); |
| 615 | 674 | buffer.redo(); |
| @@ -630,26 +689,31 @@ fn test_history() { · 14 unmodified lines | ||
| 630 | 689 | assert_eq!(buffer.text(), "X12cde6"); |
| 631 | 690 | } |
| 632 | 691 | |
| 633 | −#[test] | |
| 634 | −fn test_finalize_last_transaction() { | |
| 692 | +#[gpui::test] | |
| 693 | +fn test_finalize_last_transaction(cx: &mut gpui::TestAppContext) { | |
| 635 | 694 | let now = Instant::now(); |
| 636 | − let mut buffer = Buffer::new(ReplicaId::LOCAL, BufferId::new(1).unwrap(), "123456"); | |
| 695 | + let mut buffer = Buffer::new( | |
| 696 | + ReplicaId::LOCAL, | |
| 697 | + BufferId::new(1).unwrap(), | |
| 698 | + "123456", | |
| 699 | + cx.background_executor(), | |
| 700 | + ); | |
| 637 | 701 | buffer.history.group_interval = Duration::from_millis(1); |
| 638 | 702 | |
| 639 | 703 | buffer.start_transaction_at(now); |
| 640 | − buffer.edit([(2..4, "cd")]); | |
| 704 | + buffer.edit([(2..4, "cd")], cx.background_executor()); | |
| 641 | 705 | buffer.end_transaction_at(now); |
| 642 | 706 | assert_eq!(buffer.text(), "12cd56"); |
| 643 | 707 | |
| 644 | 708 | buffer.finalize_last_transaction(); |
| 645 | 709 | buffer.start_transaction_at(now); |
| 646 | − buffer.edit([(4..5, "e")]); | |
| 710 | + buffer.edit([(4..5, "e")], cx.background_executor()); | |
| 647 | 711 | buffer.end_transaction_at(now).unwrap(); |
| 648 | 712 | assert_eq!(buffer.text(), "12cde6"); |
| 649 | 713 | |
| 650 | 714 | buffer.start_transaction_at(now); |
| 651 | − buffer.edit([(0..1, "a")]); | |
| 652 | − buffer.edit([(1..1, "b")]); | |
| 715 | + buffer.edit([(0..1, "a")], cx.background_executor()); | |
| 716 | + buffer.edit([(1..1, "b")], cx.background_executor()); | |
| 653 | 717 | buffer.end_transaction_at(now).unwrap(); |
| 654 | 718 | assert_eq!(buffer.text(), "ab2cde6"); |
| 655 | 719 | |
| @@ -666,14 +730,19 @@ fn test_finalize_last_transaction() { · 10 unmodified lines | ||
| 666 | 730 | assert_eq!(buffer.text(), "ab2cde6"); |
| 667 | 731 | } |
| 668 | 732 | |
| 669 | −#[test] | |
| 670 | −fn test_edited_ranges_for_transaction() { | |
| 733 | +#[gpui::test] | |
| 734 | +fn test_edited_ranges_for_transaction(cx: &mut gpui::TestAppContext) { | |
| 671 | 735 | let now = Instant::now(); |
| 672 | − let mut buffer = Buffer::new(ReplicaId::LOCAL, BufferId::new(1).unwrap(), "1234567"); | |
| 736 | + let mut buffer = Buffer::new( | |
| 737 | + ReplicaId::LOCAL, | |
| 738 | + BufferId::new(1).unwrap(), | |
| 739 | + "1234567", | |
| 740 | + cx.background_executor(), | |
| 741 | + ); | |
| 673 | 742 | |
| 674 | 743 | buffer.start_transaction_at(now); |
| 675 | − buffer.edit([(2..4, "cd")]); | |
| 676 | − buffer.edit([(6..6, "efg")]); | |
| 744 | + buffer.edit([(2..4, "cd")], cx.background_executor()); | |
| 745 | + buffer.edit([(6..6, "efg")], cx.background_executor()); | |
| 677 | 746 | buffer.end_transaction_at(now); |
| 678 | 747 | assert_eq!(buffer.text(), "12cd56efg7"); |
| 679 | 748 | |
| @@ -685,7 +754,7 @@ fn test_edited_ranges_for_transaction() { · 5 unmodified lines | ||
| 685 | 754 | [2..4, 6..9] |
| 686 | 755 | ); |
| 687 | 756 | |
| 688 | − buffer.edit([(5..5, "hijk")]); | |
| 757 | + buffer.edit([(5..5, "hijk")], cx.background_executor()); | |
| 689 | 758 | assert_eq!(buffer.text(), "12cd5hijk6efg7"); |
| 690 | 759 | assert_eq!( |
| 691 | 760 | buffer |
| @@ -694,7 +763,7 @@ fn test_edited_ranges_for_transaction() { · 2 unmodified lines | ||
| 694 | 763 | [2..4, 10..13] |
| 695 | 764 | ); |
| 696 | 765 | |
| 697 | − buffer.edit([(4..4, "l")]); | |
| 766 | + buffer.edit([(4..4, "l")], cx.background_executor()); | |
| 698 | 767 | assert_eq!(buffer.text(), "12cdl5hijk6efg7"); |
| 699 | 768 | assert_eq!( |
| 700 | 769 | buffer |
| @@ -704,27 +773,42 @@ fn test_edited_ranges_for_transaction() { · 3 unmodified lines | ||
| 704 | 773 | ); |
| 705 | 774 | } |
| 706 | 775 | |
| 707 | −#[test] | |
| 708 | −fn test_concurrent_edits() { | |
| 776 | +#[gpui::test] | |
| 777 | +fn test_concurrent_edits(cx: &mut gpui::TestAppContext) { | |
| 709 | 778 | let text = "abcdef"; |
| 710 | 779 | |
| 711 | − let mut buffer1 = Buffer::new(ReplicaId::new(1), BufferId::new(1).unwrap(), text); | |
| 712 | − let mut buffer2 = Buffer::new(ReplicaId::new(2), BufferId::new(1).unwrap(), text); | |
| 713 | − let mut buffer3 = Buffer::new(ReplicaId::new(3), BufferId::new(1).unwrap(), text); | |
| 780 | + let mut buffer1 = Buffer::new( | |
| 781 | + ReplicaId::new(1), | |
| 782 | + BufferId::new(1).unwrap(), | |
| 783 | + text, | |
| 784 | + cx.background_executor(), | |
| 785 | + ); | |
| 786 | + let mut buffer2 = Buffer::new( | |
| 787 | + ReplicaId::new(2), | |
| 788 | + BufferId::new(1).unwrap(), | |
| 789 | + text, | |
| 790 | + cx.background_executor(), | |
| 791 | + ); | |
| 792 | + let mut buffer3 = Buffer::new( | |
| 793 | + ReplicaId::new(3), | |
| 794 | + BufferId::new(1).unwrap(), | |
| 795 | + text, | |
| 796 | + cx.background_executor(), | |
| 797 | + ); | |
| 714 | 798 | |
| 715 | − let buf1_op = buffer1.edit([(1..2, "12")]); | |
| 799 | + let buf1_op = buffer1.edit([(1..2, "12")], cx.background_executor()); | |
| 716 | 800 | assert_eq!(buffer1.text(), "a12cdef"); |
| 717 | − let buf2_op = buffer2.edit([(3..4, "34")]); | |
| 801 | + let buf2_op = buffer2.edit([(3..4, "34")], cx.background_executor()); | |
| 718 | 802 | assert_eq!(buffer2.text(), "abc34ef"); |
| 719 | − let buf3_op = buffer3.edit([(5..6, "56")]); | |
| 803 | + let buf3_op = buffer3.edit([(5..6, "56")], cx.background_executor()); | |
| 720 | 804 | assert_eq!(buffer3.text(), "abcde56"); |
| 721 | 805 | |
| 722 | − buffer1.apply_op(buf2_op.clone()); | |
| 723 | − buffer1.apply_op(buf3_op.clone()); | |
| 724 | − buffer2.apply_op(buf1_op.clone()); | |
| 725 | − buffer2.apply_op(buf3_op); | |
| 726 | − buffer3.apply_op(buf1_op); | |
| 727 | − buffer3.apply_op(buf2_op); | |
| 806 | + buffer1.apply_op(buf2_op.clone(), Some(cx.background_executor())); | |
| 807 | + buffer1.apply_op(buf3_op.clone(), Some(cx.background_executor())); | |
| 808 | + buffer2.apply_op(buf1_op.clone(), Some(cx.background_executor())); | |
| 809 | + buffer2.apply_op(buf3_op, Some(cx.background_executor())); | |
| 810 | + buffer3.apply_op(buf1_op, Some(cx.background_executor())); | |
| 811 | + buffer3.apply_op(buf2_op, Some(cx.background_executor())); | |
| 728 | 812 | |
| 729 | 813 | assert_eq!(buffer1.text(), "a12c34e56"); |
| 730 | 814 | assert_eq!(buffer2.text(), "a12c34e56"); |
| @@ -732,7 +816,7 @@ fn test_concurrent_edits() { · 1 unmodified line | ||
| 732 | 816 | } |
| 733 | 817 | |
| 734 | 818 | #[gpui::test(iterations = 100)] |
| 735 | −fn test_random_concurrent_edits(mut rng: StdRng) { | |
| 819 | +fn test_random_concurrent_edits(mut rng: StdRng, cx: &mut gpui::TestAppContext) { | |
| 736 | 820 | let peers = env::var("PEERS") |
| 737 | 821 | .map(|i| i.parse().expect("invalid `PEERS` variable")) |
| 738 | 822 | .unwrap_or(5); |
| @@ -753,6 +837,7 @@ fn test_random_concurrent_edits(mut rng: StdRng) { · 14 unmodified lines | ||
| 753 | 837 | ReplicaId::new(i as u16), |
| 754 | 838 | BufferId::new(1).unwrap(), |
| 755 | 839 | base_text.clone(), |
| 840 | + cx.background_executor(), | |
| 756 | 841 | ); |
| 757 | 842 | buffer.history.group_interval = Duration::from_millis(rng.random_range(0..=200)); |
| 758 | 843 | buffers.push(buffer); |
| @@ -769,7 +854,9 @@ fn test_random_concurrent_edits(mut rng: StdRng) { · 10 unmodified lines | ||
| 769 | 854 | let buffer = &mut buffers[replica_index]; |
| 770 | 855 | match rng.random_range(0..=100) { |
| 771 | 856 | 0..=50 if mutation_count != 0 => { |
| 772 | − let op = buffer.randomly_edit(&mut rng, 5).1; | |
| 857 | + let op = buffer | |
| 858 | + .randomly_edit(&mut rng, 5, cx.background_executor()) | |
| 859 | + .1; | |
| 773 | 860 | network.broadcast(buffer.replica_id, vec![op]); |
| 774 | 861 | log::info!("buffer {:?} text: {:?}", buffer.replica_id, buffer.text()); |
| 775 | 862 | mutation_count -= 1; |
| @@ -787,7 +874,7 @@ fn test_random_concurrent_edits(mut rng: StdRng) { · 11 unmodified lines | ||
| 787 | 874 | replica_id, |
| 788 | 875 | ops.len() |
| 789 | 876 | ); |
| 790 | − buffer.apply_ops(ops); | |
| 877 | + buffer.apply_ops(ops, Some(cx.background_executor())); | |
| 791 | 878 | } |
| 792 | 879 | } |
| 793 | 880 | _ => {} |
| @@ -15,6 +15,7 @@ use anyhow::{Context as _, Result}; · 14 unmodified lines | ||
| 15 | 15 | use clock::Lamport; |
| 16 | 16 | pub use clock::ReplicaId; |
| 17 | 17 | use collections::{HashMap, HashSet}; |
| 18 | +use gpui::BackgroundExecutor; | |
| 18 | 19 | use locator::Locator; |
| 19 | 20 | use operation_queue::OperationQueue; |
| 20 | 21 | pub use patch::Patch; |
| @@ -709,11 +710,41 @@ impl FromIterator<char> for LineIndent { · 688 unmodified lines | ||
| 709 | 710 | } |
| 710 | 711 | |
| 711 | 712 | impl Buffer { |
| 712 | − pub fn new(replica_id: ReplicaId, remote_id: BufferId, base_text: impl Into<String>) -> Buffer { | |
| 713 | + /// Create a new buffer from a string. | |
| 714 | + pub fn new( | |
| 715 | + replica_id: ReplicaId, | |
| 716 | + remote_id: BufferId, | |
| 717 | + base_text: impl Into<String>, | |
| 718 | + executor: &BackgroundExecutor, | |
| 719 | + ) -> Buffer { | |
| 713 | 720 | let mut base_text = base_text.into(); |
| 714 | 721 | let line_ending = LineEnding::detect(&base_text); |
| 715 | 722 | LineEnding::normalize(&mut base_text); |
| 716 | − Self::new_normalized(replica_id, remote_id, line_ending, Rope::from(&*base_text)) | |
| 723 | + Self::new_normalized( | |
| 724 | + replica_id, | |
| 725 | + remote_id, | |
| 726 | + line_ending, | |
| 727 | + Rope::from_str(&base_text, executor), | |
| 728 | + ) | |
| 729 | + } | |
| 730 | + | |
| 731 | + /// Create a new buffer from a string. | |
| 732 | + /// | |
| 733 | + /// Unlike [`Buffer::new`], this does not construct the backing rope in parallel if it is large enough. | |
| 734 | + pub fn new_slow( | |
| 735 | + replica_id: ReplicaId, | |
| 736 | + remote_id: BufferId, | |
| 737 | + base_text: impl Into<String>, | |
| 738 | + ) -> Buffer { | |
| 739 | + let mut base_text = base_text.into(); | |
| 740 | + let line_ending = LineEnding::detect(&base_text); | |
| 741 | + LineEnding::normalize(&mut base_text); | |
| 742 | + Self::new_normalized( | |
| 743 | + replica_id, | |
| 744 | + remote_id, | |
| 745 | + line_ending, | |
| 746 | + Rope::from_str_small(&base_text), | |
| 747 | + ) | |
| 717 | 748 | } |
| 718 | 749 | |
| 719 | 750 | pub fn new_normalized( |
| @@ -808,7 +839,7 @@ impl Buffer { · 88 unmodified lines | ||
| 808 | 839 | self.history.group_interval |
| 809 | 840 | } |
| 810 | 841 | |
| 811 | − pub fn edit<R, I, S, T>(&mut self, edits: R) -> Operation | |
| 842 | + pub fn edit<R, I, S, T>(&mut self, edits: R, cx: &BackgroundExecutor) -> Operation | |
| 812 | 843 | where |
| 813 | 844 | R: IntoIterator<IntoIter = I>, |
| 814 | 845 | I: ExactSizeIterator<Item = (Range<S>, T)>, |
| @@ -821,7 +852,7 @@ impl Buffer { · 6 unmodified lines | ||
| 821 | 852 | |
| 822 | 853 | self.start_transaction(); |
| 823 | 854 | let timestamp = self.lamport_clock.tick(); |
| 824 | − let operation = Operation::Edit(self.apply_local_edit(edits, timestamp)); | |
| 855 | + let operation = Operation::Edit(self.apply_local_edit(edits, timestamp, cx)); | |
| 825 | 856 | |
| 826 | 857 | self.history.push(operation.clone()); |
| 827 | 858 | self.history.push_undo(operation.timestamp()); |
| @@ -834,6 +865,7 @@ impl Buffer { · 6 unmodified lines | ||
| 834 | 865 | &mut self, |
| 835 | 866 | edits: impl ExactSizeIterator<Item = (Range<S>, T)>, |
| 836 | 867 | timestamp: clock::Lamport, |
| 868 | + executor: &BackgroundExecutor, | |
| 837 | 869 | ) -> EditOperation { |
| 838 | 870 | let mut edits_patch = Patch::default(); |
| 839 | 871 | let mut edit_op = EditOperation { |
| @@ -922,7 +954,7 @@ impl Buffer { · 82 unmodified lines | ||
| 922 | 954 | }); |
| 923 | 955 | insertion_slices.push(InsertionSlice::from_fragment(timestamp, &fragment)); |
| 924 | 956 | new_insertions.push(InsertionFragment::insert_new(&fragment)); |
| 925 | − new_ropes.push_str(new_text.as_ref()); | |
| 957 | + new_ropes.push_str(new_text.as_ref(), executor); | |
| 926 | 958 | new_fragments.push(fragment, &None); |
| 927 | 959 | insertion_offset += new_text.len(); |
| 928 | 960 | } |
| @@ -1001,22 +1033,26 @@ impl Buffer { · 72 unmodified lines | ||
| 1001 | 1033 | self.snapshot.line_ending = line_ending; |
| 1002 | 1034 | } |
| 1003 | 1035 | |
| 1004 | − pub fn apply_ops<I: IntoIterator<Item = Operation>>(&mut self, ops: I) { | |
| 1036 | + pub fn apply_ops<I: IntoIterator<Item = Operation>>( | |
| 1037 | + &mut self, | |
| 1038 | + ops: I, | |
| 1039 | + executor: Option<&BackgroundExecutor>, | |
| 1040 | + ) { | |
| 1005 | 1041 | let mut deferred_ops = Vec::new(); |
| 1006 | 1042 | for op in ops { |
| 1007 | 1043 | self.history.push(op.clone()); |
| 1008 | 1044 | if self.can_apply_op(&op) { |
| 1009 | − self.apply_op(op); | |
| 1045 | + self.apply_op(op, executor); | |
| 1010 | 1046 | } else { |
| 1011 | 1047 | self.deferred_replicas.insert(op.replica_id()); |
| 1012 | 1048 | deferred_ops.push(op); |
| 1013 | 1049 | } |
| 1014 | 1050 | } |
| 1015 | 1051 | self.deferred_ops.insert(deferred_ops); |
| 1016 | − self.flush_deferred_ops(); | |
| 1052 | + self.flush_deferred_ops(executor); | |
| 1017 | 1053 | } |
| 1018 | 1054 | |
| 1019 | − fn apply_op(&mut self, op: Operation) { | |
| 1055 | + fn apply_op(&mut self, op: Operation, executor: Option<&BackgroundExecutor>) { | |
| 1020 | 1056 | match op { |
| 1021 | 1057 | Operation::Edit(edit) => { |
| 1022 | 1058 | if !self.version.observed(edit.timestamp) { |
| @@ -1025,6 +1061,7 @@ impl Buffer { · 2 unmodified lines | ||
| 1025 | 1061 | &edit.ranges, |
| 1026 | 1062 | &edit.new_text, |
| 1027 | 1063 | edit.timestamp, |
| 1064 | + executor, | |
| 1028 | 1065 | ); |
| 1029 | 1066 | self.snapshot.version.observe(edit.timestamp); |
| 1030 | 1067 | self.lamport_clock.observe(edit.timestamp); |
| @@ -1055,6 +1092,7 @@ impl Buffer { · 24 unmodified lines | ||
| 1055 | 1092 | ranges: &[Range<FullOffset>], |
| 1056 | 1093 | new_text: &[Arc<str>], |
| 1057 | 1094 | timestamp: clock::Lamport, |
| 1095 | + executor: Option<&BackgroundExecutor>, | |
| 1058 | 1096 | ) { |
| 1059 | 1097 | if ranges.is_empty() { |
| 1060 | 1098 | return; |
| @@ -1170,7 +1208,10 @@ impl Buffer { · 109 unmodified lines | ||
| 1170 | 1208 | }); |
| 1171 | 1209 | insertion_slices.push(InsertionSlice::from_fragment(timestamp, &fragment)); |
| 1172 | 1210 | new_insertions.push(InsertionFragment::insert_new(&fragment)); |
| 1173 | − new_ropes.push_str(new_text); | |
| 1211 | + match executor { | |
| 1212 | + Some(executor) => new_ropes.push_str(new_text, executor), | |
| 1213 | + None => new_ropes.push_str_small(new_text), | |
| 1214 | + } | |
| 1174 | 1215 | new_fragments.push(fragment, &None); |
| 1175 | 1216 | insertion_offset += new_text.len(); |
| 1176 | 1217 | } |
| @@ -1348,12 +1389,12 @@ impl Buffer { · 171 unmodified lines | ||
| 1348 | 1389 | self.subscriptions.publish_mut(&edits); |
| 1349 | 1390 | } |
| 1350 | 1391 | |
| 1351 | − fn flush_deferred_ops(&mut self) { | |
| 1392 | + fn flush_deferred_ops(&mut self, executor: Option<&BackgroundExecutor>) { | |
| 1352 | 1393 | self.deferred_replicas.clear(); |
| 1353 | 1394 | let mut deferred_ops = Vec::new(); |
| 1354 | 1395 | for op in self.deferred_ops.drain().iter().cloned() { |
| 1355 | 1396 | if self.can_apply_op(&op) { |
| 1356 | − self.apply_op(op); | |
| 1397 | + self.apply_op(op, executor); | |
| 1357 | 1398 | } else { |
| 1358 | 1399 | self.deferred_replicas.insert(op.replica_id()); |
| 1359 | 1400 | deferred_ops.push(op); |
| @@ -1711,9 +1752,9 @@ impl Buffer { · 351 unmodified lines | ||
| 1711 | 1752 | #[cfg(any(test, feature = "test-support"))] |
| 1712 | 1753 | impl Buffer { |
| 1713 | 1754 | #[track_caller] |
| 1714 | − pub fn edit_via_marked_text(&mut self, marked_string: &str) { | |
| 1755 | + pub fn edit_via_marked_text(&mut self, marked_string: &str, cx: &BackgroundExecutor) { | |
| 1715 | 1756 | let edits = self.edits_for_marked_text(marked_string); |
| 1716 | − self.edit(edits); | |
| 1757 | + self.edit(edits, cx); | |
| 1717 | 1758 | } |
| 1718 | 1759 | |
| 1719 | 1760 | #[track_caller] |
| @@ -1850,6 +1891,7 @@ impl Buffer { · 130 unmodified lines | ||
| 1850 | 1891 | &mut self, |
| 1851 | 1892 | rng: &mut T, |
| 1852 | 1893 | edit_count: usize, |
| 1894 | + executor: &BackgroundExecutor, | |
| 1853 | 1895 | ) -> (Vec<(Range<usize>, Arc<str>)>, Operation) |
| 1854 | 1896 | where |
| 1855 | 1897 | T: rand::Rng, |
| @@ -1857,7 +1899,7 @@ impl Buffer { · 1 unmodified line | ||
| 1857 | 1899 | let mut edits = self.get_random_edits(rng, edit_count); |
| 1858 | 1900 | log::info!("mutating buffer {:?} with {:?}", self.replica_id, edits); |
| 1859 | 1901 | |
| 1860 | − let op = self.edit(edits.iter().cloned()); | |
| 1902 | + let op = self.edit(edits.iter().cloned(), executor); | |
| 1861 | 1903 | if let Operation::Edit(edit) = &op { |
| 1862 | 1904 | assert_eq!(edits.len(), edit.new_text.len()); |
| 1863 | 1905 | for (edit, new_text) in edits.iter_mut().zip(&edit.new_text) { |
| @@ -2692,8 +2734,12 @@ impl<'a> RopeBuilder<'a> { · 828 unmodified lines | ||
| 2692 | 2734 | } |
| 2693 | 2735 | } |
| 2694 | 2736 | |
| 2695 | − fn push_str(&mut self, text: &str) { | |
| 2696 | − self.new_visible.push(text); | |
| 2737 | + fn push_str(&mut self, text: &str, cx: &BackgroundExecutor) { | |
| 2738 | + self.new_visible.push(text, cx); | |
| 2739 | + } | |
| 2740 | + | |
| 2741 | + fn push_str_small(&mut self, text: &str) { | |
| 2742 | + self.new_visible.push_small(text); | |
| 2697 | 2743 | } |
| 2698 | 2744 | |
| 2699 | 2745 | fn finish(mut self) -> (Rope, Rope) { |
| @@ -3096,6 +3096,7 @@ mod test { · 3095 unmodified lines | ||
| 3096 | 3096 | use indoc::indoc; |
| 3097 | 3097 | use language::Point; |
| 3098 | 3098 | use multi_buffer::MultiBufferRow; |
| 3099 | + use text::Rope; | |
| 3099 | 3100 | |
| 3100 | 3101 | #[gpui::test] |
| 3101 | 3102 | async fn test_start_end_of_paragraph(cx: &mut gpui::TestAppContext) { |
| @@ -3822,7 +3823,7 @@ mod test { · 720 unmodified lines | ||
| 3822 | 3823 | cx.update_editor(|editor, _window, cx| { |
| 3823 | 3824 | let range = editor.selections.newest_anchor().range(); |
| 3824 | 3825 | let inlay_text = " field: int,\n field2: string\n field3: float"; |
| 3825 | − let inlay = Inlay::edit_prediction(1, range.start, inlay_text); | |
| 3826 | + let inlay = Inlay::edit_prediction(1, range.start, Rope::from_str_small(inlay_text)); | |
| 3826 | 3827 | editor.splice_inlays(&[], vec![inlay], cx); |
| 3827 | 3828 | }); |
| 3828 | 3829 | |
| @@ -3854,7 +3855,7 @@ mod test { · 25 unmodified lines | ||
| 3854 | 3855 | let end_of_line = |
| 3855 | 3856 | snapshot.anchor_after(Point::new(0, snapshot.line_len(MultiBufferRow(0)))); |
| 3856 | 3857 | let inlay_text = " hint"; |
| 3857 | − let inlay = Inlay::edit_prediction(1, end_of_line, inlay_text); | |
| 3858 | + let inlay = Inlay::edit_prediction(1, end_of_line, Rope::from_str_small(inlay_text)); | |
| 3858 | 3859 | editor.splice_inlays(&[], vec![inlay], cx); |
| 3859 | 3860 | }); |
| 3860 | 3861 | cx.simulate_keystrokes("$"); |
| @@ -3893,7 +3894,7 @@ mod test { · 32 unmodified lines | ||
| 3893 | 3894 | // The empty line is at line 3 (0-indexed) |
| 3894 | 3895 | let line_start = snapshot.anchor_after(Point::new(3, 0)); |
| 3895 | 3896 | let inlay_text = ": Vec<u32>"; |
| 3896 | − let inlay = Inlay::edit_prediction(1, line_start, inlay_text); | |
| 3897 | + let inlay = Inlay::edit_prediction(1, line_start, Rope::from_str_small(inlay_text)); | |
| 3897 | 3898 | editor.splice_inlays(&[], vec![inlay], cx); |
| 3898 | 3899 | }); |
| 3899 | 3900 | |
| @@ -3937,7 +3938,8 @@ mod test { · 37 unmodified lines | ||
| 3937 | 3938 | let snapshot = editor.buffer().read(cx).snapshot(cx); |
| 3938 | 3939 | let empty_line_start = snapshot.anchor_after(Point::new(2, 0)); |
| 3939 | 3940 | let inlay_text = ": i32"; |
| 3940 | − let inlay = Inlay::edit_prediction(2, empty_line_start, inlay_text); | |
| 3941 | + let inlay = | |
| 3942 | + Inlay::edit_prediction(2, empty_line_start, Rope::from_str_small(inlay_text)); | |
| 3941 | 3943 | editor.splice_inlays(&[], vec![inlay], cx); |
| 3942 | 3944 | }); |
| 3943 | 3945 | |
| @@ -7580,13 +7580,13 @@ pub fn create_and_open_local_file( · 7579 unmodified lines | ||
| 7580 | 7580 | path: &'static Path, |
| 7581 | 7581 | window: &mut Window, |
| 7582 | 7582 | cx: &mut Context<Workspace>, |
| 7583 | − default_content: impl 'static + Send + FnOnce() -> Rope, | |
| 7583 | + default_content: impl 'static + Send + FnOnce(&mut AsyncApp) -> Rope, | |
| 7584 | 7584 | ) -> Task<Result<Box<dyn ItemHandle>>> { |
| 7585 | 7585 | cx.spawn_in(window, async move |workspace, cx| { |
| 7586 | 7586 | let fs = workspace.read_with(cx, |workspace, _| workspace.app_state().fs.clone())?; |
| 7587 | 7587 | if !fs.is_file(path).await { |
| 7588 | 7588 | fs.create_file(path, Default::default()).await?; |
| 7589 | − fs.save(path, &default_content(), Default::default()) | |
| 7589 | + fs.save(path, &default_content(cx), Default::default()) | |
| 7590 | 7590 | .await?; |
| 7591 | 7591 | } |
| 7592 | 7592 | |
| @@ -20,6 +20,7 @@ use std::{ · 19 unmodified lines | ||
| 20 | 20 | path::{Path, PathBuf}, |
| 21 | 21 | sync::Arc, |
| 22 | 22 | }; |
| 23 | +use text::Rope; | |
| 23 | 24 | use util::{ |
| 24 | 25 | ResultExt, path, |
| 25 | 26 | rel_path::{RelPath, rel_path}, |
| @@ -646,9 +647,13 @@ async fn test_dirs_no_longer_ignored(cx: &mut TestAppContext) { · 620 unmodified lines | ||
| 646 | 647 | |
| 647 | 648 | // Update the gitignore so that node_modules is no longer ignored, |
| 648 | 649 | // but a subdirectory is ignored |
| 649 | − fs.save("/root/.gitignore".as_ref(), &"e".into(), Default::default()) | |
| 650 | − .await | |
| 651 | − .unwrap(); | |
| 650 | + fs.save( | |
| 651 | + "/root/.gitignore".as_ref(), | |
| 652 | + &Rope::from_str("e", cx.background_executor()), | |
| 653 | + Default::default(), | |
| 654 | + ) | |
| 655 | + .await | |
| 656 | + .unwrap(); | |
| 652 | 657 | cx.executor().run_until_parked(); |
| 653 | 658 | |
| 654 | 659 | // All of the directories that are no longer ignored are now loaded. |
| @@ -716,7 +721,7 @@ async fn test_write_file(cx: &mut TestAppContext) { · 61 unmodified lines | ||
| 716 | 721 | .update(cx, |tree, cx| { |
| 717 | 722 | tree.write_file( |
| 718 | 723 | rel_path("tracked-dir/file.txt").into(), |
| 719 | − "hello".into(), | |
| 724 | + Rope::from_str("hello", cx.background_executor()), | |
| 720 | 725 | Default::default(), |
| 721 | 726 | cx, |
| 722 | 727 | ) |
| @@ -727,7 +732,7 @@ async fn test_write_file(cx: &mut TestAppContext) { · 4 unmodified lines | ||
| 727 | 732 | .update(cx, |tree, cx| { |
| 728 | 733 | tree.write_file( |
| 729 | 734 | rel_path("ignored-dir/file.txt").into(), |
| 730 | − "world".into(), | |
| 735 | + Rope::from_str("world", cx.background_executor()), | |
| 731 | 736 | Default::default(), |
| 732 | 737 | cx, |
| 733 | 738 | ) |
| @@ -1465,7 +1470,7 @@ async fn test_random_worktree_operations_during_initial_scan( · 731 unmodified lines | ||
| 1465 | 1470 | let fs = FakeFs::new(cx.background_executor.clone()) as Arc<dyn Fs>; |
| 1466 | 1471 | fs.as_fake().insert_tree(root_dir, json!({})).await; |
| 1467 | 1472 | for _ in 0..initial_entries { |
| 1468 | − randomly_mutate_fs(&fs, root_dir, 1.0, &mut rng).await; | |
| 1473 | + randomly_mutate_fs(&fs, root_dir, 1.0, &mut rng, cx.background_executor()).await; | |
| 1469 | 1474 | } |
| 1470 | 1475 | log::info!("generated initial tree"); |
| 1471 | 1476 | |
| @@ -1555,7 +1560,7 @@ async fn test_random_worktree_changes(cx: &mut TestAppContext, mut rng: StdRng) · 83 unmodified lines | ||
| 1555 | 1560 | let fs = FakeFs::new(cx.background_executor.clone()) as Arc<dyn Fs>; |
| 1556 | 1561 | fs.as_fake().insert_tree(root_dir, json!({})).await; |
| 1557 | 1562 | for _ in 0..initial_entries { |
| 1558 | − randomly_mutate_fs(&fs, root_dir, 1.0, &mut rng).await; | |
| 1563 | + randomly_mutate_fs(&fs, root_dir, 1.0, &mut rng, cx.background_executor()).await; | |
| 1559 | 1564 | } |
| 1560 | 1565 | log::info!("generated initial tree"); |
| 1561 | 1566 | |
| @@ -1598,7 +1603,7 @@ async fn test_random_worktree_changes(cx: &mut TestAppContext, mut rng: StdRng) · 36 unmodified lines | ||
| 1598 | 1603 | .await |
| 1599 | 1604 | .log_err(); |
| 1600 | 1605 | } else { |
| 1601 | − randomly_mutate_fs(&fs, root_dir, 1.0, &mut rng).await; | |
| 1606 | + randomly_mutate_fs(&fs, root_dir, 1.0, &mut rng, cx.background_executor()).await; | |
| 1602 | 1607 | } |
| 1603 | 1608 | |
| 1604 | 1609 | let buffered_event_count = fs.as_fake().buffered_event_count(); |
| @@ -1607,7 +1612,7 @@ async fn test_random_worktree_changes(cx: &mut TestAppContext, mut rng: StdRng) · 2 unmodified lines | ||
| 1607 | 1612 | log::info!("flushing {} events", len); |
| 1608 | 1613 | fs.as_fake().flush_events(len); |
| 1609 | 1614 | } else { |
| 1610 | − randomly_mutate_fs(&fs, root_dir, 0.6, &mut rng).await; | |
| 1615 | + randomly_mutate_fs(&fs, root_dir, 0.6, &mut rng, cx.background_executor()).await; | |
| 1611 | 1616 | mutations_len -= 1; |
| 1612 | 1617 | } |
| 1613 | 1618 | |
| @@ -1759,8 +1764,12 @@ fn randomly_mutate_worktree( · 145 unmodified lines | ||
| 1759 | 1764 | }) |
| 1760 | 1765 | } else { |
| 1761 | 1766 | log::info!("overwriting file {:?} ({})", &entry.path, entry.id.0); |
| 1762 | − let task = | |
| 1763 | − worktree.write_file(entry.path.clone(), "".into(), Default::default(), cx); | |
| 1767 | + let task = worktree.write_file( | |
| 1768 | + entry.path.clone(), | |
| 1769 | + Rope::default(), | |
| 1770 | + Default::default(), | |
| 1771 | + cx, | |
| 1772 | + ); | |
| 1764 | 1773 | cx.background_spawn(async move { |
| 1765 | 1774 | task.await?; |
| 1766 | 1775 | Ok(()) |
| @@ -1775,6 +1784,7 @@ async fn randomly_mutate_fs( · 8 unmodified lines | ||
| 1775 | 1784 | root_path: &Path, |
| 1776 | 1785 | insertion_probability: f64, |
| 1777 | 1786 | rng: &mut impl Rng, |
| 1787 | + executor: &BackgroundExecutor, | |
| 1778 | 1788 | ) { |
| 1779 | 1789 | log::info!("mutating fs"); |
| 1780 | 1790 | let mut files = Vec::new(); |
| @@ -1849,7 +1859,7 @@ async fn randomly_mutate_fs( · 68 unmodified lines | ||
| 1849 | 1859 | ); |
| 1850 | 1860 | fs.save( |
| 1851 | 1861 | &ignore_path, |
| 1852 | − &ignore_contents.as_str().into(), | |
| 1862 | + &Rope::from_str(ignore_contents.as_str(), executor), | |
| 1853 | 1863 | Default::default(), |
| 1854 | 1864 | ) |
| 1855 | 1865 | .await |
| @@ -28,10 +28,10 @@ use git_ui::commit_view::CommitViewToolbar; · 27 unmodified lines | ||
| 28 | 28 | use git_ui::git_panel::GitPanel; |
| 29 | 29 | use git_ui::project_diff::ProjectDiffToolbar; |
| 30 | 30 | use gpui::{ |
| 31 | − Action, App, AppContext as _, Context, DismissEvent, Element, Entity, Focusable, KeyBinding, | |
| 32 | − ParentElement, PathPromptOptions, PromptLevel, ReadGlobal, SharedString, Styled, Task, | |
| 33 | − TitlebarOptions, UpdateGlobal, Window, WindowKind, WindowOptions, actions, image_cache, point, | |
| 34 | − px, retain_all, | |
| 31 | + Action, App, AppContext as _, AsyncApp, Context, DismissEvent, Element, Entity, Focusable, | |
| 32 | + KeyBinding, ParentElement, PathPromptOptions, PromptLevel, ReadGlobal, SharedString, Styled, | |
| 33 | + Task, TitlebarOptions, UpdateGlobal, Window, WindowKind, WindowOptions, actions, image_cache, | |
| 34 | + point, px, retain_all, | |
| 35 | 35 | }; |
| 36 | 36 | use image_viewer::ImageInfo; |
| 37 | 37 | use language::Capability; |
| @@ -201,7 +201,12 @@ pub fn init(cx: &mut App) { · 163 unmodified lines | ||
| 201 | 201 | with_active_or_new_workspace(cx, |_, window, cx| { |
| 202 | 202 | open_settings_file( |
| 203 | 203 | paths::keymap_file(), |
| 204 | − || settings::initial_keymap_content().as_ref().into(), | |
| 204 | + |cx| { | |
| 205 | + Rope::from_str( | |
| 206 | + settings::initial_keymap_content().as_ref(), | |
| 207 | + cx.background_executor(), | |
| 208 | + ) | |
| 209 | + }, | |
| 205 | 210 | window, |
| 206 | 211 | cx, |
| 207 | 212 | ); |
| @@ -211,7 +216,12 @@ pub fn init(cx: &mut App) { · 3 unmodified lines | ||
| 211 | 216 | with_active_or_new_workspace(cx, |_, window, cx| { |
| 212 | 217 | open_settings_file( |
| 213 | 218 | paths::settings_file(), |
| 214 | − || settings::initial_user_settings_content().as_ref().into(), | |
| 219 | + |cx| { | |
| 220 | + Rope::from_str( | |
| 221 | + settings::initial_user_settings_content().as_ref(), | |
| 222 | + cx.background_executor(), | |
| 223 | + ) | |
| 224 | + }, | |
| 215 | 225 | window, |
| 216 | 226 | cx, |
| 217 | 227 | ); |
| @@ -226,7 +236,12 @@ pub fn init(cx: &mut App) { · 8 unmodified lines | ||
| 226 | 236 | with_active_or_new_workspace(cx, |_, window, cx| { |
| 227 | 237 | open_settings_file( |
| 228 | 238 | paths::tasks_file(), |
| 229 | − || settings::initial_tasks_content().as_ref().into(), | |
| 239 | + |cx| { | |
| 240 | + Rope::from_str( | |
| 241 | + settings::initial_tasks_content().as_ref(), | |
| 242 | + cx.background_executor(), | |
| 243 | + ) | |
| 244 | + }, | |
| 230 | 245 | window, |
| 231 | 246 | cx, |
| 232 | 247 | ); |
| @@ -236,7 +251,12 @@ pub fn init(cx: &mut App) { · 3 unmodified lines | ||
| 236 | 251 | with_active_or_new_workspace(cx, |_, window, cx| { |
| 237 | 252 | open_settings_file( |
| 238 | 253 | paths::debug_scenarios_file(), |
| 239 | − || settings::initial_debug_tasks_content().as_ref().into(), | |
| 254 | + |cx| { | |
| 255 | + Rope::from_str( | |
| 256 | + settings::initial_debug_tasks_content().as_ref(), | |
| 257 | + cx.background_executor(), | |
| 258 | + ) | |
| 259 | + }, | |
| 240 | 260 | window, |
| 241 | 261 | cx, |
| 242 | 262 | ); |
| @@ -1939,7 +1959,7 @@ fn open_bundled_file( · 1696 unmodified lines | ||
| 1939 | 1959 | |
| 1940 | 1960 | fn open_settings_file( |
| 1941 | 1961 | abs_path: &'static Path, |
| 1942 | − default_content: impl FnOnce() -> Rope + Send + 'static, | |
| 1962 | + default_content: impl FnOnce(&mut AsyncApp) -> Rope + Send + 'static, | |
| 1943 | 1963 | window: &mut Window, |
| 1944 | 1964 | cx: &mut Context<Workspace>, |
| 1945 | 1965 | ) { |
| @@ -4355,7 +4375,7 @@ mod tests { · 2409 unmodified lines | ||
| 4355 | 4375 | .fs |
| 4356 | 4376 | .save( |
| 4357 | 4377 | "/settings.json".as_ref(), |
| 4358 | − &r#"{"base_keymap": "Atom"}"#.into(), | |
| 4378 | + &Rope::from_str_small(r#"{"base_keymap": "Atom"}"#), | |
| 4359 | 4379 | Default::default(), |
| 4360 | 4380 | ) |
| 4361 | 4381 | .await |
| @@ -4365,7 +4385,7 @@ mod tests { · 3 unmodified lines | ||
| 4365 | 4385 | .fs |
| 4366 | 4386 | .save( |
| 4367 | 4387 | "/keymap.json".as_ref(), |
| 4368 | − &r#"[{"bindings": {"backspace": "test_only::ActionA"}}]"#.into(), | |
| 4388 | + &Rope::from_str_small(r#"[{"bindings": {"backspace": "test_only::ActionA"}}]"#), | |
| 4369 | 4389 | Default::default(), |
| 4370 | 4390 | ) |
| 4371 | 4391 | .await |
| @@ -4413,7 +4433,7 @@ mod tests { · 41 unmodified lines | ||
| 4413 | 4433 | .fs |
| 4414 | 4434 | .save( |
| 4415 | 4435 | "/keymap.json".as_ref(), |
| 4416 | − &r#"[{"bindings": {"backspace": "test_only::ActionB"}}]"#.into(), | |
| 4436 | + &Rope::from_str_small(r#"[{"bindings": {"backspace": "test_only::ActionB"}}]"#), | |
| 4417 | 4437 | Default::default(), |
| 4418 | 4438 | ) |
| 4419 | 4439 | .await |
| @@ -4433,7 +4453,7 @@ mod tests { · 13 unmodified lines | ||
| 4433 | 4453 | .fs |
| 4434 | 4454 | .save( |
| 4435 | 4455 | "/settings.json".as_ref(), |
| 4436 | − &r#"{"base_keymap": "JetBrains"}"#.into(), | |
| 4456 | + &Rope::from_str_small(r#"{"base_keymap": "JetBrains"}"#), | |
| 4437 | 4457 | Default::default(), |
| 4438 | 4458 | ) |
| 4439 | 4459 | .await |
| @@ -4473,7 +4493,7 @@ mod tests { · 33 unmodified lines | ||
| 4473 | 4493 | .fs |
| 4474 | 4494 | .save( |
| 4475 | 4495 | "/settings.json".as_ref(), |
| 4476 | − &r#"{"base_keymap": "Atom"}"#.into(), | |
| 4496 | + &Rope::from_str_small(r#"{"base_keymap": "Atom"}"#), | |
| 4477 | 4497 | Default::default(), |
| 4478 | 4498 | ) |
| 4479 | 4499 | .await |
| @@ -4482,7 +4502,7 @@ mod tests { · 2 unmodified lines | ||
| 4482 | 4502 | .fs |
| 4483 | 4503 | .save( |
| 4484 | 4504 | "/keymap.json".as_ref(), |
| 4485 | − &r#"[{"bindings": {"backspace": "test_only::ActionA"}}]"#.into(), | |
| 4505 | + &Rope::from_str_small(r#"[{"bindings": {"backspace": "test_only::ActionA"}}]"#), | |
| 4486 | 4506 | Default::default(), |
| 4487 | 4507 | ) |
| 4488 | 4508 | .await |
| @@ -4525,7 +4545,7 @@ mod tests { · 36 unmodified lines | ||
| 4525 | 4545 | .fs |
| 4526 | 4546 | .save( |
| 4527 | 4547 | "/keymap.json".as_ref(), |
| 4528 | − &r#"[{"bindings": {"backspace": null}}]"#.into(), | |
| 4548 | + &Rope::from_str_small(r#"[{"bindings": {"backspace": null}}]"#), | |
| 4529 | 4549 | Default::default(), |
| 4530 | 4550 | ) |
| 4531 | 4551 | .await |
| @@ -4545,7 +4565,7 @@ mod tests { · 13 unmodified lines | ||
| 4545 | 4565 | .fs |
| 4546 | 4566 | .save( |
| 4547 | 4567 | "/settings.json".as_ref(), |
| 4548 | − &r#"{"base_keymap": "JetBrains"}"#.into(), | |
| 4568 | + &Rope::from_str_small(r#"{"base_keymap": "JetBrains"}"#), | |
| 4549 | 4569 | Default::default(), |
| 4550 | 4570 | ) |
| 4551 | 4571 | .await |
| @@ -861,7 +861,7 @@ mod tests { · 860 unmodified lines | ||
| 861 | 861 | .fs |
| 862 | 862 | .save( |
| 863 | 863 | Path::new(file1_path), |
| 864 | − &Rope::from("content1"), | |
| 864 | + &Rope::from_str("content1", cx.background_executor()), | |
| 865 | 865 | LineEnding::Unix, |
| 866 | 866 | ) |
| 867 | 867 | .await |
| @@ -875,7 +875,7 @@ mod tests { · 7 unmodified lines | ||
| 875 | 875 | .fs |
| 876 | 876 | .save( |
| 877 | 877 | Path::new(file2_path), |
| 878 | − &Rope::from("content2"), | |
| 878 | + &Rope::from_str("content2", cx.background_executor()), | |
| 879 | 879 | LineEnding::Unix, |
| 880 | 880 | ) |
| 881 | 881 | .await |
| @@ -1836,12 +1836,13 @@ mod tests { · 1835 unmodified lines | ||
| 1836 | 1836 | let fs = project::FakeFs::new(cx.executor()); |
| 1837 | 1837 | let project = Project::test(fs.clone(), [], cx).await; |
| 1838 | 1838 | |
| 1839 | − let buffer = cx.new(|_cx| { | |
| 1839 | + let buffer = cx.new(|cx| { | |
| 1840 | 1840 | Buffer::remote( |
| 1841 | 1841 | language::BufferId::new(1).unwrap(), |
| 1842 | 1842 | ReplicaId::new(1), |
| 1843 | 1843 | language::Capability::ReadWrite, |
| 1844 | 1844 | "fn main() {\n println!(\"Hello\");\n}", |
| 1845 | + cx.background_executor(), | |
| 1845 | 1846 | ) |
| 1846 | 1847 | }); |
| 1847 | 1848 | |