From 0b5e39919034d11c36655369f60cf9cc256743d0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 5 Jul 2019 19:40:02 +0300 Subject: use correct file for diagnostics closes #1475 --- crates/ra_ide_api/src/diagnostics.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/diagnostics.rs b/crates/ra_ide_api/src/diagnostics.rs index 9ab455b0e..a46289cba 100644 --- a/crates/ra_ide_api/src/diagnostics.rs +++ b/crates/ra_ide_api/src/diagnostics.rs @@ -1,7 +1,7 @@ use std::cell::RefCell; use hir::{ - diagnostics::{Diagnostic as _, DiagnosticSink}, + diagnostics::{AstDiagnostic, Diagnostic as _, DiagnosticSink}, source_binder, }; use itertools::Itertools; @@ -9,7 +9,7 @@ use ra_assists::ast_editor::{AstBuilder, AstEditor}; use ra_db::SourceDatabase; use ra_prof::profile; use ra_syntax::{ - ast::{self, AstNode, NamedField, NamedFieldList}, + ast::{self, AstNode, NamedField}, Location, SyntaxNode, TextRange, T, }; use ra_text_edit::{TextEdit, TextEditBuilder}; @@ -34,9 +34,7 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec fix: None, })); - let source_file = parse.tree; - - for node in source_file.syntax().descendants() { + for node in parse.tree.syntax().descendants() { check_unnecessary_braces_in_use_statement(&mut res, file_id, node); check_struct_shorthand_initialization(&mut res, file_id, node); } @@ -61,9 +59,8 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec }) }) .on::(|d| { - let syntax_node = d.syntax_node_ptr(); - let node = NamedFieldList::cast(syntax_node.to_node(source_file.syntax())).unwrap(); - let mut ast_editor = AstEditor::new(node); + let node = d.ast(db); + let mut ast_editor = AstEditor::new(&*node); for f in d.missed_fields.iter() { ast_editor.append_field(&AstBuilder::::from_name(f)); } -- cgit v1.2.3