Merge branch 'master' into feature/issue/1856

# Conflicts:
#	crates/ra_assists/src/ast_editor.rs
This commit is contained in:
Alexander Andreev 2019-09-30 12:07:26 +03:00
commit 81efd696cc
53 changed files with 1180 additions and 957 deletions

View file

@ -4,10 +4,10 @@ use std::cell::RefCell;
use hir::diagnostics::{AstDiagnostic, Diagnostic as _, DiagnosticSink};
use itertools::Itertools;
use ra_assists::ast_editor::AstEditor;
use ra_db::SourceDatabase;
use ra_prof::profile;
use ra_syntax::{
algo,
ast::{self, make, AstNode},
Location, SyntaxNode, TextRange, T,
};
@ -58,15 +58,15 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic>
})
})
.on::<hir::diagnostics::MissingFields, _>(|d| {
let node = d.ast(db);
let mut ast_editor = AstEditor::new(node);
let mut field_list = d.ast(db);
for f in d.missed_fields.iter() {
let field = make::record_field(make::name_ref(&f.to_string()), Some(make::expr_unit()));
ast_editor.append_field(&field);
field_list = field_list.append_field(&field);
}
let mut builder = TextEditBuilder::default();
ast_editor.into_text_edit(&mut builder);
algo::diff(&d.ast(db).syntax(), &field_list.syntax()).into_text_edit(&mut builder);
let fix =
SourceChange::source_file_edit_from("fill struct fields", file_id, builder.finish());
res.borrow_mut().push(Diagnostic {

View file

@ -79,7 +79,7 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
node_range: node.syntax().text_range(),
kind: node.syntax().kind(),
detail,
deprecated: node.attrs().filter_map(|x| x.as_named()).any(|x| x == "deprecated"),
deprecated: node.attrs().filter_map(|x| x.simple_name()).any(|x| x == "deprecated"),
})
}

View file

@ -19,7 +19,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
.keyword\.unsafe { color: #DFAF8F; }
.keyword\.control { color: #F0DFAF; font-weight: bold; }
</style>
<pre><code><span class="attribute">#</span><span class="attribute">[</span><span class="attribute">derive</span><span class="attribute">(</span><span class="attribute">Clone</span><span class="attribute">,</span><span class="attribute"> </span><span class="attribute">Debug</span><span class="attribute">)</span><span class="attribute">]</span>
<pre><code><span class="attribute">#</span><span class="attribute">[</span><span class="attribute text">derive</span><span class="attribute">(</span><span class="attribute">Clone</span><span class="attribute">,</span><span class="attribute"> </span><span class="attribute">Debug</span><span class="attribute">)</span><span class="attribute">]</span>
<span class="keyword">struct</span> <span class="type">Foo</span> {
<span class="keyword">pub</span> <span class="field">x</span>: <span class="type">i32</span>,
<span class="keyword">pub</span> <span class="field">y</span>: <span class="type">i32</span>,