Simplify buffer constructor methods
Don't expose the `buffer::History` to callers of `language::Buffer`
This commit is contained in:
parent
4069db4959
commit
5bfbeb55c0
5 changed files with 60 additions and 92 deletions
|
@ -78,10 +78,8 @@ async fn test_apply_diff(mut cx: gpui::TestAppContext) {
|
|||
|
||||
#[gpui::test]
|
||||
async fn test_reparse(mut cx: gpui::TestAppContext) {
|
||||
let buffer = cx.add_model(|cx| {
|
||||
let text = "fn a() {}".into();
|
||||
Buffer::from_history(0, History::new(text), None, Some(rust_lang()), None, cx)
|
||||
});
|
||||
let text = "fn a() {}";
|
||||
let buffer = cx.add_model(|cx| Buffer::new(0, text, cx).with_language(rust_lang(), None, cx));
|
||||
|
||||
// Wait for the initial text to parse
|
||||
buffer
|
||||
|
@ -222,9 +220,8 @@ fn test_enclosing_bracket_ranges(cx: &mut MutableAppContext) {
|
|||
}
|
||||
}
|
||||
"
|
||||
.unindent()
|
||||
.into();
|
||||
Buffer::from_history(0, History::new(text), None, Some(rust_lang()), None, cx)
|
||||
.unindent();
|
||||
Buffer::new(0, text, cx).with_language(rust_lang(), None, cx)
|
||||
});
|
||||
let buffer = buffer.read(cx);
|
||||
assert_eq!(
|
||||
|
@ -253,9 +250,8 @@ fn test_enclosing_bracket_ranges(cx: &mut MutableAppContext) {
|
|||
#[gpui::test]
|
||||
fn test_edit_with_autoindent(cx: &mut MutableAppContext) {
|
||||
cx.add_model(|cx| {
|
||||
let text = "fn a() {}".into();
|
||||
let mut buffer =
|
||||
Buffer::from_history(0, History::new(text), None, Some(rust_lang()), None, cx);
|
||||
let text = "fn a() {}";
|
||||
let mut buffer = Buffer::new(0, text, cx).with_language(rust_lang(), None, cx);
|
||||
|
||||
buffer.edit_with_autoindent([8..8], "\n\n", cx);
|
||||
assert_eq!(buffer.text(), "fn a() {\n \n}");
|
||||
|
@ -273,8 +269,9 @@ fn test_edit_with_autoindent(cx: &mut MutableAppContext) {
|
|||
#[gpui::test]
|
||||
fn test_autoindent_moves_selections(cx: &mut MutableAppContext) {
|
||||
cx.add_model(|cx| {
|
||||
let text = History::new("fn a() {}".into());
|
||||
let mut buffer = Buffer::from_history(0, text, None, Some(rust_lang()), None, cx);
|
||||
let text = "fn a() {}";
|
||||
|
||||
let mut buffer = Buffer::new(0, text, cx).with_language(rust_lang(), None, cx);
|
||||
|
||||
let selection_set_id = buffer.add_selection_set(Vec::new(), cx);
|
||||
buffer.start_transaction(Some(selection_set_id)).unwrap();
|
||||
|
@ -331,10 +328,9 @@ fn test_autoindent_does_not_adjust_lines_with_unchanged_suggestion(cx: &mut Muta
|
|||
d;
|
||||
}
|
||||
"
|
||||
.unindent()
|
||||
.into();
|
||||
let mut buffer =
|
||||
Buffer::from_history(0, History::new(text), None, Some(rust_lang()), None, cx);
|
||||
.unindent();
|
||||
|
||||
let mut buffer = Buffer::new(0, text, cx).with_language(rust_lang(), None, cx);
|
||||
|
||||
// Lines 2 and 3 don't match the indentation suggestion. When editing these lines,
|
||||
// their indentation is not adjusted.
|
||||
|
@ -378,14 +374,12 @@ fn test_autoindent_does_not_adjust_lines_with_unchanged_suggestion(cx: &mut Muta
|
|||
#[gpui::test]
|
||||
fn test_autoindent_adjusts_lines_when_only_text_changes(cx: &mut MutableAppContext) {
|
||||
cx.add_model(|cx| {
|
||||
let text = History::new(
|
||||
"
|
||||
fn a() {}
|
||||
"
|
||||
.unindent()
|
||||
.into(),
|
||||
);
|
||||
let mut buffer = Buffer::from_history(0, text, None, Some(rust_lang()), None, cx);
|
||||
let text = "
|
||||
fn a() {}
|
||||
"
|
||||
.unindent();
|
||||
|
||||
let mut buffer = Buffer::new(0, text, cx).with_language(rust_lang(), None, cx);
|
||||
|
||||
buffer.edit_with_autoindent([5..5], "\nb", cx);
|
||||
assert_eq!(
|
||||
|
@ -440,8 +434,8 @@ impl Buffer {
|
|||
}
|
||||
}
|
||||
|
||||
fn rust_lang() -> Arc<Language> {
|
||||
Arc::new(
|
||||
fn rust_lang() -> Option<Arc<Language>> {
|
||||
Some(Arc::new(
|
||||
Language::new(
|
||||
LanguageConfig {
|
||||
name: "Rust".to_string(),
|
||||
|
@ -461,7 +455,7 @@ fn rust_lang() -> Arc<Language> {
|
|||
.unwrap()
|
||||
.with_brackets_query(r#" ("{" @open "}" @close) "#)
|
||||
.unwrap(),
|
||||
)
|
||||
))
|
||||
}
|
||||
|
||||
fn empty(point: Point) -> Range<Point> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue