From 6eeec5d75f0757c341440198fde90c3363226307 Mon Sep 17 00:00:00 2001 From: AdnoC Date: Tue, 29 Dec 2020 22:46:34 -0700 Subject: Smarter bracketed use diagnostic --- crates/ide/src/diagnostics.rs | 6 ++++++ crates/syntax/src/ast/node_ext.rs | 8 ++++++++ 2 files changed, 14 insertions(+) (limited to 'crates') diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs index 038273750..53f8bccdc 100644 --- a/crates/ide/src/diagnostics.rs +++ b/crates/ide/src/diagnostics.rs @@ -199,6 +199,12 @@ fn check_unnecessary_braces_in_use_statement( ) -> Option<()> { let use_tree_list = ast::UseTreeList::cast(node.clone())?; if let Some((single_use_tree,)) = use_tree_list.use_trees().collect_tuple() { + // If there is a comment inside the bracketed `use`, + // assume it is a commented out module path and don't show diagnostic. + if use_tree_list.has_inner_comment() { + return Some(()); + } + let use_range = use_tree_list.syntax().text_range(); let edit = text_edit_for_remove_unnecessary_braces_with_self_in_use_statement(&single_use_tree) diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs index c45cb514a..8a8c2319b 100644 --- a/crates/syntax/src/ast/node_ext.rs +++ b/crates/syntax/src/ast/node_ext.rs @@ -193,6 +193,14 @@ impl ast::UseTreeList { .and_then(ast::UseTree::cast) .expect("UseTreeLists are always nested in UseTrees") } + + pub fn has_inner_comment(&self) -> bool { + self.syntax() + .children_with_tokens() + .filter_map(|it| it.into_token()) + .find_map(ast::Comment::cast) + .is_some() + } } impl ast::Impl { -- cgit v1.2.3 From 58c1949a7b49ca6edc8dc4080b0850a346ad8bd3 Mon Sep 17 00:00:00 2001 From: AdnoC Date: Tue, 29 Dec 2020 22:52:47 -0700 Subject: test for new behavior --- crates/ide/src/diagnostics.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'crates') diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs index 53f8bccdc..79d126ff2 100644 --- a/crates/ide/src/diagnostics.rs +++ b/crates/ide/src/diagnostics.rs @@ -636,6 +636,22 @@ pub struct Foo { pub a: i32, pub b: i32 } use a; use a::{c, d::e}; +mod a { + mod c {} + mod d { + mod e {} + } +} +"#, + ); + check_no_diagnostics( + r#" +use a; +use a::{ + c, + // d::e +}; + mod a { mod c {} mod d { -- cgit v1.2.3 From ddbf484acf15efd73b61ac80a941730b507c01de Mon Sep 17 00:00:00 2001 From: AdnoC Date: Tue, 29 Dec 2020 22:56:00 -0700 Subject: indentation --- crates/syntax/src/ast/node_ext.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'crates') diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs index 8a8c2319b..2aa472fb4 100644 --- a/crates/syntax/src/ast/node_ext.rs +++ b/crates/syntax/src/ast/node_ext.rs @@ -197,9 +197,9 @@ impl ast::UseTreeList { pub fn has_inner_comment(&self) -> bool { self.syntax() .children_with_tokens() - .filter_map(|it| it.into_token()) - .find_map(ast::Comment::cast) - .is_some() + .filter_map(|it| it.into_token()) + .find_map(ast::Comment::cast) + .is_some() } } -- cgit v1.2.3