mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
fix: Add missing fields diagnostic fix for patterns
This commit is contained in:
parent
1da2d82f58
commit
dd3f7664fd
4 changed files with 184 additions and 62 deletions
|
@ -546,6 +546,49 @@ impl ast::RecordExprField {
|
|||
}
|
||||
}
|
||||
|
||||
impl ast::RecordPatFieldList {
|
||||
pub fn add_field(&self, field: ast::RecordPatField) {
|
||||
let is_multiline = self.syntax().text().contains_char('\n');
|
||||
let whitespace = if is_multiline {
|
||||
let indent = IndentLevel::from_node(self.syntax()) + 1;
|
||||
make::tokens::whitespace(&format!("\n{}", indent))
|
||||
} else {
|
||||
make::tokens::single_space()
|
||||
};
|
||||
|
||||
if is_multiline {
|
||||
normalize_ws_between_braces(self.syntax());
|
||||
}
|
||||
|
||||
let position = match self.fields().last() {
|
||||
Some(last_field) => {
|
||||
let comma = match last_field
|
||||
.syntax()
|
||||
.siblings_with_tokens(Direction::Next)
|
||||
.filter_map(|it| it.into_token())
|
||||
.find(|it| it.kind() == T![,])
|
||||
{
|
||||
Some(it) => it,
|
||||
None => {
|
||||
let comma = ast::make::token(T![,]);
|
||||
ted::insert(Position::after(last_field.syntax()), &comma);
|
||||
comma
|
||||
}
|
||||
};
|
||||
Position::after(comma)
|
||||
}
|
||||
None => match self.l_curly_token() {
|
||||
Some(it) => Position::after(it),
|
||||
None => Position::last_child_of(self.syntax()),
|
||||
},
|
||||
};
|
||||
|
||||
ted::insert_all(position, vec![whitespace.into(), field.syntax().clone().into()]);
|
||||
if is_multiline {
|
||||
ted::insert(Position::after(field.syntax()), ast::make::token(T![,]));
|
||||
}
|
||||
}
|
||||
}
|
||||
impl ast::StmtList {
|
||||
pub fn push_front(&self, statement: ast::Stmt) {
|
||||
ted::insert(Position::after(self.l_curly_token().unwrap()), statement.syntax());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue