From 76e170c3d0d0784c0e612c5849798c65a2034f29 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 25 May 2020 14:12:53 +0200 Subject: Less rust-analyzer specific onEnter --- crates/ra_ide/src/lib.rs | 3 ++- crates/ra_ide/src/typing/on_enter.rs | 11 +++-------- 2 files changed, 5 insertions(+), 9 deletions(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 5ac002d82..d983cd910 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs @@ -309,7 +309,8 @@ impl Analysis { /// Returns an edit which should be applied when opening a new line, fixing /// up minor stuff like continuing the comment. - pub fn on_enter(&self, position: FilePosition) -> Cancelable> { + /// The edit will be a snippet (with `$0`). + pub fn on_enter(&self, position: FilePosition) -> Cancelable> { self.with_db(|db| typing::on_enter(&db, position)) } diff --git a/crates/ra_ide/src/typing/on_enter.rs b/crates/ra_ide/src/typing/on_enter.rs index e7d64b4f6..a40d8af9c 100644 --- a/crates/ra_ide/src/typing/on_enter.rs +++ b/crates/ra_ide/src/typing/on_enter.rs @@ -11,9 +11,7 @@ use ra_syntax::{ }; use ra_text_edit::TextEdit; -use crate::{SourceChange, SourceFileEdit}; - -pub(crate) fn on_enter(db: &RootDatabase, position: FilePosition) -> Option { +pub(crate) fn on_enter(db: &RootDatabase, position: FilePosition) -> Option { let parse = db.parse(position.file_id); let file = parse.tree(); let comment = file @@ -41,9 +39,7 @@ pub(crate) fn on_enter(db: &RootDatabase, position: FilePosition) -> Option bool { @@ -90,9 +86,8 @@ mod tests { let (analysis, file_id) = single_file(&before); let result = analysis.on_enter(FilePosition { offset, file_id }).unwrap()?; - assert_eq!(result.source_file_edits.len(), 1); let mut actual = before.to_string(); - result.source_file_edits[0].edit.apply(&mut actual); + result.apply(&mut actual); Some(actual) } -- cgit v1.2.3