aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_editor/src/diagnostics.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_editor/src/diagnostics.rs')
-rw-r--r--crates/ra_editor/src/diagnostics.rs32
1 files changed, 11 insertions, 21 deletions
diff --git a/crates/ra_editor/src/diagnostics.rs b/crates/ra_editor/src/diagnostics.rs
index 199b0e502..2b695dfdf 100644
--- a/crates/ra_editor/src/diagnostics.rs
+++ b/crates/ra_editor/src/diagnostics.rs
@@ -1,25 +1,15 @@
1use itertools::Itertools; 1use itertools::Itertools;
2 2
3use ra_syntax::{ 3use ra_syntax::{
4 Location, SourceFile, SyntaxKind, TextRange, SyntaxNode,
4 ast::{self, AstNode}, 5 ast::{self, AstNode},
5 Location,
6 SourceFileNode,
7 SyntaxKind,
8 TextRange,
9};
10use ra_syntax::SyntaxNodeRef;
11use ra_text_edit::{
12 TextEdit,
13 TextEditBuilder,
14};
15 6
16use crate::{
17 Diagnostic,
18 LocalEdit,
19 Severity,
20}; 7};
8use ra_text_edit::{TextEdit, TextEditBuilder};
9
10use crate::{Diagnostic, LocalEdit, Severity};
21 11
22pub fn diagnostics(file: &SourceFileNode) -> Vec<Diagnostic> { 12pub fn diagnostics(file: &SourceFile) -> Vec<Diagnostic> {
23 fn location_to_range(location: Location) -> TextRange { 13 fn location_to_range(location: Location) -> TextRange {
24 match location { 14 match location {
25 Location::Offset(offset) => TextRange::offset_len(offset, 1.into()), 15 Location::Offset(offset) => TextRange::offset_len(offset, 1.into()),
@@ -48,7 +38,7 @@ pub fn diagnostics(file: &SourceFileNode) -> Vec<Diagnostic> {
48 38
49fn check_unnecessary_braces_in_use_statement( 39fn check_unnecessary_braces_in_use_statement(
50 acc: &mut Vec<Diagnostic>, 40 acc: &mut Vec<Diagnostic>,
51 node: SyntaxNodeRef, 41 node: &SyntaxNode,
52) -> Option<()> { 42) -> Option<()> {
53 let use_tree_list = ast::UseTreeList::cast(node)?; 43 let use_tree_list = ast::UseTreeList::cast(node)?;
54 if let Some((single_use_tree,)) = use_tree_list.use_trees().collect_tuple() { 44 if let Some((single_use_tree,)) = use_tree_list.use_trees().collect_tuple() {
@@ -79,7 +69,7 @@ fn check_unnecessary_braces_in_use_statement(
79} 69}
80 70
81fn text_edit_for_remove_unnecessary_braces_with_self_in_use_statement( 71fn text_edit_for_remove_unnecessary_braces_with_self_in_use_statement(
82 single_use_tree: ast::UseTree, 72 single_use_tree: &ast::UseTree,
83) -> Option<TextEdit> { 73) -> Option<TextEdit> {
84 let use_tree_list_node = single_use_tree.syntax().parent()?; 74 let use_tree_list_node = single_use_tree.syntax().parent()?;
85 if single_use_tree 75 if single_use_tree
@@ -102,7 +92,7 @@ fn text_edit_for_remove_unnecessary_braces_with_self_in_use_statement(
102 92
103fn check_struct_shorthand_initialization( 93fn check_struct_shorthand_initialization(
104 acc: &mut Vec<Diagnostic>, 94 acc: &mut Vec<Diagnostic>,
105 node: SyntaxNodeRef, 95 node: &SyntaxNode,
106) -> Option<()> { 96) -> Option<()> {
107 let struct_lit = ast::StructLit::cast(node)?; 97 let struct_lit = ast::StructLit::cast(node)?;
108 let named_field_list = struct_lit.named_field_list()?; 98 let named_field_list = struct_lit.named_field_list()?;
@@ -138,10 +128,10 @@ mod tests {
138 128
139 use super::*; 129 use super::*;
140 130
141 type DiagnosticChecker = fn(&mut Vec<Diagnostic>, SyntaxNodeRef) -> Option<()>; 131 type DiagnosticChecker = fn(&mut Vec<Diagnostic>, &SyntaxNode) -> Option<()>;
142 132
143 fn check_not_applicable(code: &str, func: DiagnosticChecker) { 133 fn check_not_applicable(code: &str, func: DiagnosticChecker) {
144 let file = SourceFileNode::parse(code); 134 let file = SourceFile::parse(code);
145 let mut diagnostics = Vec::new(); 135 let mut diagnostics = Vec::new();
146 for node in file.syntax().descendants() { 136 for node in file.syntax().descendants() {
147 func(&mut diagnostics, node); 137 func(&mut diagnostics, node);
@@ -150,7 +140,7 @@ mod tests {
150 } 140 }
151 141
152 fn check_apply(before: &str, after: &str, func: DiagnosticChecker) { 142 fn check_apply(before: &str, after: &str, func: DiagnosticChecker) {
153 let file = SourceFileNode::parse(before); 143 let file = SourceFile::parse(before);
154 let mut diagnostics = Vec::new(); 144 let mut diagnostics = Vec::new();
155 for node in file.syntax().descendants() { 145 for node in file.syntax().descendants() {
156 func(&mut diagnostics, node); 146 func(&mut diagnostics, node);