minor: dead code

This commit is contained in:
Aleksey Kladov 2021-06-13 22:11:33 +03:00
parent ff52167c9a
commit b404b91da6
2 changed files with 34 additions and 50 deletions

View File

@ -86,36 +86,14 @@ impl Diagnostic {
self
}
fn error(range: TextRange, message: String) -> Self {
Self {
message,
range,
severity: Severity::Error,
fixes: None,
unused: false,
code: None,
experimental: false,
}
fn with_fixes(mut self, fixes: Option<Vec<Assist>>) -> Diagnostic {
self.fixes = fixes;
self
}
fn hint(range: TextRange, message: String) -> Self {
Self {
message,
range,
severity: Severity::WeakWarning,
fixes: None,
unused: false,
code: None,
experimental: false,
}
}
fn with_fixes(self, fixes: Option<Vec<Assist>>) -> Self {
Self { fixes, ..self }
}
fn with_unused(self, unused: bool) -> Self {
Self { unused, ..self }
fn with_unused(mut self, unused: bool) -> Diagnostic {
self.unused = unused;
self
}
}
@ -150,11 +128,9 @@ pub(crate) fn diagnostics(
// [#34344] Only take first 128 errors to prevent slowing down editor/ide, the number 128 is chosen arbitrarily.
res.extend(
parse
.errors()
.iter()
.take(128)
.map(|err| Diagnostic::error(err.range(), format!("Syntax Error: {}", err))),
parse.errors().iter().take(128).map(|err| {
Diagnostic::new("syntax-error", format!("Syntax Error: {}", err), err.range())
}),
);
for node in parse.tree().syntax().descendants() {
@ -244,13 +220,18 @@ fn check_unnecessary_braces_in_use_statement(
});
acc.push(
Diagnostic::hint(use_range, "Unnecessary braces in use statement".to_string())
.with_fixes(Some(vec![fix(
"remove_braces",
"Remove unnecessary braces",
SourceChange::from_text_edit(file_id, edit),
use_range,
)])),
Diagnostic::new(
"unnecessary-braces",
"Unnecessary braces in use statement".to_string(),
use_range,
)
.severity(Severity::WeakWarning)
.with_fixes(Some(vec![fix(
"remove_braces",
"Remove unnecessary braces",
SourceChange::from_text_edit(file_id, edit),
use_range,
)])),
);
}

View File

@ -5,7 +5,7 @@ use ide_db::{base_db::FileId, source_change::SourceChange};
use syntax::{ast, match_ast, AstNode, SyntaxNode};
use text_edit::TextEdit;
use crate::{diagnostics::fix, Diagnostic};
use crate::{diagnostics::fix, Diagnostic, Severity};
pub(super) fn check(acc: &mut Vec<Diagnostic>, file_id: FileId, node: &SyntaxNode) {
match_ast! {
@ -46,7 +46,8 @@ fn check_expr_field_shorthand(
let field_range = record_field.syntax().text_range();
acc.push(
Diagnostic::hint(field_range, "Shorthand struct initialization".to_string())
Diagnostic::new("use-field-shorthand", "Shorthand struct initialization", field_range)
.severity(Severity::WeakWarning)
.with_fixes(Some(vec![fix(
"use_expr_field_shorthand",
"Use struct shorthand initialization",
@ -85,14 +86,16 @@ fn check_pat_field_shorthand(
let edit = edit_builder.finish();
let field_range = record_pat_field.syntax().text_range();
acc.push(Diagnostic::hint(field_range, "Shorthand struct pattern".to_string()).with_fixes(
Some(vec![fix(
"use_pat_field_shorthand",
"Use struct field shorthand",
SourceChange::from_text_edit(file_id, edit),
field_range,
)]),
));
acc.push(
Diagnostic::new("use-field-shorthand", "Shorthand struct pattern", field_range)
.severity(Severity::WeakWarning)
.with_fixes(Some(vec![fix(
"use_pat_field_shorthand",
"Use struct field shorthand",
SourceChange::from_text_edit(file_id, edit),
field_range,
)])),
);
}
}