aboutsummaryrefslogtreecommitdiff
path: root/crates/ide
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-10-15 15:48:25 +0100
committerAleksey Kladov <[email protected]>2020-10-15 15:48:25 +0100
commitc8cbd398e4e54059b1594ef934ce96d6fc0c8130 (patch)
tree18086038741564f954619bc7457670d156e17d20 /crates/ide
parentd447a9a381ecf16ea010b9953159ed533d9ba509 (diff)
Prepare for pat_field_shorthand
Diffstat (limited to 'crates/ide')
-rw-r--r--crates/ide/src/diagnostics.rs18
1 files changed, 13 insertions, 5 deletions
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs
index b30cdb6ed..fb2a2fb28 100644
--- a/crates/ide/src/diagnostics.rs
+++ b/crates/ide/src/diagnostics.rs
@@ -15,7 +15,7 @@ use itertools::Itertools;
15use rustc_hash::FxHashSet; 15use rustc_hash::FxHashSet;
16use syntax::{ 16use syntax::{
17 ast::{self, AstNode}, 17 ast::{self, AstNode},
18 SyntaxNode, TextRange, T, 18 match_ast, SyntaxNode, TextRange, T,
19}; 19};
20use text_edit::TextEdit; 20use text_edit::TextEdit;
21 21
@@ -80,7 +80,7 @@ pub(crate) fn diagnostics(
80 80
81 for node in parse.tree().syntax().descendants() { 81 for node in parse.tree().syntax().descendants() {
82 check_unnecessary_braces_in_use_statement(&mut res, file_id, &node); 82 check_unnecessary_braces_in_use_statement(&mut res, file_id, &node);
83 check_struct_shorthand_initialization(&mut res, file_id, &node); 83 check_field_shorthand(&mut res, file_id, &node);
84 } 84 }
85 let res = RefCell::new(res); 85 let res = RefCell::new(res);
86 let sink_builder = DiagnosticSinkBuilder::new() 86 let sink_builder = DiagnosticSinkBuilder::new()
@@ -188,12 +188,20 @@ fn text_edit_for_remove_unnecessary_braces_with_self_in_use_statement(
188 None 188 None
189} 189}
190 190
191fn check_struct_shorthand_initialization( 191fn check_field_shorthand(acc: &mut Vec<Diagnostic>, file_id: FileId, node: &SyntaxNode) {
192 match_ast! {
193 match node {
194 ast::RecordExpr(it) => check_expr_field_shorthand(acc, file_id, it),
195 _ => None
196 }
197 };
198}
199
200fn check_expr_field_shorthand(
192 acc: &mut Vec<Diagnostic>, 201 acc: &mut Vec<Diagnostic>,
193 file_id: FileId, 202 file_id: FileId,
194 node: &SyntaxNode, 203 record_lit: ast::RecordExpr,
195) -> Option<()> { 204) -> Option<()> {
196 let record_lit = ast::RecordExpr::cast(node.clone())?;
197 let record_field_list = record_lit.record_expr_field_list()?; 205 let record_field_list = record_lit.record_expr_field_list()?;
198 for record_field in record_field_list.fields() { 206 for record_field in record_field_list.fields() {
199 if let (Some(name_ref), Some(expr)) = (record_field.name_ref(), record_field.expr()) { 207 if let (Some(name_ref), Some(expr)) = (record_field.name_ref(), record_field.expr()) {