mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
Disable remove unnecessary braces diagnotics for self imports
This commit is contained in:
parent
0dd2c0d8d3
commit
ce0239bd6a
1 changed files with 22 additions and 11 deletions
|
@ -1,6 +1,6 @@
|
||||||
use ide_db::{base_db::FileId, source_change::SourceChange};
|
use ide_db::{base_db::FileId, source_change::SourceChange};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use syntax::{ast, AstNode, SyntaxNode, TextRange};
|
use syntax::{ast, AstNode, SyntaxKind, SyntaxNode, TextRange};
|
||||||
use text_edit::TextEdit;
|
use text_edit::TextEdit;
|
||||||
|
|
||||||
use crate::{fix, Diagnostic, DiagnosticCode};
|
use crate::{fix, Diagnostic, DiagnosticCode};
|
||||||
|
@ -15,6 +15,11 @@ pub(crate) fn useless_braces(
|
||||||
) -> Option<()> {
|
) -> Option<()> {
|
||||||
let use_tree_list = ast::UseTreeList::cast(node.clone())?;
|
let use_tree_list = ast::UseTreeList::cast(node.clone())?;
|
||||||
if let Some((single_use_tree,)) = use_tree_list.use_trees().collect_tuple() {
|
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`,
|
// If there is a comment inside the bracketed `use`,
|
||||||
// assume it is a commented out module path and don't show diagnostic.
|
// assume it is a commented out module path and don't show diagnostic.
|
||||||
if use_tree_list.has_inner_comment() {
|
if use_tree_list.has_inner_comment() {
|
||||||
|
@ -91,6 +96,22 @@ mod a {
|
||||||
pub mod e {}
|
pub mod e {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
check_diagnostics(
|
||||||
|
r#"
|
||||||
|
use a::{self};
|
||||||
|
|
||||||
|
mod a {
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
check_diagnostics(
|
||||||
|
r#"
|
||||||
|
use a::{self as cool_name};
|
||||||
|
|
||||||
|
mod a {
|
||||||
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
check_fix(
|
check_fix(
|
||||||
|
@ -121,16 +142,6 @@ use a::{c$0};
|
||||||
r#"
|
r#"
|
||||||
mod a { pub mod c {} }
|
mod a { pub mod c {} }
|
||||||
use a::c;
|
use a::c;
|
||||||
"#,
|
|
||||||
);
|
|
||||||
check_fix(
|
|
||||||
r#"
|
|
||||||
mod a {}
|
|
||||||
use a::{self$0};
|
|
||||||
"#,
|
|
||||||
r#"
|
|
||||||
mod a {}
|
|
||||||
use a;
|
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
check_fix(
|
check_fix(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue