aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r--crates/ra_ide_api/src/assists.rs2
-rw-r--r--crates/ra_ide_api/src/call_info.rs2
-rw-r--r--crates/ra_ide_api/src/change.rs2
-rw-r--r--crates/ra_ide_api/src/completion.rs2
-rw-r--r--crates/ra_ide_api/src/completion/complete_dot.rs2
-rw-r--r--crates/ra_ide_api/src/completion/complete_fn_param.rs18
-rw-r--r--crates/ra_ide_api/src/completion/complete_keyword.rs20
-rw-r--r--crates/ra_ide_api/src/completion/complete_macro_in_item_position.rs2
-rw-r--r--crates/ra_ide_api/src/completion/complete_path.rs2
-rw-r--r--crates/ra_ide_api/src/completion/complete_pattern.rs2
-rw-r--r--crates/ra_ide_api/src/completion/complete_postfix.rs2
-rw-r--r--crates/ra_ide_api/src/completion/complete_record_literal.rs2
-rw-r--r--crates/ra_ide_api/src/completion/complete_record_pattern.rs2
-rw-r--r--crates/ra_ide_api/src/completion/complete_scope.rs2
-rw-r--r--crates/ra_ide_api/src/completion/complete_snippet.rs2
-rw-r--r--crates/ra_ide_api/src/completion/completion_context.rs2
-rw-r--r--crates/ra_ide_api/src/completion/completion_item.rs2
-rw-r--r--crates/ra_ide_api/src/completion/presentation.rs1
-rw-r--r--crates/ra_ide_api/src/db.rs2
-rw-r--r--crates/ra_ide_api/src/diagnostics.rs12
-rw-r--r--crates/ra_ide_api/src/display/function_signature.rs2
-rw-r--r--crates/ra_ide_api/src/display/navigation_target.rs61
-rw-r--r--crates/ra_ide_api/src/display/short_label.rs2
-rw-r--r--crates/ra_ide_api/src/display/structure.rs120
-rw-r--r--crates/ra_ide_api/src/extend_selection.rs2
-rw-r--r--crates/ra_ide_api/src/feature_flags.rs2
-rw-r--r--crates/ra_ide_api/src/folding_ranges.rs2
-rw-r--r--crates/ra_ide_api/src/goto_definition.rs187
-rw-r--r--crates/ra_ide_api/src/goto_type_definition.rs2
-rw-r--r--crates/ra_ide_api/src/hover.rs79
-rw-r--r--crates/ra_ide_api/src/impls.rs2
-rw-r--r--crates/ra_ide_api/src/inlay_hints.rs106
-rw-r--r--crates/ra_ide_api/src/join_lines.rs2
-rw-r--r--crates/ra_ide_api/src/lib.rs6
-rw-r--r--crates/ra_ide_api/src/line_index.rs3
-rw-r--r--crates/ra_ide_api/src/line_index_utils.rs2
-rw-r--r--crates/ra_ide_api/src/marks.rs2
-rw-r--r--crates/ra_ide_api/src/matching_brace.rs2
-rw-r--r--crates/ra_ide_api/src/mock_analysis.rs8
-rw-r--r--crates/ra_ide_api/src/name_ref_kind.rs2
-rw-r--r--crates/ra_ide_api/src/parent_module.rs5
-rw-r--r--crates/ra_ide_api/src/references.rs2
-rw-r--r--crates/ra_ide_api/src/runnables.rs3
-rw-r--r--crates/ra_ide_api/src/snapshots/highlighting.html2
-rw-r--r--crates/ra_ide_api/src/status.rs2
-rw-r--r--crates/ra_ide_api/src/symbol_index.rs26
-rw-r--r--crates/ra_ide_api/src/syntax_highlighting.rs2
-rw-r--r--crates/ra_ide_api/src/syntax_tree.rs2
-rw-r--r--crates/ra_ide_api/src/test_utils.rs2
-rw-r--r--crates/ra_ide_api/src/typing.rs2
-rw-r--r--crates/ra_ide_api/src/wasm_shims.rs2
51 files changed, 425 insertions, 302 deletions
diff --git a/crates/ra_ide_api/src/assists.rs b/crates/ra_ide_api/src/assists.rs
index e3d1ac529..e00589733 100644
--- a/crates/ra_ide_api/src/assists.rs
+++ b/crates/ra_ide_api/src/assists.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use ra_db::{FilePosition, FileRange}; 3use ra_db::{FilePosition, FileRange};
2 4
3use crate::{db::RootDatabase, SourceChange, SourceFileEdit}; 5use crate::{db::RootDatabase, SourceChange, SourceFileEdit};
diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs
index d5e116526..7d18be483 100644
--- a/crates/ra_ide_api/src/call_info.rs
+++ b/crates/ra_ide_api/src/call_info.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use ra_db::SourceDatabase; 3use ra_db::SourceDatabase;
2use ra_syntax::{ 4use ra_syntax::{
3 algo::find_node_at_offset, 5 algo::find_node_at_offset,
diff --git a/crates/ra_ide_api/src/change.rs b/crates/ra_ide_api/src/change.rs
index 981851829..09913787b 100644
--- a/crates/ra_ide_api/src/change.rs
+++ b/crates/ra_ide_api/src/change.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use std::{fmt, sync::Arc, time}; 3use std::{fmt, sync::Arc, time};
2 4
3use ra_db::{ 5use ra_db::{
diff --git a/crates/ra_ide_api/src/completion.rs b/crates/ra_ide_api/src/completion.rs
index 0ad414831..abe1f36ce 100644
--- a/crates/ra_ide_api/src/completion.rs
+++ b/crates/ra_ide_api/src/completion.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1mod completion_item; 3mod completion_item;
2mod completion_context; 4mod completion_context;
3mod presentation; 5mod presentation;
diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs
index 9e64c8659..28c8324d0 100644
--- a/crates/ra_ide_api/src/completion/complete_dot.rs
+++ b/crates/ra_ide_api/src/completion/complete_dot.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use hir::{Adt, Ty, TypeCtor}; 3use hir::{Adt, Ty, TypeCtor};
2 4
3use crate::completion::completion_item::CompletionKind; 5use crate::completion::completion_item::CompletionKind;
diff --git a/crates/ra_ide_api/src/completion/complete_fn_param.rs b/crates/ra_ide_api/src/completion/complete_fn_param.rs
index 6639b6fff..3e936e3ec 100644
--- a/crates/ra_ide_api/src/completion/complete_fn_param.rs
+++ b/crates/ra_ide_api/src/completion/complete_fn_param.rs
@@ -1,7 +1,6 @@
1use ra_syntax::{ 1//! FIXME: write short doc here
2 algo::visit::{visitor_ctx, VisitorCtx}, 2
3 ast, AstNode, 3use ra_syntax::{ast, match_ast, AstNode};
4};
5use rustc_hash::FxHashMap; 4use rustc_hash::FxHashMap;
6 5
7use crate::completion::{CompletionContext, CompletionItem, CompletionKind, Completions}; 6use crate::completion::{CompletionContext, CompletionItem, CompletionKind, Completions};
@@ -17,10 +16,13 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
17 16
18 let mut params = FxHashMap::default(); 17 let mut params = FxHashMap::default();
19 for node in ctx.token.parent().ancestors() { 18 for node in ctx.token.parent().ancestors() {
20 let _ = visitor_ctx(&mut params) 19 match_ast! {
21 .visit::<ast::SourceFile, _>(process) 20 match node {
22 .visit::<ast::ItemList, _>(process) 21 ast::SourceFile(it) => { process(it, &mut params) },
23 .accept(&node); 22 ast::ItemList(it) => { process(it, &mut params) },
23 _ => (),
24 }
25 }
24 } 26 }
25 params 27 params
26 .into_iter() 28 .into_iter()
diff --git a/crates/ra_ide_api/src/completion/complete_keyword.rs b/crates/ra_ide_api/src/completion/complete_keyword.rs
index c527a9f63..48c688a08 100644
--- a/crates/ra_ide_api/src/completion/complete_keyword.rs
+++ b/crates/ra_ide_api/src/completion/complete_keyword.rs
@@ -1,7 +1,8 @@
1//! FIXME: write short doc here
2
1use ra_syntax::{ 3use ra_syntax::{
2 algo::visit::{visitor, Visitor},
3 ast::{self, LoopBodyOwner}, 4 ast::{self, LoopBodyOwner},
4 AstNode, 5 match_ast, AstNode,
5 SyntaxKind::*, 6 SyntaxKind::*,
6 SyntaxToken, 7 SyntaxToken,
7}; 8};
@@ -82,12 +83,15 @@ fn is_in_loop_body(leaf: &SyntaxToken) -> bool {
82 if node.kind() == FN_DEF || node.kind() == LAMBDA_EXPR { 83 if node.kind() == FN_DEF || node.kind() == LAMBDA_EXPR {
83 break; 84 break;
84 } 85 }
85 let loop_body = visitor() 86 let loop_body = match_ast! {
86 .visit::<ast::ForExpr, _>(|it| it.loop_body()) 87 match node {
87 .visit::<ast::WhileExpr, _>(|it| it.loop_body()) 88 ast::ForExpr(it) => { it.loop_body() },
88 .visit::<ast::LoopExpr, _>(|it| it.loop_body()) 89 ast::WhileExpr(it) => { it.loop_body() },
89 .accept(&node); 90 ast::LoopExpr(it) => { it.loop_body() },
90 if let Some(Some(body)) = loop_body { 91 _ => None,
92 }
93 };
94 if let Some(body) = loop_body {
91 if leaf.text_range().is_subrange(&body.syntax().text_range()) { 95 if leaf.text_range().is_subrange(&body.syntax().text_range()) {
92 return true; 96 return true;
93 } 97 }
diff --git a/crates/ra_ide_api/src/completion/complete_macro_in_item_position.rs b/crates/ra_ide_api/src/completion/complete_macro_in_item_position.rs
index 0cbe4abf7..d808b2357 100644
--- a/crates/ra_ide_api/src/completion/complete_macro_in_item_position.rs
+++ b/crates/ra_ide_api/src/completion/complete_macro_in_item_position.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use crate::completion::{CompletionContext, Completions}; 3use crate::completion::{CompletionContext, Completions};
2 4
3pub(super) fn complete_macro_in_item_position(acc: &mut Completions, ctx: &CompletionContext) { 5pub(super) fn complete_macro_in_item_position(acc: &mut Completions, ctx: &CompletionContext) {
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs
index e9fec54d8..e01197fe4 100644
--- a/crates/ra_ide_api/src/completion/complete_path.rs
+++ b/crates/ra_ide_api/src/completion/complete_path.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use hir::{Adt, Either, PathResolution}; 3use hir::{Adt, Either, PathResolution};
2use ra_syntax::AstNode; 4use ra_syntax::AstNode;
3use test_utils::tested_by; 5use test_utils::tested_by;
diff --git a/crates/ra_ide_api/src/completion/complete_pattern.rs b/crates/ra_ide_api/src/completion/complete_pattern.rs
index c17b5b7ee..513ad6e5f 100644
--- a/crates/ra_ide_api/src/completion/complete_pattern.rs
+++ b/crates/ra_ide_api/src/completion/complete_pattern.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use crate::completion::{CompletionContext, Completions}; 3use crate::completion::{CompletionContext, Completions};
2 4
3/// Completes constats and paths in patterns. 5/// Completes constats and paths in patterns.
diff --git a/crates/ra_ide_api/src/completion/complete_postfix.rs b/crates/ra_ide_api/src/completion/complete_postfix.rs
index 3970d1af3..445a02676 100644
--- a/crates/ra_ide_api/src/completion/complete_postfix.rs
+++ b/crates/ra_ide_api/src/completion/complete_postfix.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use crate::{ 3use crate::{
2 completion::{ 4 completion::{
3 completion_context::CompletionContext, 5 completion_context::CompletionContext,
diff --git a/crates/ra_ide_api/src/completion/complete_record_literal.rs b/crates/ra_ide_api/src/completion/complete_record_literal.rs
index ed4029964..4406695d5 100644
--- a/crates/ra_ide_api/src/completion/complete_record_literal.rs
+++ b/crates/ra_ide_api/src/completion/complete_record_literal.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use hir::Substs; 3use hir::Substs;
2 4
3use crate::completion::{CompletionContext, Completions}; 5use crate::completion::{CompletionContext, Completions};
diff --git a/crates/ra_ide_api/src/completion/complete_record_pattern.rs b/crates/ra_ide_api/src/completion/complete_record_pattern.rs
index 70716b3d6..d20fa796c 100644
--- a/crates/ra_ide_api/src/completion/complete_record_pattern.rs
+++ b/crates/ra_ide_api/src/completion/complete_record_pattern.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use hir::Substs; 3use hir::Substs;
2 4
3use crate::completion::{CompletionContext, Completions}; 5use crate::completion::{CompletionContext, Completions};
diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs
index cb70a1f21..515a6285c 100644
--- a/crates/ra_ide_api/src/completion/complete_scope.rs
+++ b/crates/ra_ide_api/src/completion/complete_scope.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use ra_assists::auto_import_text_edit; 3use ra_assists::auto_import_text_edit;
2use ra_syntax::{ast, AstNode, SmolStr}; 4use ra_syntax::{ast, AstNode, SmolStr};
3use ra_text_edit::TextEditBuilder; 5use ra_text_edit::TextEditBuilder;
diff --git a/crates/ra_ide_api/src/completion/complete_snippet.rs b/crates/ra_ide_api/src/completion/complete_snippet.rs
index b06221c2a..2df79b6c3 100644
--- a/crates/ra_ide_api/src/completion/complete_snippet.rs
+++ b/crates/ra_ide_api/src/completion/complete_snippet.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use crate::completion::{ 3use crate::completion::{
2 completion_item::Builder, CompletionContext, CompletionItem, CompletionItemKind, 4 completion_item::Builder, CompletionContext, CompletionItem, CompletionItemKind,
3 CompletionKind, Completions, 5 CompletionKind, Completions,
diff --git a/crates/ra_ide_api/src/completion/completion_context.rs b/crates/ra_ide_api/src/completion/completion_context.rs
index 57542152f..e9ad06965 100644
--- a/crates/ra_ide_api/src/completion/completion_context.rs
+++ b/crates/ra_ide_api/src/completion/completion_context.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use ra_syntax::{ 3use ra_syntax::{
2 algo::{find_covering_element, find_node_at_offset}, 4 algo::{find_covering_element, find_node_at_offset},
3 ast, AstNode, Parse, SourceFile, 5 ast, AstNode, Parse, SourceFile,
diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs
index d787bb69e..b1f0390ec 100644
--- a/crates/ra_ide_api/src/completion/completion_item.rs
+++ b/crates/ra_ide_api/src/completion/completion_item.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use std::fmt; 3use std::fmt;
2 4
3use hir::Documentation; 5use hir::Documentation;
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs
index b8aa433c1..48028a2f9 100644
--- a/crates/ra_ide_api/src/completion/presentation.rs
+++ b/crates/ra_ide_api/src/completion/presentation.rs
@@ -1,4 +1,5 @@
1//! This modules takes care of rendering various definitions as completion items. 1//! This modules takes care of rendering various definitions as completion items.
2
2use hir::{Docs, HasSource, HirDisplay, ScopeDef, Ty, TypeWalk}; 3use hir::{Docs, HasSource, HirDisplay, ScopeDef, Ty, TypeWalk};
3use join_to_string::join; 4use join_to_string::join;
4use ra_syntax::ast::NameOwner; 5use ra_syntax::ast::NameOwner;
diff --git a/crates/ra_ide_api/src/db.rs b/crates/ra_ide_api/src/db.rs
index afd9022ce..ea0714add 100644
--- a/crates/ra_ide_api/src/db.rs
+++ b/crates/ra_ide_api/src/db.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use std::sync::Arc; 3use std::sync::Arc;
2 4
3use ra_db::{ 5use ra_db::{
diff --git a/crates/ra_ide_api/src/diagnostics.rs b/crates/ra_ide_api/src/diagnostics.rs
index 144bc0a70..0435188c8 100644
--- a/crates/ra_ide_api/src/diagnostics.rs
+++ b/crates/ra_ide_api/src/diagnostics.rs
@@ -1,11 +1,13 @@
1//! FIXME: write short doc here
2
1use std::cell::RefCell; 3use std::cell::RefCell;
2 4
3use hir::diagnostics::{AstDiagnostic, Diagnostic as _, DiagnosticSink}; 5use hir::diagnostics::{AstDiagnostic, Diagnostic as _, DiagnosticSink};
4use itertools::Itertools; 6use itertools::Itertools;
5use ra_assists::ast_editor::AstEditor;
6use ra_db::SourceDatabase; 7use ra_db::SourceDatabase;
7use ra_prof::profile; 8use ra_prof::profile;
8use ra_syntax::{ 9use ra_syntax::{
10 algo,
9 ast::{self, make, AstNode}, 11 ast::{self, make, AstNode},
10 Location, SyntaxNode, TextRange, T, 12 Location, SyntaxNode, TextRange, T,
11}; 13};
@@ -56,15 +58,15 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic>
56 }) 58 })
57 }) 59 })
58 .on::<hir::diagnostics::MissingFields, _>(|d| { 60 .on::<hir::diagnostics::MissingFields, _>(|d| {
59 let node = d.ast(db); 61 let mut field_list = d.ast(db);
60 let mut ast_editor = AstEditor::new(node);
61 for f in d.missed_fields.iter() { 62 for f in d.missed_fields.iter() {
62 let field = make::record_field(make::name_ref(&f.to_string()), Some(make::expr_unit())); 63 let field = make::record_field(make::name_ref(&f.to_string()), Some(make::expr_unit()));
63 ast_editor.append_field(&field); 64 field_list = field_list.append_field(&field);
64 } 65 }
65 66
66 let mut builder = TextEditBuilder::default(); 67 let mut builder = TextEditBuilder::default();
67 ast_editor.into_text_edit(&mut builder); 68 algo::diff(&d.ast(db).syntax(), &field_list.syntax()).into_text_edit(&mut builder);
69
68 let fix = 70 let fix =
69 SourceChange::source_file_edit_from("fill struct fields", file_id, builder.finish()); 71 SourceChange::source_file_edit_from("fill struct fields", file_id, builder.finish());
70 res.borrow_mut().push(Diagnostic { 72 res.borrow_mut().push(Diagnostic {
diff --git a/crates/ra_ide_api/src/display/function_signature.rs b/crates/ra_ide_api/src/display/function_signature.rs
index 644a4532b..43f022ccd 100644
--- a/crates/ra_ide_api/src/display/function_signature.rs
+++ b/crates/ra_ide_api/src/display/function_signature.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use std::fmt::{self, Display}; 3use std::fmt::{self, Display};
2 4
3use hir::{Docs, Documentation, HasSource}; 5use hir::{Docs, Documentation, HasSource};
diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs
index d3e774bd0..d0b1a8a2a 100644
--- a/crates/ra_ide_api/src/display/navigation_target.rs
+++ b/crates/ra_ide_api/src/display/navigation_target.rs
@@ -1,9 +1,10 @@
1//! FIXME: write short doc here
2
1use hir::{AssocItem, FieldSource, HasSource, ModuleSource}; 3use hir::{AssocItem, FieldSource, HasSource, ModuleSource};
2use ra_db::{FileId, SourceDatabase}; 4use ra_db::{FileId, SourceDatabase};
3use ra_syntax::{ 5use ra_syntax::{
4 algo::visit::{visitor, Visitor},
5 ast::{self, DocCommentsOwner}, 6 ast::{self, DocCommentsOwner},
6 AstNode, AstPtr, SmolStr, 7 match_ast, AstNode, AstPtr, SmolStr,
7 SyntaxKind::{self, NAME}, 8 SyntaxKind::{self, NAME},
8 SyntaxNode, TextRange, 9 SyntaxNode, TextRange,
9}; 10};
@@ -306,19 +307,22 @@ pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option
306 let parse = db.parse(symbol.file_id); 307 let parse = db.parse(symbol.file_id);
307 let node = symbol.ptr.to_node(parse.tree().syntax()); 308 let node = symbol.ptr.to_node(parse.tree().syntax());
308 309
309 visitor() 310 match_ast! {
310 .visit(|it: ast::FnDef| it.doc_comment_text()) 311 match node {
311 .visit(|it: ast::StructDef| it.doc_comment_text()) 312 ast::FnDef(it) => { it.doc_comment_text() },
312 .visit(|it: ast::EnumDef| it.doc_comment_text()) 313 ast::StructDef(it) => { it.doc_comment_text() },
313 .visit(|it: ast::TraitDef| it.doc_comment_text()) 314 ast::EnumDef(it) => { it.doc_comment_text() },
314 .visit(|it: ast::Module| it.doc_comment_text()) 315 ast::TraitDef(it) => { it.doc_comment_text() },
315 .visit(|it: ast::TypeAliasDef| it.doc_comment_text()) 316 ast::Module(it) => { it.doc_comment_text() },
316 .visit(|it: ast::ConstDef| it.doc_comment_text()) 317 ast::TypeAliasDef(it) => { it.doc_comment_text() },
317 .visit(|it: ast::StaticDef| it.doc_comment_text()) 318 ast::ConstDef(it) => { it.doc_comment_text() },
318 .visit(|it: ast::RecordFieldDef| it.doc_comment_text()) 319 ast::StaticDef(it) => { it.doc_comment_text() },
319 .visit(|it: ast::EnumVariant| it.doc_comment_text()) 320 ast::RecordFieldDef(it) => { it.doc_comment_text() },
320 .visit(|it: ast::MacroCall| it.doc_comment_text()) 321 ast::EnumVariant(it) => { it.doc_comment_text() },
321 .accept(&node)? 322 ast::MacroCall(it) => { it.doc_comment_text() },
323 _ => None,
324 }
325 }
322} 326}
323 327
324/// Get a description of a symbol. 328/// Get a description of a symbol.
@@ -328,16 +332,19 @@ pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) ->
328 let parse = db.parse(symbol.file_id); 332 let parse = db.parse(symbol.file_id);
329 let node = symbol.ptr.to_node(parse.tree().syntax()); 333 let node = symbol.ptr.to_node(parse.tree().syntax());
330 334
331 visitor() 335 match_ast! {
332 .visit(|node: ast::FnDef| node.short_label()) 336 match node {
333 .visit(|node: ast::StructDef| node.short_label()) 337 ast::FnDef(it) => { it.short_label() },
334 .visit(|node: ast::EnumDef| node.short_label()) 338 ast::StructDef(it) => { it.short_label() },
335 .visit(|node: ast::TraitDef| node.short_label()) 339 ast::EnumDef(it) => { it.short_label() },
336 .visit(|node: ast::Module| node.short_label()) 340 ast::TraitDef(it) => { it.short_label() },
337 .visit(|node: ast::TypeAliasDef| node.short_label()) 341 ast::Module(it) => { it.short_label() },
338 .visit(|node: ast::ConstDef| node.short_label()) 342 ast::TypeAliasDef(it) => { it.short_label() },
339 .visit(|node: ast::StaticDef| node.short_label()) 343 ast::ConstDef(it) => { it.short_label() },
340 .visit(|node: ast::RecordFieldDef| node.short_label()) 344 ast::StaticDef(it) => { it.short_label() },
341 .visit(|node: ast::EnumVariant| node.short_label()) 345 ast::RecordFieldDef(it) => { it.short_label() },
342 .accept(&node)? 346 ast::EnumVariant(it) => { it.short_label() },
347 _ => None,
348 }
349 }
343} 350}
diff --git a/crates/ra_ide_api/src/display/short_label.rs b/crates/ra_ide_api/src/display/short_label.rs
index b16d504e1..5d2bce3d2 100644
--- a/crates/ra_ide_api/src/display/short_label.rs
+++ b/crates/ra_ide_api/src/display/short_label.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use format_buf::format; 3use format_buf::format;
2use ra_syntax::ast::{self, AstNode, NameOwner, TypeAscriptionOwner, VisibilityOwner}; 4use ra_syntax::ast::{self, AstNode, NameOwner, TypeAscriptionOwner, VisibilityOwner};
3 5
diff --git a/crates/ra_ide_api/src/display/structure.rs b/crates/ra_ide_api/src/display/structure.rs
index be042ed17..ddd8b7b20 100644
--- a/crates/ra_ide_api/src/display/structure.rs
+++ b/crates/ra_ide_api/src/display/structure.rs
@@ -1,9 +1,10 @@
1//! FIXME: write short doc here
2
1use crate::TextRange; 3use crate::TextRange;
2 4
3use ra_syntax::{ 5use ra_syntax::{
4 algo::visit::{visitor, Visitor},
5 ast::{self, AttrsOwner, NameOwner, TypeAscriptionOwner, TypeParamsOwner}, 6 ast::{self, AttrsOwner, NameOwner, TypeAscriptionOwner, TypeParamsOwner},
6 AstNode, SourceFile, SyntaxKind, SyntaxNode, WalkEvent, 7 match_ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, WalkEvent,
7}; 8};
8 9
9#[derive(Debug, Clone)] 10#[derive(Debug, Clone)]
@@ -77,7 +78,7 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
77 node_range: node.syntax().text_range(), 78 node_range: node.syntax().text_range(),
78 kind: node.syntax().kind(), 79 kind: node.syntax().kind(),
79 detail, 80 detail,
80 deprecated: node.attrs().filter_map(|x| x.as_named()).any(|x| x == "deprecated"), 81 deprecated: node.attrs().filter_map(|x| x.simple_name()).any(|x| x == "deprecated"),
81 }) 82 })
82 } 83 }
83 84
@@ -99,63 +100,66 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
99 }) 100 })
100 } 101 }
101 102
102 visitor() 103 match_ast! {
103 .visit(|fn_def: ast::FnDef| { 104 match node {
104 let mut detail = String::from("fn"); 105 ast::FnDef(it) => {
105 if let Some(type_param_list) = fn_def.type_param_list() { 106 let mut detail = String::from("fn");
106 collapse_ws(type_param_list.syntax(), &mut detail); 107 if let Some(type_param_list) = it.type_param_list() {
107 } 108 collapse_ws(type_param_list.syntax(), &mut detail);
108 if let Some(param_list) = fn_def.param_list() { 109 }
109 collapse_ws(param_list.syntax(), &mut detail); 110 if let Some(param_list) = it.param_list() {
110 } 111 collapse_ws(param_list.syntax(), &mut detail);
111 if let Some(ret_type) = fn_def.ret_type() { 112 }
112 detail.push_str(" "); 113 if let Some(ret_type) = it.ret_type() {
113 collapse_ws(ret_type.syntax(), &mut detail); 114 detail.push_str(" ");
114 } 115 collapse_ws(ret_type.syntax(), &mut detail);
115
116 decl_with_detail(fn_def, Some(detail))
117 })
118 .visit(decl::<ast::StructDef>)
119 .visit(decl::<ast::EnumDef>)
120 .visit(decl::<ast::EnumVariant>)
121 .visit(decl::<ast::TraitDef>)
122 .visit(decl::<ast::Module>)
123 .visit(|td: ast::TypeAliasDef| {
124 let ty = td.type_ref();
125 decl_with_type_ref(td, ty)
126 })
127 .visit(decl_with_ascription::<ast::RecordFieldDef>)
128 .visit(decl_with_ascription::<ast::ConstDef>)
129 .visit(decl_with_ascription::<ast::StaticDef>)
130 .visit(|im: ast::ImplBlock| {
131 let target_type = im.target_type()?;
132 let target_trait = im.target_trait();
133 let label = match target_trait {
134 None => format!("impl {}", target_type.syntax().text()),
135 Some(t) => {
136 format!("impl {} for {}", t.syntax().text(), target_type.syntax().text(),)
137 } 116 }
138 };
139 117
140 let node = StructureNode { 118 decl_with_detail(it, Some(detail))
141 parent: None, 119 },
142 label, 120 ast::StructDef(it) => { decl(it) },
143 navigation_range: target_type.syntax().text_range(), 121 ast::EnumDef(it) => { decl(it) },
144 node_range: im.syntax().text_range(), 122 ast::EnumVariant(it) => { decl(it) },
145 kind: im.syntax().kind(), 123 ast::TraitDef(it) => { decl(it) },
146 detail: None, 124 ast::Module(it) => { decl(it) },
147 deprecated: false, 125 ast::TypeAliasDef(it) => {
148 }; 126 let ty = it.type_ref();
149 Some(node) 127 decl_with_type_ref(it, ty)
150 }) 128 },
151 .visit(|mc: ast::MacroCall| { 129 ast::RecordFieldDef(it) => { decl_with_ascription(it) },
152 let first_token = mc.syntax().first_token().unwrap(); 130 ast::ConstDef(it) => { decl_with_ascription(it) },
153 if first_token.text().as_str() != "macro_rules" { 131 ast::StaticDef(it) => { decl_with_ascription(it) },
154 return None; 132 ast::ImplBlock(it) => {
155 } 133 let target_type = it.target_type()?;
156 decl(mc) 134 let target_trait = it.target_trait();
157 }) 135 let label = match target_trait {
158 .accept(&node)? 136 None => format!("impl {}", target_type.syntax().text()),
137 Some(t) => {
138 format!("impl {} for {}", t.syntax().text(), target_type.syntax().text(),)
139 }
140 };
141
142 let node = StructureNode {
143 parent: None,
144 label,
145 navigation_range: target_type.syntax().text_range(),
146 node_range: it.syntax().text_range(),
147 kind: it.syntax().kind(),
148 detail: None,
149 deprecated: false,
150 };
151 Some(node)
152 },
153 ast::MacroCall(it) => {
154 let first_token = it.syntax().first_token().unwrap();
155 if first_token.text().as_str() != "macro_rules" {
156 return None;
157 }
158 decl(it)
159 },
160 _ => None,
161 }
162 }
159} 163}
160 164
161#[cfg(test)] 165#[cfg(test)]
diff --git a/crates/ra_ide_api/src/extend_selection.rs b/crates/ra_ide_api/src/extend_selection.rs
index e990eb0d1..33fefb541 100644
--- a/crates/ra_ide_api/src/extend_selection.rs
+++ b/crates/ra_ide_api/src/extend_selection.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use ra_db::SourceDatabase; 3use ra_db::SourceDatabase;
2use ra_syntax::{ 4use ra_syntax::{
3 algo::find_covering_element, 5 algo::find_covering_element,
diff --git a/crates/ra_ide_api/src/feature_flags.rs b/crates/ra_ide_api/src/feature_flags.rs
index 9f82ac71c..d3ca7be03 100644
--- a/crates/ra_ide_api/src/feature_flags.rs
+++ b/crates/ra_ide_api/src/feature_flags.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use rustc_hash::FxHashMap; 3use rustc_hash::FxHashMap;
2 4
3/// Feature flags hold fine-grained toggles for all *user-visible* features of 5/// Feature flags hold fine-grained toggles for all *user-visible* features of
diff --git a/crates/ra_ide_api/src/folding_ranges.rs b/crates/ra_ide_api/src/folding_ranges.rs
index 79fadcc5d..4eeb76d14 100644
--- a/crates/ra_ide_api/src/folding_ranges.rs
+++ b/crates/ra_ide_api/src/folding_ranges.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use rustc_hash::FxHashSet; 3use rustc_hash::FxHashSet;
2 4
3use ra_syntax::{ 5use ra_syntax::{
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs
index bc8863dad..41a88314f 100644
--- a/crates/ra_ide_api/src/goto_definition.rs
+++ b/crates/ra_ide_api/src/goto_definition.rs
@@ -1,11 +1,10 @@
1//! FIXME: write short doc here
2
1use ra_db::{FileId, SourceDatabase}; 3use ra_db::{FileId, SourceDatabase};
2use ra_syntax::{ 4use ra_syntax::{
3 algo::{ 5 algo::find_node_at_offset,
4 find_node_at_offset,
5 visit::{visitor, Visitor},
6 },
7 ast::{self, DocCommentsOwner}, 6 ast::{self, DocCommentsOwner},
8 AstNode, SyntaxNode, 7 match_ast, AstNode, SyntaxNode,
9}; 8};
10 9
11use crate::{ 10use crate::{
@@ -112,91 +111,99 @@ pub(crate) fn name_definition(
112} 111}
113 112
114fn named_target(file_id: FileId, node: &SyntaxNode) -> Option<NavigationTarget> { 113fn named_target(file_id: FileId, node: &SyntaxNode) -> Option<NavigationTarget> {
115 visitor() 114 match_ast! {
116 .visit(|node: ast::StructDef| { 115 match node {
117 NavigationTarget::from_named( 116 ast::StructDef(it) => {
118 file_id, 117 Some(NavigationTarget::from_named(
119 &node, 118 file_id,
120 node.doc_comment_text(), 119 &it,
121 node.short_label(), 120 it.doc_comment_text(),
122 ) 121 it.short_label(),
123 }) 122 ))
124 .visit(|node: ast::EnumDef| { 123 },
125 NavigationTarget::from_named( 124 ast::EnumDef(it) => {
126 file_id, 125 Some(NavigationTarget::from_named(
127 &node, 126 file_id,
128 node.doc_comment_text(), 127 &it,
129 node.short_label(), 128 it.doc_comment_text(),
130 ) 129 it.short_label(),
131 }) 130 ))
132 .visit(|node: ast::EnumVariant| { 131 },
133 NavigationTarget::from_named( 132 ast::EnumVariant(it) => {
134 file_id, 133 Some(NavigationTarget::from_named(
135 &node, 134 file_id,
136 node.doc_comment_text(), 135 &it,
137 node.short_label(), 136 it.doc_comment_text(),
138 ) 137 it.short_label(),
139 }) 138 ))
140 .visit(|node: ast::FnDef| { 139 },
141 NavigationTarget::from_named( 140 ast::FnDef(it) => {
142 file_id, 141 Some(NavigationTarget::from_named(
143 &node, 142 file_id,
144 node.doc_comment_text(), 143 &it,
145 node.short_label(), 144 it.doc_comment_text(),
146 ) 145 it.short_label(),
147 }) 146 ))
148 .visit(|node: ast::TypeAliasDef| { 147 },
149 NavigationTarget::from_named( 148 ast::TypeAliasDef(it) => {
150 file_id, 149 Some(NavigationTarget::from_named(
151 &node, 150 file_id,
152 node.doc_comment_text(), 151 &it,
153 node.short_label(), 152 it.doc_comment_text(),
154 ) 153 it.short_label(),
155 }) 154 ))
156 .visit(|node: ast::ConstDef| { 155 },
157 NavigationTarget::from_named( 156 ast::ConstDef(it) => {
158 file_id, 157 Some(NavigationTarget::from_named(
159 &node, 158 file_id,
160 node.doc_comment_text(), 159 &it,
161 node.short_label(), 160 it.doc_comment_text(),
162 ) 161 it.short_label(),
163 }) 162 ))
164 .visit(|node: ast::StaticDef| { 163 },
165 NavigationTarget::from_named( 164 ast::StaticDef(it) => {
166 file_id, 165 Some(NavigationTarget::from_named(
167 &node, 166 file_id,
168 node.doc_comment_text(), 167 &it,
169 node.short_label(), 168 it.doc_comment_text(),
170 ) 169 it.short_label(),
171 }) 170 ))
172 .visit(|node: ast::TraitDef| { 171 },
173 NavigationTarget::from_named( 172 ast::TraitDef(it) => {
174 file_id, 173 Some(NavigationTarget::from_named(
175 &node, 174 file_id,
176 node.doc_comment_text(), 175 &it,
177 node.short_label(), 176 it.doc_comment_text(),
178 ) 177 it.short_label(),
179 }) 178 ))
180 .visit(|node: ast::RecordFieldDef| { 179 },
181 NavigationTarget::from_named( 180 ast::RecordFieldDef(it) => {
182 file_id, 181 Some(NavigationTarget::from_named(
183 &node, 182 file_id,
184 node.doc_comment_text(), 183 &it,
185 node.short_label(), 184 it.doc_comment_text(),
186 ) 185 it.short_label(),
187 }) 186 ))
188 .visit(|node: ast::Module| { 187 },
189 NavigationTarget::from_named( 188 ast::Module(it) => {
190 file_id, 189 Some(NavigationTarget::from_named(
191 &node, 190 file_id,
192 node.doc_comment_text(), 191 &it,
193 node.short_label(), 192 it.doc_comment_text(),
194 ) 193 it.short_label(),
195 }) 194 ))
196 .visit(|node: ast::MacroCall| { 195 },
197 NavigationTarget::from_named(file_id, &node, node.doc_comment_text(), None) 196 ast::MacroCall(it) => {
198 }) 197 Some(NavigationTarget::from_named(
199 .accept(node) 198 file_id,
199 &it,
200 it.doc_comment_text(),
201 None,
202 ))
203 },
204 _ => None,
205 }
206 }
200} 207}
201 208
202#[cfg(test)] 209#[cfg(test)]
diff --git a/crates/ra_ide_api/src/goto_type_definition.rs b/crates/ra_ide_api/src/goto_type_definition.rs
index 72884e5ca..059d80524 100644
--- a/crates/ra_ide_api/src/goto_type_definition.rs
+++ b/crates/ra_ide_api/src/goto_type_definition.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use ra_db::SourceDatabase; 3use ra_db::SourceDatabase;
2use ra_syntax::{ast, AstNode}; 4use ra_syntax::{ast, AstNode};
3 5
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs
index 655bcdb16..24b161c5c 100644
--- a/crates/ra_ide_api/src/hover.rs
+++ b/crates/ra_ide_api/src/hover.rs
@@ -1,12 +1,11 @@
1//! FIXME: write short doc here
2
1use hir::{Adt, HasSource, HirDisplay}; 3use hir::{Adt, HasSource, HirDisplay};
2use ra_db::SourceDatabase; 4use ra_db::SourceDatabase;
3use ra_syntax::{ 5use ra_syntax::{
4 algo::{ 6 algo::{ancestors_at_offset, find_covering_element, find_node_at_offset},
5 ancestors_at_offset, find_covering_element, find_node_at_offset,
6 visit::{visitor, Visitor},
7 },
8 ast::{self, DocCommentsOwner}, 7 ast::{self, DocCommentsOwner},
9 AstNode, 8 match_ast, AstNode,
10}; 9};
11 10
12use crate::{ 11use crate::{
@@ -176,37 +175,45 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
176 } 175 }
177 } else if let Some(name) = find_node_at_offset::<ast::Name>(file.syntax(), position.offset) { 176 } else if let Some(name) = find_node_at_offset::<ast::Name>(file.syntax(), position.offset) {
178 if let Some(parent) = name.syntax().parent() { 177 if let Some(parent) = name.syntax().parent() {
179 let text = visitor() 178 let text = match_ast! {
180 .visit(|node: ast::StructDef| { 179 match parent {
181 hover_text(node.doc_comment_text(), node.short_label()) 180 ast::StructDef(it) => {
182 }) 181 hover_text(it.doc_comment_text(), it.short_label())
183 .visit(|node: ast::EnumDef| hover_text(node.doc_comment_text(), node.short_label())) 182 },
184 .visit(|node: ast::EnumVariant| { 183 ast::EnumDef(it) => {
185 hover_text(node.doc_comment_text(), node.short_label()) 184 hover_text(it.doc_comment_text(), it.short_label())
186 }) 185 },
187 .visit(|node: ast::FnDef| hover_text(node.doc_comment_text(), node.short_label())) 186 ast::EnumVariant(it) => {
188 .visit(|node: ast::TypeAliasDef| { 187 hover_text(it.doc_comment_text(), it.short_label())
189 hover_text(node.doc_comment_text(), node.short_label()) 188 },
190 }) 189 ast::FnDef(it) => {
191 .visit(|node: ast::ConstDef| { 190 hover_text(it.doc_comment_text(), it.short_label())
192 hover_text(node.doc_comment_text(), node.short_label()) 191 },
193 }) 192 ast::TypeAliasDef(it) => {
194 .visit(|node: ast::StaticDef| { 193 hover_text(it.doc_comment_text(), it.short_label())
195 hover_text(node.doc_comment_text(), node.short_label()) 194 },
196 }) 195 ast::ConstDef(it) => {
197 .visit(|node: ast::TraitDef| { 196 hover_text(it.doc_comment_text(), it.short_label())
198 hover_text(node.doc_comment_text(), node.short_label()) 197 },
199 }) 198 ast::StaticDef(it) => {
200 .visit(|node: ast::RecordFieldDef| { 199 hover_text(it.doc_comment_text(), it.short_label())
201 hover_text(node.doc_comment_text(), node.short_label()) 200 },
202 }) 201 ast::TraitDef(it) => {
203 .visit(|node: ast::Module| hover_text(node.doc_comment_text(), node.short_label())) 202 hover_text(it.doc_comment_text(), it.short_label())
204 .visit(|node: ast::MacroCall| hover_text(node.doc_comment_text(), None)) 203 },
205 .accept(&parent); 204 ast::RecordFieldDef(it) => {
206 205 hover_text(it.doc_comment_text(), it.short_label())
207 if let Some(text) = text { 206 },
208 res.extend(text); 207 ast::Module(it) => {
209 } 208 hover_text(it.doc_comment_text(), it.short_label())
209 },
210 ast::MacroCall(it) => {
211 hover_text(it.doc_comment_text(), None)
212 },
213 _ => None,
214 }
215 };
216 res.extend(text);
210 } 217 }
211 218
212 if !res.is_empty() && range.is_none() { 219 if !res.is_empty() && range.is_none() {
diff --git a/crates/ra_ide_api/src/impls.rs b/crates/ra_ide_api/src/impls.rs
index f57f9a21b..7fc1b1efa 100644
--- a/crates/ra_ide_api/src/impls.rs
+++ b/crates/ra_ide_api/src/impls.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use hir::{db::HirDatabase, ApplicationTy, FromSource, Ty, TypeCtor}; 3use hir::{db::HirDatabase, ApplicationTy, FromSource, Ty, TypeCtor};
2use ra_db::SourceDatabase; 4use ra_db::SourceDatabase;
3use ra_syntax::{algo::find_node_at_offset, ast, AstNode}; 5use ra_syntax::{algo::find_node_at_offset, ast, AstNode};
diff --git a/crates/ra_ide_api/src/inlay_hints.rs b/crates/ra_ide_api/src/inlay_hints.rs
index 16bdcf9d1..f1c0dc164 100644
--- a/crates/ra_ide_api/src/inlay_hints.rs
+++ b/crates/ra_ide_api/src/inlay_hints.rs
@@ -1,9 +1,10 @@
1//! FIXME: write short doc here
2
1use crate::{db::RootDatabase, FileId}; 3use crate::{db::RootDatabase, FileId};
2use hir::{HirDisplay, SourceAnalyzer, Ty}; 4use hir::{HirDisplay, SourceAnalyzer, Ty};
3use ra_syntax::{ 5use ra_syntax::{
4 algo::visit::{visitor, Visitor},
5 ast::{self, AstNode, TypeAscriptionOwner}, 6 ast::{self, AstNode, TypeAscriptionOwner},
6 SmolStr, SourceFile, SyntaxKind, SyntaxNode, TextRange, 7 match_ast, SmolStr, SourceFile, SyntaxKind, SyntaxNode, TextRange,
7}; 8};
8 9
9#[derive(Debug, PartialEq, Eq)] 10#[derive(Debug, PartialEq, Eq)]
@@ -31,55 +32,58 @@ fn get_inlay_hints(
31 file_id: FileId, 32 file_id: FileId,
32 node: &SyntaxNode, 33 node: &SyntaxNode,
33) -> Option<Vec<InlayHint>> { 34) -> Option<Vec<InlayHint>> {
34 visitor() 35 match_ast! {
35 .visit(|let_statement: ast::LetStmt| { 36 match node {
36 if let_statement.ascribed_type().is_some() { 37 ast::LetStmt(it) => {
37 return None; 38 if it.ascribed_type().is_some() {
38 } 39 return None;
39 let pat = let_statement.pat()?; 40 }
40 let analyzer = SourceAnalyzer::new(db, file_id, let_statement.syntax(), None); 41 let pat = it.pat()?;
41 Some(get_pat_type_hints(db, &analyzer, pat, false)) 42 let analyzer = SourceAnalyzer::new(db, file_id, it.syntax(), None);
42 }) 43 Some(get_pat_type_hints(db, &analyzer, pat, false))
43 .visit(|closure_parameter: ast::LambdaExpr| { 44 },
44 let analyzer = SourceAnalyzer::new(db, file_id, closure_parameter.syntax(), None); 45 ast::LambdaExpr(it) => {
45 closure_parameter.param_list().map(|param_list| { 46 let analyzer = SourceAnalyzer::new(db, file_id, it.syntax(), None);
46 param_list 47 it.param_list().map(|param_list| {
47 .params() 48 param_list
48 .filter(|closure_param| closure_param.ascribed_type().is_none()) 49 .params()
49 .filter_map(|closure_param| closure_param.pat()) 50 .filter(|closure_param| closure_param.ascribed_type().is_none())
50 .map(|root_pat| get_pat_type_hints(db, &analyzer, root_pat, false)) 51 .filter_map(|closure_param| closure_param.pat())
51 .flatten() 52 .map(|root_pat| get_pat_type_hints(db, &analyzer, root_pat, false))
52 .collect() 53 .flatten()
53 }) 54 .collect()
54 }) 55 })
55 .visit(|for_expression: ast::ForExpr| { 56 },
56 let pat = for_expression.pat()?; 57 ast::ForExpr(it) => {
57 let analyzer = SourceAnalyzer::new(db, file_id, for_expression.syntax(), None); 58 let pat = it.pat()?;
58 Some(get_pat_type_hints(db, &analyzer, pat, false)) 59 let analyzer = SourceAnalyzer::new(db, file_id, it.syntax(), None);
59 }) 60 Some(get_pat_type_hints(db, &analyzer, pat, false))
60 .visit(|if_expr: ast::IfExpr| { 61 },
61 let pat = if_expr.condition()?.pat()?; 62 ast::IfExpr(it) => {
62 let analyzer = SourceAnalyzer::new(db, file_id, if_expr.syntax(), None); 63 let pat = it.condition()?.pat()?;
63 Some(get_pat_type_hints(db, &analyzer, pat, true)) 64 let analyzer = SourceAnalyzer::new(db, file_id, it.syntax(), None);
64 }) 65 Some(get_pat_type_hints(db, &analyzer, pat, true))
65 .visit(|while_expr: ast::WhileExpr| { 66 },
66 let pat = while_expr.condition()?.pat()?; 67 ast::WhileExpr(it) => {
67 let analyzer = SourceAnalyzer::new(db, file_id, while_expr.syntax(), None); 68 let pat = it.condition()?.pat()?;
68 Some(get_pat_type_hints(db, &analyzer, pat, true)) 69 let analyzer = SourceAnalyzer::new(db, file_id, it.syntax(), None);
69 }) 70 Some(get_pat_type_hints(db, &analyzer, pat, true))
70 .visit(|match_arm_list: ast::MatchArmList| { 71 },
71 let analyzer = SourceAnalyzer::new(db, file_id, match_arm_list.syntax(), None); 72 ast::MatchArmList(it) => {
72 Some( 73 let analyzer = SourceAnalyzer::new(db, file_id, it.syntax(), None);
73 match_arm_list 74 Some(
74 .arms() 75 it
75 .map(|match_arm| match_arm.pats()) 76 .arms()
76 .flatten() 77 .map(|match_arm| match_arm.pats())
77 .map(|root_pat| get_pat_type_hints(db, &analyzer, root_pat, true)) 78 .flatten()
78 .flatten() 79 .map(|root_pat| get_pat_type_hints(db, &analyzer, root_pat, true))
79 .collect(), 80 .flatten()
80 ) 81 .collect(),
81 }) 82 )
82 .accept(&node)? 83 },
84 _ => None,
85 }
86 }
83} 87}
84 88
85fn get_pat_type_hints( 89fn get_pat_type_hints(
diff --git a/crates/ra_ide_api/src/join_lines.rs b/crates/ra_ide_api/src/join_lines.rs
index a71e4ed7d..6f71b27db 100644
--- a/crates/ra_ide_api/src/join_lines.rs
+++ b/crates/ra_ide_api/src/join_lines.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use itertools::Itertools; 3use itertools::Itertools;
2use ra_fmt::{compute_ws, extract_trivial_expression}; 4use ra_fmt::{compute_ws, extract_trivial_expression};
3use ra_syntax::{ 5use ra_syntax::{
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs
index 44d1ec77b..24f1b91f6 100644
--- a/crates/ra_ide_api/src/lib.rs
+++ b/crates/ra_ide_api/src/lib.rs
@@ -49,6 +49,7 @@ mod test_utils;
49 49
50use std::sync::Arc; 50use std::sync::Arc;
51 51
52use ra_cfg::CfgOptions;
52use ra_db::{ 53use ra_db::{
53 salsa::{self, ParallelDatabase}, 54 salsa::{self, ParallelDatabase},
54 CheckCanceled, SourceDatabase, 55 CheckCanceled, SourceDatabase,
@@ -322,7 +323,10 @@ impl Analysis {
322 change.add_root(source_root, true); 323 change.add_root(source_root, true);
323 let mut crate_graph = CrateGraph::default(); 324 let mut crate_graph = CrateGraph::default();
324 let file_id = FileId(0); 325 let file_id = FileId(0);
325 crate_graph.add_crate_root(file_id, Edition::Edition2018); 326 // FIXME: cfg options
327 // Default to enable test for single file.
328 let cfg_options = CfgOptions::default().atom("test".into());
329 crate_graph.add_crate_root(file_id, Edition::Edition2018, cfg_options);
326 change.add_file(source_root, file_id, "main.rs".into(), Arc::new(text)); 330 change.add_file(source_root, file_id, "main.rs".into(), Arc::new(text));
327 change.set_crate_graph(crate_graph); 331 change.set_crate_graph(crate_graph);
328 host.apply_change(change); 332 host.apply_change(change);
diff --git a/crates/ra_ide_api/src/line_index.rs b/crates/ra_ide_api/src/line_index.rs
index 71de8a928..710890d27 100644
--- a/crates/ra_ide_api/src/line_index.rs
+++ b/crates/ra_ide_api/src/line_index.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use crate::TextUnit; 3use crate::TextUnit;
2use rustc_hash::FxHashMap; 4use rustc_hash::FxHashMap;
3use superslice::Ext; 5use superslice::Ext;
@@ -278,5 +280,4 @@ const C: char = \"メ メ\";
278 280
279 assert_eq!(col_index.utf16_to_utf8_col(2, 15), TextUnit::from_usize(15)); 281 assert_eq!(col_index.utf16_to_utf8_col(2, 15), TextUnit::from_usize(15));
280 } 282 }
281
282} 283}
diff --git a/crates/ra_ide_api/src/line_index_utils.rs b/crates/ra_ide_api/src/line_index_utils.rs
index 534009b98..bd1e08feb 100644
--- a/crates/ra_ide_api/src/line_index_utils.rs
+++ b/crates/ra_ide_api/src/line_index_utils.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use crate::{line_index::Utf16Char, LineCol, LineIndex}; 3use crate::{line_index::Utf16Char, LineCol, LineIndex};
2use ra_syntax::{TextRange, TextUnit}; 4use ra_syntax::{TextRange, TextUnit};
3use ra_text_edit::{AtomTextEdit, TextEdit}; 5use ra_text_edit::{AtomTextEdit, TextEdit};
diff --git a/crates/ra_ide_api/src/marks.rs b/crates/ra_ide_api/src/marks.rs
index c3752cc54..3f4ba248b 100644
--- a/crates/ra_ide_api/src/marks.rs
+++ b/crates/ra_ide_api/src/marks.rs
@@ -1,3 +1,5 @@
1//! See test_utils/src/marks.rs
2
1test_utils::marks!( 3test_utils::marks!(
2 inserts_parens_for_function_calls 4 inserts_parens_for_function_calls
3 goto_definition_works_for_macros 5 goto_definition_works_for_macros
diff --git a/crates/ra_ide_api/src/matching_brace.rs b/crates/ra_ide_api/src/matching_brace.rs
index e802d01e4..d1204fac0 100644
--- a/crates/ra_ide_api/src/matching_brace.rs
+++ b/crates/ra_ide_api/src/matching_brace.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use ra_syntax::{ast::AstNode, SourceFile, SyntaxKind, TextUnit, T}; 3use ra_syntax::{ast::AstNode, SourceFile, SyntaxKind, TextUnit, T};
2 4
3pub fn matching_brace(file: &SourceFile, offset: TextUnit) -> Option<TextUnit> { 5pub fn matching_brace(file: &SourceFile, offset: TextUnit) -> Option<TextUnit> {
diff --git a/crates/ra_ide_api/src/mock_analysis.rs b/crates/ra_ide_api/src/mock_analysis.rs
index 132f6f875..80b71894c 100644
--- a/crates/ra_ide_api/src/mock_analysis.rs
+++ b/crates/ra_ide_api/src/mock_analysis.rs
@@ -1,5 +1,8 @@
1//! FIXME: write short doc here
2
1use std::sync::Arc; 3use std::sync::Arc;
2 4
5use ra_cfg::CfgOptions;
3use relative_path::RelativePathBuf; 6use relative_path::RelativePathBuf;
4use test_utils::{extract_offset, extract_range, parse_fixture, CURSOR_MARKER}; 7use test_utils::{extract_offset, extract_range, parse_fixture, CURSOR_MARKER};
5 8
@@ -91,10 +94,11 @@ impl MockAnalysis {
91 assert!(path.starts_with('/')); 94 assert!(path.starts_with('/'));
92 let path = RelativePathBuf::from_path(&path[1..]).unwrap(); 95 let path = RelativePathBuf::from_path(&path[1..]).unwrap();
93 let file_id = FileId(i as u32 + 1); 96 let file_id = FileId(i as u32 + 1);
97 let cfg_options = CfgOptions::default();
94 if path == "/lib.rs" || path == "/main.rs" { 98 if path == "/lib.rs" || path == "/main.rs" {
95 root_crate = Some(crate_graph.add_crate_root(file_id, Edition2018)); 99 root_crate = Some(crate_graph.add_crate_root(file_id, Edition2018, cfg_options));
96 } else if path.ends_with("/lib.rs") { 100 } else if path.ends_with("/lib.rs") {
97 let other_crate = crate_graph.add_crate_root(file_id, Edition2018); 101 let other_crate = crate_graph.add_crate_root(file_id, Edition2018, cfg_options);
98 let crate_name = path.parent().unwrap().file_name().unwrap(); 102 let crate_name = path.parent().unwrap().file_name().unwrap();
99 if let Some(root_crate) = root_crate { 103 if let Some(root_crate) = root_crate {
100 crate_graph.add_dep(root_crate, crate_name.into(), other_crate).unwrap(); 104 crate_graph.add_dep(root_crate, crate_name.into(), other_crate).unwrap();
diff --git a/crates/ra_ide_api/src/name_ref_kind.rs b/crates/ra_ide_api/src/name_ref_kind.rs
index aff03464a..149585971 100644
--- a/crates/ra_ide_api/src/name_ref_kind.rs
+++ b/crates/ra_ide_api/src/name_ref_kind.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use hir::Either; 3use hir::Either;
2use ra_syntax::{ast, AstNode, AstPtr}; 4use ra_syntax::{ast, AstNode, AstPtr};
3use test_utils::tested_by; 5use test_utils::tested_by;
diff --git a/crates/ra_ide_api/src/parent_module.rs b/crates/ra_ide_api/src/parent_module.rs
index 3668da8d7..566509849 100644
--- a/crates/ra_ide_api/src/parent_module.rs
+++ b/crates/ra_ide_api/src/parent_module.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use ra_db::{CrateId, FileId, FilePosition}; 3use ra_db::{CrateId, FileId, FilePosition};
2 4
3use crate::{db::RootDatabase, NavigationTarget}; 5use crate::{db::RootDatabase, NavigationTarget};
@@ -39,6 +41,7 @@ mod tests {
39 AnalysisChange, CrateGraph, 41 AnalysisChange, CrateGraph,
40 Edition::Edition2018, 42 Edition::Edition2018,
41 }; 43 };
44 use ra_cfg::CfgOptions;
42 45
43 #[test] 46 #[test]
44 fn test_resolve_parent_module() { 47 fn test_resolve_parent_module() {
@@ -86,7 +89,7 @@ mod tests {
86 assert!(host.analysis().crate_for(mod_file).unwrap().is_empty()); 89 assert!(host.analysis().crate_for(mod_file).unwrap().is_empty());
87 90
88 let mut crate_graph = CrateGraph::default(); 91 let mut crate_graph = CrateGraph::default();
89 let crate_id = crate_graph.add_crate_root(root_file, Edition2018); 92 let crate_id = crate_graph.add_crate_root(root_file, Edition2018, CfgOptions::default());
90 let mut change = AnalysisChange::new(); 93 let mut change = AnalysisChange::new();
91 change.set_crate_graph(crate_graph); 94 change.set_crate_graph(crate_graph);
92 host.apply_change(change); 95 host.apply_change(change);
diff --git a/crates/ra_ide_api/src/references.rs b/crates/ra_ide_api/src/references.rs
index acca71f2a..84c2eb793 100644
--- a/crates/ra_ide_api/src/references.rs
+++ b/crates/ra_ide_api/src/references.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use hir::{Either, ModuleSource}; 3use hir::{Either, ModuleSource};
2use ra_db::SourceDatabase; 4use ra_db::SourceDatabase;
3use ra_syntax::{algo::find_node_at_offset, ast, AstNode, SourceFile, SyntaxNode}; 5use ra_syntax::{algo::find_node_at_offset, ast, AstNode, SourceFile, SyntaxNode};
diff --git a/crates/ra_ide_api/src/runnables.rs b/crates/ra_ide_api/src/runnables.rs
index 095ca56c4..910883da7 100644
--- a/crates/ra_ide_api/src/runnables.rs
+++ b/crates/ra_ide_api/src/runnables.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use itertools::Itertools; 3use itertools::Itertools;
2use ra_db::SourceDatabase; 4use ra_db::SourceDatabase;
3use ra_syntax::{ 5use ra_syntax::{
@@ -229,5 +231,4 @@ mod tests {
229 let runnables = analysis.runnables(pos.file_id).unwrap(); 231 let runnables = analysis.runnables(pos.file_id).unwrap();
230 assert!(runnables.is_empty()) 232 assert!(runnables.is_empty())
231 } 233 }
232
233} 234}
diff --git a/crates/ra_ide_api/src/snapshots/highlighting.html b/crates/ra_ide_api/src/snapshots/highlighting.html
index b39c4d371..ae30ebba3 100644
--- a/crates/ra_ide_api/src/snapshots/highlighting.html
+++ b/crates/ra_ide_api/src/snapshots/highlighting.html
@@ -19,7 +19,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
19.keyword\.unsafe { color: #DFAF8F; } 19.keyword\.unsafe { color: #DFAF8F; }
20.keyword\.control { color: #F0DFAF; font-weight: bold; } 20.keyword\.control { color: #F0DFAF; font-weight: bold; }
21</style> 21</style>
22<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> 22<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>
23<span class="keyword">struct</span> <span class="type">Foo</span> { 23<span class="keyword">struct</span> <span class="type">Foo</span> {
24 <span class="keyword">pub</span> <span class="field">x</span>: <span class="type">i32</span>, 24 <span class="keyword">pub</span> <span class="field">x</span>: <span class="type">i32</span>,
25 <span class="keyword">pub</span> <span class="field">y</span>: <span class="type">i32</span>, 25 <span class="keyword">pub</span> <span class="field">y</span>: <span class="type">i32</span>,
diff --git a/crates/ra_ide_api/src/status.rs b/crates/ra_ide_api/src/status.rs
index dee2ea46a..f91f16c8e 100644
--- a/crates/ra_ide_api/src/status.rs
+++ b/crates/ra_ide_api/src/status.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use std::{fmt, iter::FromIterator, sync::Arc}; 3use std::{fmt, iter::FromIterator, sync::Arc};
2 4
3use hir::MacroFile; 5use hir::MacroFile;
diff --git a/crates/ra_ide_api/src/symbol_index.rs b/crates/ra_ide_api/src/symbol_index.rs
index 02cdfbc60..797e9926f 100644
--- a/crates/ra_ide_api/src/symbol_index.rs
+++ b/crates/ra_ide_api/src/symbol_index.rs
@@ -32,9 +32,8 @@ use ra_db::{
32 SourceDatabase, SourceRootId, 32 SourceDatabase, SourceRootId,
33}; 33};
34use ra_syntax::{ 34use ra_syntax::{
35 algo::visit::{visitor, Visitor},
36 ast::{self, NameOwner}, 35 ast::{self, NameOwner},
37 AstNode, Parse, SmolStr, SourceFile, 36 match_ast, AstNode, Parse, SmolStr, SourceFile,
38 SyntaxKind::{self, *}, 37 SyntaxKind::{self, *},
39 SyntaxNode, SyntaxNodePtr, TextRange, WalkEvent, 38 SyntaxNode, SyntaxNodePtr, TextRange, WalkEvent,
40}; 39};
@@ -306,16 +305,19 @@ fn to_symbol(node: &SyntaxNode) -> Option<(SmolStr, SyntaxNodePtr, TextRange)> {
306 305
307 Some((name, ptr, name_range)) 306 Some((name, ptr, name_range))
308 } 307 }
309 visitor() 308 match_ast! {
310 .visit(decl::<ast::FnDef>) 309 match node {
311 .visit(decl::<ast::StructDef>) 310 ast::FnDef(it) => { decl(it) },
312 .visit(decl::<ast::EnumDef>) 311 ast::StructDef(it) => { decl(it) },
313 .visit(decl::<ast::TraitDef>) 312 ast::EnumDef(it) => { decl(it) },
314 .visit(decl::<ast::Module>) 313 ast::TraitDef(it) => { decl(it) },
315 .visit(decl::<ast::TypeAliasDef>) 314 ast::Module(it) => { decl(it) },
316 .visit(decl::<ast::ConstDef>) 315 ast::TypeAliasDef(it) => { decl(it) },
317 .visit(decl::<ast::StaticDef>) 316 ast::ConstDef(it) => { decl(it) },
318 .accept(node)? 317 ast::StaticDef(it) => { decl(it) },
318 _ => None,
319 }
320 }
319} 321}
320 322
321fn to_file_symbol(node: &SyntaxNode, file_id: FileId) -> Option<FileSymbol> { 323fn to_file_symbol(node: &SyntaxNode, file_id: FileId) -> Option<FileSymbol> {
diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs
index 3d7f91c1d..9ae2dc061 100644
--- a/crates/ra_ide_api/src/syntax_highlighting.rs
+++ b/crates/ra_ide_api/src/syntax_highlighting.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use rustc_hash::{FxHashMap, FxHashSet}; 3use rustc_hash::{FxHashMap, FxHashSet};
2 4
3use hir::{Mutability, Ty}; 5use hir::{Mutability, Ty};
diff --git a/crates/ra_ide_api/src/syntax_tree.rs b/crates/ra_ide_api/src/syntax_tree.rs
index e2bb120b4..4d0f0fc47 100644
--- a/crates/ra_ide_api/src/syntax_tree.rs
+++ b/crates/ra_ide_api/src/syntax_tree.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use crate::db::RootDatabase; 3use crate::db::RootDatabase;
2use ra_db::SourceDatabase; 4use ra_db::SourceDatabase;
3use ra_syntax::{ 5use ra_syntax::{
diff --git a/crates/ra_ide_api/src/test_utils.rs b/crates/ra_ide_api/src/test_utils.rs
index 6e0d883b4..8adb214d4 100644
--- a/crates/ra_ide_api/src/test_utils.rs
+++ b/crates/ra_ide_api/src/test_utils.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use ra_syntax::{SourceFile, TextUnit}; 3use ra_syntax::{SourceFile, TextUnit};
2use ra_text_edit::TextEdit; 4use ra_text_edit::TextEdit;
3 5
diff --git a/crates/ra_ide_api/src/typing.rs b/crates/ra_ide_api/src/typing.rs
index 2d4491442..2f5782012 100644
--- a/crates/ra_ide_api/src/typing.rs
+++ b/crates/ra_ide_api/src/typing.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use ra_db::{FilePosition, SourceDatabase}; 3use ra_db::{FilePosition, SourceDatabase};
2use ra_fmt::leading_indent; 4use ra_fmt::leading_indent;
3use ra_syntax::{ 5use ra_syntax::{
diff --git a/crates/ra_ide_api/src/wasm_shims.rs b/crates/ra_ide_api/src/wasm_shims.rs
index 592dddf44..088cc9be4 100644
--- a/crates/ra_ide_api/src/wasm_shims.rs
+++ b/crates/ra_ide_api/src/wasm_shims.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1#[cfg(not(feature = "wasm"))] 3#[cfg(not(feature = "wasm"))]
2pub use std::time::Instant; 4pub use std::time::Instant;
3 5