test short structs

This commit is contained in:
Aleksey Kladov 2019-04-22 00:52:21 +03:00
parent f313ac45af
commit 97f41d7343
3 changed files with 39 additions and 4 deletions

View File

@ -110,13 +110,20 @@ impl AstEditor<ast::NamedFieldList> {
let position = match position {
InsertPosition::First => after_l_curly!(),
InsertPosition::Last => match self.ast().fields().last() {
Some(it) => after_field!(it),
None => after_l_curly!(),
},
InsertPosition::Last => {
if !is_multiline {
// don't insert comma before curly
to_insert.pop();
}
match self.ast().fields().last() {
Some(it) => after_field!(it),
None => after_l_curly!(),
}
}
InsertPosition::Before(anchor) => InsertPosition::Before(anchor.syntax().into()),
InsertPosition::After(anchor) => after_field!(anchor),
};
self.ast = self.insert_children(position, to_insert.iter().cloned());
}

View File

@ -194,4 +194,31 @@ mod tests {
"#,
);
}
#[test]
fn fill_struct_short() {
check_assist(
fill_struct_fields,
r#"
struct S {
foo: u32,
bar: String,
}
fn main() {
let s = S {<|> };
}
"#,
r#"
struct S {
foo: u32,
bar: String,
}
fn main() {
let s = <|>S { foo: (), bar: () };
}
"#,
);
}
}

View File

@ -24,6 +24,7 @@ use crate::{
pub use rowan::WalkEvent;
pub(crate) use rowan::{GreenNode, GreenToken};
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum InsertPosition<T> {
First,
Last,