diff options
| author | AmrDeveloper <amr96@programmer.net> | 2023-07-05 16:34:04 +0200 |
|---|---|---|
| committer | AmrDeveloper <amr96@programmer.net> | 2023-07-05 16:34:04 +0200 |
| commit | ce0239bd6a58ce5326b7480c8bdd8552d111a46f (patch) | |
| tree | 1c5651a56d3352e90f36649e2a92668e28396136 | |
| parent | 0dd2c0d8d3f6aa8ec1079270d65d2ecf1c64ce78 (diff) | |
| download | rust-ce0239bd6a58ce5326b7480c8bdd8552d111a46f.tar.gz rust-ce0239bd6a58ce5326b7480c8bdd8552d111a46f.zip | |
Disable remove unnecessary braces diagnotics for self imports
| -rw-r--r-- | crates/ide-diagnostics/src/handlers/useless_braces.rs | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/crates/ide-diagnostics/src/handlers/useless_braces.rs b/crates/ide-diagnostics/src/handlers/useless_braces.rs index 11ce811efaa..49cdcdb00f0 100644 --- a/crates/ide-diagnostics/src/handlers/useless_braces.rs +++ b/crates/ide-diagnostics/src/handlers/useless_braces.rs @@ -1,6 +1,6 @@ use ide_db::{base_db::FileId, source_change::SourceChange}; use itertools::Itertools; -use syntax::{ast, AstNode, SyntaxNode, TextRange}; +use syntax::{ast, AstNode, SyntaxKind, SyntaxNode, TextRange}; use text_edit::TextEdit; use crate::{fix, Diagnostic, DiagnosticCode}; @@ -15,6 +15,11 @@ pub(crate) fn useless_braces( ) -> 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 `self` inside the bracketed `use`, don't show diagnostic. + if single_use_tree.syntax().first_token().unwrap().kind() == SyntaxKind::SELF_KW { + return Some(()); + } + // 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() { @@ -93,6 +98,22 @@ mod a { } "#, ); + check_diagnostics( + r#" +use a::{self}; + +mod a { +} +"#, + ); + check_diagnostics( + r#" +use a::{self as cool_name}; + +mod a { +} +"#, + ); check_fix( r#" mod b {} @@ -125,16 +146,6 @@ use a::c; ); check_fix( r#" -mod a {} -use a::{self$0}; -"#, - r#" -mod a {} -use a; -"#, - ); - check_fix( - r#" mod a { pub mod c {} pub mod d { pub mod e {} } } use a::{c, d::{e$0}}; "#, |
