aboutsummaryrefslogtreecommitdiff
path: root/crates/ide
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-06-13 20:11:33 +0100
committerAleksey Kladov <[email protected]>2021-06-13 20:11:33 +0100
commitb404b91da68556141ad39fffcef2865f073dd3d1 (patch)
tree85c6549df052ca97ec04a7038c35025b52981f64 /crates/ide
parentff52167c9a8dd6f99a56a35eae8d634d0ddf1286 (diff)
minor: dead code
Diffstat (limited to 'crates/ide')
-rw-r--r--crates/ide/src/diagnostics.rs61
-rw-r--r--crates/ide/src/diagnostics/field_shorthand.rs23
2 files changed, 34 insertions, 50 deletions
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs
index c024e3e1e..253c360bb 100644
--- a/crates/ide/src/diagnostics.rs
+++ b/crates/ide/src/diagnostics.rs
@@ -86,36 +86,14 @@ impl Diagnostic {
86 self 86 self
87 } 87 }
88 88
89 fn error(range: TextRange, message: String) -> Self { 89 fn with_fixes(mut self, fixes: Option<Vec<Assist>>) -> Diagnostic {
90 Self { 90 self.fixes = fixes;
91 message, 91 self
92 range,
93 severity: Severity::Error,
94 fixes: None,
95 unused: false,
96 code: None,
97 experimental: false,
98 }
99 }
100
101 fn hint(range: TextRange, message: String) -> Self {
102 Self {
103 message,
104 range,
105 severity: Severity::WeakWarning,
106 fixes: None,
107 unused: false,
108 code: None,
109 experimental: false,
110 }
111 }
112
113 fn with_fixes(self, fixes: Option<Vec<Assist>>) -> Self {
114 Self { fixes, ..self }
115 } 92 }
116 93
117 fn with_unused(self, unused: bool) -> Self { 94 fn with_unused(mut self, unused: bool) -> Diagnostic {
118 Self { unused, ..self } 95 self.unused = unused;
96 self
119 } 97 }
120} 98}
121 99
@@ -150,11 +128,9 @@ pub(crate) fn diagnostics(
150 128
151 // [#34344] Only take first 128 errors to prevent slowing down editor/ide, the number 128 is chosen arbitrarily. 129 // [#34344] Only take first 128 errors to prevent slowing down editor/ide, the number 128 is chosen arbitrarily.
152 res.extend( 130 res.extend(
153 parse 131 parse.errors().iter().take(128).map(|err| {
154 .errors() 132 Diagnostic::new("syntax-error", format!("Syntax Error: {}", err), err.range())
155 .iter() 133 }),
156 .take(128)
157 .map(|err| Diagnostic::error(err.range(), format!("Syntax Error: {}", err))),
158 ); 134 );
159 135
160 for node in parse.tree().syntax().descendants() { 136 for node in parse.tree().syntax().descendants() {
@@ -244,13 +220,18 @@ fn check_unnecessary_braces_in_use_statement(
244 }); 220 });
245 221
246 acc.push( 222 acc.push(
247 Diagnostic::hint(use_range, "Unnecessary braces in use statement".to_string()) 223 Diagnostic::new(
248 .with_fixes(Some(vec![fix( 224 "unnecessary-braces",
249 "remove_braces", 225 "Unnecessary braces in use statement".to_string(),
250 "Remove unnecessary braces", 226 use_range,
251 SourceChange::from_text_edit(file_id, edit), 227 )
252 use_range, 228 .severity(Severity::WeakWarning)
253 )])), 229 .with_fixes(Some(vec![fix(
230 "remove_braces",
231 "Remove unnecessary braces",
232 SourceChange::from_text_edit(file_id, edit),
233 use_range,
234 )])),
254 ); 235 );
255 } 236 }
256 237
diff --git a/crates/ide/src/diagnostics/field_shorthand.rs b/crates/ide/src/diagnostics/field_shorthand.rs
index e885a398e..c7f4dab8e 100644
--- a/crates/ide/src/diagnostics/field_shorthand.rs
+++ b/crates/ide/src/diagnostics/field_shorthand.rs
@@ -5,7 +5,7 @@ use ide_db::{base_db::FileId, source_change::SourceChange};
5use syntax::{ast, match_ast, AstNode, SyntaxNode}; 5use syntax::{ast, match_ast, AstNode, SyntaxNode};
6use text_edit::TextEdit; 6use text_edit::TextEdit;
7 7
8use crate::{diagnostics::fix, Diagnostic}; 8use crate::{diagnostics::fix, Diagnostic, Severity};
9 9
10pub(super) fn check(acc: &mut Vec<Diagnostic>, file_id: FileId, node: &SyntaxNode) { 10pub(super) fn check(acc: &mut Vec<Diagnostic>, file_id: FileId, node: &SyntaxNode) {
11 match_ast! { 11 match_ast! {
@@ -46,7 +46,8 @@ fn check_expr_field_shorthand(
46 46
47 let field_range = record_field.syntax().text_range(); 47 let field_range = record_field.syntax().text_range();
48 acc.push( 48 acc.push(
49 Diagnostic::hint(field_range, "Shorthand struct initialization".to_string()) 49 Diagnostic::new("use-field-shorthand", "Shorthand struct initialization", field_range)
50 .severity(Severity::WeakWarning)
50 .with_fixes(Some(vec![fix( 51 .with_fixes(Some(vec![fix(
51 "use_expr_field_shorthand", 52 "use_expr_field_shorthand",
52 "Use struct shorthand initialization", 53 "Use struct shorthand initialization",
@@ -85,14 +86,16 @@ fn check_pat_field_shorthand(
85 let edit = edit_builder.finish(); 86 let edit = edit_builder.finish();
86 87
87 let field_range = record_pat_field.syntax().text_range(); 88 let field_range = record_pat_field.syntax().text_range();
88 acc.push(Diagnostic::hint(field_range, "Shorthand struct pattern".to_string()).with_fixes( 89 acc.push(
89 Some(vec![fix( 90 Diagnostic::new("use-field-shorthand", "Shorthand struct pattern", field_range)
90 "use_pat_field_shorthand", 91 .severity(Severity::WeakWarning)
91 "Use struct field shorthand", 92 .with_fixes(Some(vec![fix(
92 SourceChange::from_text_edit(file_id, edit), 93 "use_pat_field_shorthand",
93 field_range, 94 "Use struct field shorthand",
94 )]), 95 SourceChange::from_text_edit(file_id, edit),
95 )); 96 field_range,
97 )])),
98 );
96 } 99 }
97} 100}
98 101