Skip to content

Commit ce0239b

Browse files
committed
Disable remove unnecessary braces diagnotics for self imports
1 parent 0dd2c0d commit ce0239b

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

crates/ide-diagnostics/src/handlers/useless_braces.rs

+22-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use ide_db::{base_db::FileId, source_change::SourceChange};
22
use itertools::Itertools;
3-
use syntax::{ast, AstNode, SyntaxNode, TextRange};
3+
use syntax::{ast, AstNode, SyntaxKind, SyntaxNode, TextRange};
44
use text_edit::TextEdit;
55

66
use crate::{fix, Diagnostic, DiagnosticCode};
@@ -15,6 +15,11 @@ pub(crate) fn useless_braces(
1515
) -> Option<()> {
1616
let use_tree_list = ast::UseTreeList::cast(node.clone())?;
1717
if let Some((single_use_tree,)) = use_tree_list.use_trees().collect_tuple() {
18+
// If there is a `self` inside the bracketed `use`, don't show diagnostic.
19+
if single_use_tree.syntax().first_token().unwrap().kind() == SyntaxKind::SELF_KW {
20+
return Some(());
21+
}
22+
1823
// If there is a comment inside the bracketed `use`,
1924
// assume it is a commented out module path and don't show diagnostic.
2025
if use_tree_list.has_inner_comment() {
@@ -91,6 +96,22 @@ mod a {
9196
pub mod e {}
9297
}
9398
}
99+
"#,
100+
);
101+
check_diagnostics(
102+
r#"
103+
use a::{self};
104+
105+
mod a {
106+
}
107+
"#,
108+
);
109+
check_diagnostics(
110+
r#"
111+
use a::{self as cool_name};
112+
113+
mod a {
114+
}
94115
"#,
95116
);
96117
check_fix(
@@ -121,16 +142,6 @@ use a::{c$0};
121142
r#"
122143
mod a { pub mod c {} }
123144
use a::c;
124-
"#,
125-
);
126-
check_fix(
127-
r#"
128-
mod a {}
129-
use a::{self$0};
130-
"#,
131-
r#"
132-
mod a {}
133-
use a;
134145
"#,
135146
);
136147
check_fix(

0 commit comments

Comments
 (0)