mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-19 11:12:43 +00:00
test short structs
This commit is contained in:
parent
f313ac45af
commit
97f41d7343
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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: () };
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user