From ca9e0f5fe9ad29ab0c5a0771a0d0eaec97e4104b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 5 May 2020 23:48:26 +0200 Subject: Fixup tests --- crates/ra_ide/src/typing.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'crates/ra_ide/src/typing.rs') diff --git a/crates/ra_ide/src/typing.rs b/crates/ra_ide/src/typing.rs index 2a8b4327f..a03da4693 100644 --- a/crates/ra_ide/src/typing.rs +++ b/crates/ra_ide/src/typing.rs @@ -142,10 +142,13 @@ mod tests { fn do_type_char(char_typed: char, before: &str) -> Option<(String, SingleFileChange)> { let (offset, before) = extract_offset(before); let edit = TextEdit::insert(offset, char_typed.to_string()); - let before = edit.apply(&before); + let mut before = before.to_string(); + edit.apply(&mut before); let parse = SourceFile::parse(&before); - on_char_typed_inner(&parse.tree(), offset, char_typed) - .map(|it| (it.edit.apply(&before), it)) + on_char_typed_inner(&parse.tree(), offset, char_typed).map(|it| { + it.edit.apply(&mut before); + (before.to_string(), it) + }) } fn type_char(char_typed: char, before: &str, after: &str) { -- cgit v1.2.3 From 3850b1c0860a075f1fd569577c2a2fecd1fc2f0c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 6 May 2020 11:31:26 +0200 Subject: Lift SourceChange to the ra_ide_db --- crates/ra_ide/src/typing.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide/src/typing.rs') diff --git a/crates/ra_ide/src/typing.rs b/crates/ra_ide/src/typing.rs index a03da4693..6f04f0be4 100644 --- a/crates/ra_ide/src/typing.rs +++ b/crates/ra_ide/src/typing.rs @@ -17,15 +17,16 @@ mod on_enter; use ra_db::{FilePosition, SourceDatabase}; use ra_fmt::leading_indent; -use ra_ide_db::RootDatabase; +use ra_ide_db::{source_change::SingleFileChange, RootDatabase}; use ra_syntax::{ algo::find_node_at_offset, ast::{self, AstToken}, AstNode, SourceFile, TextRange, TextSize, }; + use ra_text_edit::TextEdit; -use crate::{source_change::SingleFileChange, SourceChange}; +use crate::SourceChange; pub(crate) use on_enter::on_enter; -- cgit v1.2.3 From 04a8daaa33ad8aa068ccc24011c0844d06ba0ee7 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 21 May 2020 00:46:08 +0200 Subject: Remove unused cursor positions --- crates/ra_ide/src/typing.rs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'crates/ra_ide/src/typing.rs') diff --git a/crates/ra_ide/src/typing.rs b/crates/ra_ide/src/typing.rs index 6f04f0be4..867a0f0bd 100644 --- a/crates/ra_ide/src/typing.rs +++ b/crates/ra_ide/src/typing.rs @@ -111,7 +111,7 @@ fn on_dot_typed(file: &SourceFile, offset: TextSize) -> Option Some(SingleFileChange { label: "reindent dot".to_string(), edit: TextEdit::replace(TextRange::new(offset - current_indent_len, offset), target_indent), - cursor_position: Some(offset + target_indent_len - current_indent_len + TextSize::of('.')), + cursor_position: None, }) } @@ -130,7 +130,7 @@ fn on_arrow_typed(file: &SourceFile, offset: TextSize) -> Option Option<(String, SingleFileChange)> { + fn do_type_char(char_typed: char, before: &str) -> Option { let (offset, before) = extract_offset(before); let edit = TextEdit::insert(offset, char_typed.to_string()); let mut before = before.to_string(); @@ -148,21 +148,15 @@ mod tests { let parse = SourceFile::parse(&before); on_char_typed_inner(&parse.tree(), offset, char_typed).map(|it| { it.edit.apply(&mut before); - (before.to_string(), it) + before.to_string() }) } fn type_char(char_typed: char, before: &str, after: &str) { - let (actual, file_change) = do_type_char(char_typed, before) + let actual = do_type_char(char_typed, before) .unwrap_or_else(|| panic!("typing `{}` did nothing", char_typed)); - if after.contains("<|>") { - let (offset, after) = extract_offset(after); - assert_eq_text!(&after, &actual); - assert_eq!(file_change.cursor_position, Some(offset)) - } else { - assert_eq_text!(after, &actual); - } + assert_eq_text!(after, &actual); } fn type_char_noop(char_typed: char, before: &str) { @@ -350,6 +344,6 @@ fn foo() { #[test] fn adds_space_after_return_type() { - type_char('>', "fn foo() -<|>{ 92 }", "fn foo() -><|> { 92 }") + type_char('>', "fn foo() -<|>{ 92 }", "fn foo() -> { 92 }") } } -- cgit v1.2.3 From 4fdb1eac08bc29029fe888967dcc11d38d25c205 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 21 May 2020 00:46:08 +0200 Subject: Remove unused cursor positions --- crates/ra_ide/src/typing.rs | 3 --- 1 file changed, 3 deletions(-) (limited to 'crates/ra_ide/src/typing.rs') diff --git a/crates/ra_ide/src/typing.rs b/crates/ra_ide/src/typing.rs index 867a0f0bd..cd48cad93 100644 --- a/crates/ra_ide/src/typing.rs +++ b/crates/ra_ide/src/typing.rs @@ -82,7 +82,6 @@ fn on_eq_typed(file: &SourceFile, offset: TextSize) -> Option Some(SingleFileChange { label: "add semicolon".to_string(), edit: TextEdit::insert(offset, ";".to_string()), - cursor_position: None, }) } @@ -111,7 +110,6 @@ fn on_dot_typed(file: &SourceFile, offset: TextSize) -> Option Some(SingleFileChange { label: "reindent dot".to_string(), edit: TextEdit::replace(TextRange::new(offset - current_indent_len, offset), target_indent), - cursor_position: None, }) } @@ -130,7 +128,6 @@ fn on_arrow_typed(file: &SourceFile, offset: TextSize) -> Option