aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-07-04 21:09:32 +0100
committerbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-07-04 21:09:32 +0100
commitcacdb0eab8131bfb945eb7ed0150c92ec56eefe2 (patch)
treef762de90ce813591bc640ae0bce36493a3dcafa9 /crates/ra_ide_api/src
parent4e8664d9d37021e85d72b6228fa45e7edf4a1a74 (diff)
parent1834bae5b86c54ed9dece26e82436919d59e6cb7 (diff)
Merge #1486
1486: allow rustfmt to reorder imports r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r--crates/ra_ide_api/src/assists.rs4
-rw-r--r--crates/ra_ide_api/src/call_info.rs8
-rw-r--r--crates/ra_ide_api/src/change.rs15
-rw-r--r--crates/ra_ide_api/src/completion.rs14
-rw-r--r--crates/ra_ide_api/src/completion/complete_dot.rs4
-rw-r--r--crates/ra_ide_api/src/completion/complete_fn_param.rs5
-rw-r--r--crates/ra_ide_api/src/completion/complete_keyword.rs9
-rw-r--r--crates/ra_ide_api/src/completion/complete_path.rs6
-rw-r--r--crates/ra_ide_api/src/completion/complete_pattern.rs2
-rw-r--r--crates/ra_ide_api/src/completion/complete_postfix.rs15
-rw-r--r--crates/ra_ide_api/src/completion/complete_scope.rs10
-rw-r--r--crates/ra_ide_api/src/completion/complete_snippet.rs7
-rw-r--r--crates/ra_ide_api/src/completion/complete_struct_literal.rs2
-rw-r--r--crates/ra_ide_api/src/completion/completion_context.rs10
-rw-r--r--crates/ra_ide_api/src/completion/completion_item.rs4
-rw-r--r--crates/ra_ide_api/src/completion/presentation.rs12
-rw-r--r--crates/ra_ide_api/src/db.rs12
-rw-r--r--crates/ra_ide_api/src/diagnostics.rs17
-rw-r--r--crates/ra_ide_api/src/display.rs11
-rw-r--r--crates/ra_ide_api/src/display/function_signature.rs7
-rw-r--r--crates/ra_ide_api/src/display/navigation_target.rs11
-rw-r--r--crates/ra_ide_api/src/display/short_label.rs4
-rw-r--r--crates/ra_ide_api/src/display/structure.rs2
-rw-r--r--crates/ra_ide_api/src/extend_selection.rs10
-rw-r--r--crates/ra_ide_api/src/folding_ranges.rs5
-rw-r--r--crates/ra_ide_api/src/goto_definition.rs9
-rw-r--r--crates/ra_ide_api/src/goto_type_definition.rs7
-rw-r--r--crates/ra_ide_api/src/hover.rs22
-rw-r--r--crates/ra_ide_api/src/impls.rs9
-rw-r--r--crates/ra_ide_api/src/join_lines.rs11
-rw-r--r--crates/ra_ide_api/src/lib.rs28
-rw-r--r--crates/ra_ide_api/src/line_index.rs2
-rw-r--r--crates/ra_ide_api/src/line_index_utils.rs6
-rw-r--r--crates/ra_ide_api/src/matching_brace.rs8
-rw-r--r--crates/ra_ide_api/src/mock_analysis.rs5
-rw-r--r--crates/ra_ide_api/src/name_ref_kind.rs2
-rw-r--r--crates/ra_ide_api/src/parent_module.rs8
-rw-r--r--crates/ra_ide_api/src/references.rs30
-rw-r--r--crates/ra_ide_api/src/runnables.rs6
-rw-r--r--crates/ra_ide_api/src/status.rs22
-rw-r--r--crates/ra_ide_api/src/symbol_index.rs36
-rw-r--r--crates/ra_ide_api/src/syntax_highlighting.rs14
-rw-r--r--crates/ra_ide_api/src/syntax_tree.rs8
-rw-r--r--crates/ra_ide_api/src/typing.rs11
44 files changed, 215 insertions, 235 deletions
diff --git a/crates/ra_ide_api/src/assists.rs b/crates/ra_ide_api/src/assists.rs
index 355c0a42a..e3d1ac529 100644
--- a/crates/ra_ide_api/src/assists.rs
+++ b/crates/ra_ide_api/src/assists.rs
@@ -1,6 +1,6 @@
1use ra_db::{FileRange, FilePosition}; 1use ra_db::{FilePosition, FileRange};
2 2
3use crate::{SourceFileEdit, SourceChange, db::RootDatabase}; 3use crate::{db::RootDatabase, SourceChange, SourceFileEdit};
4 4
5pub use ra_assists::AssistId; 5pub use ra_assists::AssistId;
6 6
diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs
index 2948c646b..368fdcaa1 100644
--- a/crates/ra_ide_api/src/call_info.rs
+++ b/crates/ra_ide_api/src/call_info.rs
@@ -1,12 +1,12 @@
1use test_utils::tested_by;
2use ra_db::SourceDatabase; 1use ra_db::SourceDatabase;
3use ra_syntax::{ 2use ra_syntax::{
4 AstNode, SyntaxNode, TextUnit,
5 ast::{self, ArgListOwner},
6 algo::find_node_at_offset, 3 algo::find_node_at_offset,
4 ast::{self, ArgListOwner},
5 AstNode, SyntaxNode, TextUnit,
7}; 6};
7use test_utils::tested_by;
8 8
9use crate::{FilePosition, CallInfo, FunctionSignature, db::RootDatabase}; 9use crate::{db::RootDatabase, CallInfo, FilePosition, FunctionSignature};
10 10
11/// Computes parameter information for the given call expression. 11/// Computes parameter information for the given call expression.
12pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<CallInfo> { 12pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<CallInfo> {
diff --git a/crates/ra_ide_api/src/change.rs b/crates/ra_ide_api/src/change.rs
index c0c289335..2a1af0a0a 100644
--- a/crates/ra_ide_api/src/change.rs
+++ b/crates/ra_ide_api/src/change.rs
@@ -1,22 +1,19 @@
1use std::{ 1use std::{fmt, sync::Arc, time};
2 fmt, time,
3 sync::Arc,
4};
5 2
6use rustc_hash::FxHashMap;
7use ra_db::{ 3use ra_db::{
8 SourceRootId, FileId, CrateGraph, SourceDatabase, SourceRoot,
9 salsa::{Database, SweepStrategy}, 4 salsa::{Database, SweepStrategy},
5 CrateGraph, FileId, SourceDatabase, SourceRoot, SourceRootId,
10}; 6};
7use ra_prof::{memory_usage, profile, Bytes};
11use ra_syntax::SourceFile; 8use ra_syntax::SourceFile;
12use ra_prof::{profile, Bytes, memory_usage};
13use relative_path::RelativePathBuf;
14use rayon::prelude::*; 9use rayon::prelude::*;
10use relative_path::RelativePathBuf;
11use rustc_hash::FxHashMap;
15 12
16use crate::{ 13use crate::{
17 db::RootDatabase, 14 db::RootDatabase,
18 symbol_index::{SymbolIndex, SymbolsDatabase},
19 status::syntax_tree_stats, 15 status::syntax_tree_stats,
16 symbol_index::{SymbolIndex, SymbolsDatabase},
20}; 17};
21 18
22#[derive(Default)] 19#[derive(Default)]
diff --git a/crates/ra_ide_api/src/completion.rs b/crates/ra_ide_api/src/completion.rs
index 3a75bbf92..c23b5da59 100644
--- a/crates/ra_ide_api/src/completion.rs
+++ b/crates/ra_ide_api/src/completion.rs
@@ -14,19 +14,19 @@ mod complete_postfix;
14 14
15use ra_db::SourceDatabase; 15use ra_db::SourceDatabase;
16 16
17#[cfg(test)]
18use crate::completion::completion_item::{check_completion, do_completion};
17use crate::{ 19use crate::{
18 db,
19 FilePosition,
20 completion::{ 20 completion::{
21 completion_item::{Completions, CompletionKind},
22 completion_context::CompletionContext, 21 completion_context::CompletionContext,
22 completion_item::{CompletionKind, Completions},
23 }, 23 },
24 24 db, FilePosition,
25}; 25};
26#[cfg(test)]
27use crate::completion::completion_item::{do_completion, check_completion};
28 26
29pub use crate::completion::completion_item::{CompletionItem, CompletionItemKind, InsertTextFormat}; 27pub use crate::completion::completion_item::{
28 CompletionItem, CompletionItemKind, InsertTextFormat,
29};
30 30
31/// Main entry point for completion. We run completion as a two-phase process. 31/// Main entry point for completion. We run completion as a two-phase process.
32/// 32///
diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs
index a97e876e9..a5f071442 100644
--- a/crates/ra_ide_api/src/completion/complete_dot.rs
+++ b/crates/ra_ide_api/src/completion/complete_dot.rs
@@ -1,4 +1,4 @@
1use hir::{Ty, AdtDef, TypeCtor}; 1use hir::{AdtDef, Ty, TypeCtor};
2 2
3use crate::completion::{CompletionContext, Completions}; 3use crate::completion::{CompletionContext, Completions};
4use rustc_hash::FxHashSet; 4use rustc_hash::FxHashSet;
@@ -49,7 +49,7 @@ fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty
49 49
50#[cfg(test)] 50#[cfg(test)]
51mod tests { 51mod tests {
52 use crate::completion::{do_completion, CompletionKind, CompletionItem}; 52 use crate::completion::{do_completion, CompletionItem, CompletionKind};
53 use insta::assert_debug_snapshot_matches; 53 use insta::assert_debug_snapshot_matches;
54 54
55 fn do_ref_completion(code: &str) -> Vec<CompletionItem> { 55 fn do_ref_completion(code: &str) -> Vec<CompletionItem> {
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 d738ffc13..5a117c485 100644
--- a/crates/ra_ide_api/src/completion/complete_fn_param.rs
+++ b/crates/ra_ide_api/src/completion/complete_fn_param.rs
@@ -1,11 +1,10 @@
1use ra_syntax::{ 1use ra_syntax::{
2 algo::visit::{visitor_ctx, VisitorCtx}, 2 algo::visit::{visitor_ctx, VisitorCtx},
3 ast, 3 ast, AstNode,
4 AstNode,
5}; 4};
6use rustc_hash::FxHashMap; 5use rustc_hash::FxHashMap;
7 6
8use crate::completion::{CompletionContext, Completions, CompletionKind, CompletionItem}; 7use crate::completion::{CompletionContext, CompletionItem, CompletionKind, Completions};
9 8
10/// Complete repeated parameters, both name and type. For example, if all 9/// Complete repeated parameters, both name and type. For example, if all
11/// functions in a file have a `spam: &mut Spam` parameter, a completion with 10/// functions in a file have a `spam: &mut Spam` parameter, a completion with
diff --git a/crates/ra_ide_api/src/completion/complete_keyword.rs b/crates/ra_ide_api/src/completion/complete_keyword.rs
index cfb9fd6e8..034ed934d 100644
--- a/crates/ra_ide_api/src/completion/complete_keyword.rs
+++ b/crates/ra_ide_api/src/completion/complete_keyword.rs
@@ -1,11 +1,14 @@
1use ra_syntax::{ 1use ra_syntax::{
2 algo::visit::{visitor, Visitor}, 2 algo::visit::{visitor, Visitor},
3 AstNode,
4 ast::{self, LoopBodyOwner}, 3 ast::{self, LoopBodyOwner},
5 SyntaxKind::*, SyntaxToken, 4 AstNode,
5 SyntaxKind::*,
6 SyntaxToken,
6}; 7};
7 8
8use crate::completion::{CompletionContext, CompletionItem, Completions, CompletionKind, CompletionItemKind}; 9use crate::completion::{
10 CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, Completions,
11};
9 12
10pub(super) fn complete_use_tree_keyword(acc: &mut Completions, ctx: &CompletionContext) { 13pub(super) fn complete_use_tree_keyword(acc: &mut Completions, ctx: &CompletionContext) {
11 // complete keyword "crate" in use stmt 14 // complete keyword "crate" in use stmt
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs
index da8fb9d8e..29586cd1f 100644
--- a/crates/ra_ide_api/src/completion/complete_path.rs
+++ b/crates/ra_ide_api/src/completion/complete_path.rs
@@ -1,8 +1,8 @@
1use hir::{Resolution, Either}; 1use hir::{Either, Resolution};
2use ra_syntax::AstNode; 2use ra_syntax::AstNode;
3use test_utils::tested_by; 3use test_utils::tested_by;
4 4
5use crate::completion::{Completions, CompletionContext}; 5use crate::completion::{CompletionContext, Completions};
6 6
7pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { 7pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
8 let path = match &ctx.path_prefix { 8 let path = match &ctx.path_prefix {
@@ -78,7 +78,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
78mod tests { 78mod tests {
79 use test_utils::covers; 79 use test_utils::covers;
80 80
81 use crate::completion::{CompletionKind, do_completion, CompletionItem}; 81 use crate::completion::{do_completion, CompletionItem, CompletionKind};
82 use insta::assert_debug_snapshot_matches; 82 use insta::assert_debug_snapshot_matches;
83 83
84 fn do_reference_completion(code: &str) -> Vec<CompletionItem> { 84 fn do_reference_completion(code: &str) -> Vec<CompletionItem> {
diff --git a/crates/ra_ide_api/src/completion/complete_pattern.rs b/crates/ra_ide_api/src/completion/complete_pattern.rs
index 6655a05a7..f12dfcc17 100644
--- a/crates/ra_ide_api/src/completion/complete_pattern.rs
+++ b/crates/ra_ide_api/src/completion/complete_pattern.rs
@@ -27,8 +27,8 @@ pub(super) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) {
27 27
28#[cfg(test)] 28#[cfg(test)]
29mod tests { 29mod tests {
30 use crate::completion::{do_completion, CompletionItem, CompletionKind};
30 use insta::assert_debug_snapshot_matches; 31 use insta::assert_debug_snapshot_matches;
31 use crate::completion::{CompletionItem, CompletionKind, do_completion};
32 32
33 fn complete(code: &str) -> Vec<CompletionItem> { 33 fn complete(code: &str) -> Vec<CompletionItem> {
34 do_completion(code, CompletionKind::Reference) 34 do_completion(code, CompletionKind::Reference)
diff --git a/crates/ra_ide_api/src/completion/complete_postfix.rs b/crates/ra_ide_api/src/completion/complete_postfix.rs
index e20a12e2a..7042d8bff 100644
--- a/crates/ra_ide_api/src/completion/complete_postfix.rs
+++ b/crates/ra_ide_api/src/completion/complete_postfix.rs
@@ -1,18 +1,11 @@
1use crate::{ 1use crate::{
2 completion::{ 2 completion::{
3 completion_item::{
4 Completions,
5 Builder,
6 CompletionKind,
7 },
8 completion_context::CompletionContext, 3 completion_context::CompletionContext,
4 completion_item::{Builder, CompletionKind, Completions},
9 }, 5 },
10 CompletionItem 6 CompletionItem,
11};
12use ra_syntax::{
13 ast::AstNode,
14 TextRange
15}; 7};
8use ra_syntax::{ast::AstNode, TextRange};
16use ra_text_edit::TextEditBuilder; 9use ra_text_edit::TextEditBuilder;
17 10
18fn postfix_snippet(ctx: &CompletionContext, label: &str, detail: &str, snippet: &str) -> Builder { 11fn postfix_snippet(ctx: &CompletionContext, label: &str, detail: &str, snippet: &str) -> Builder {
@@ -58,7 +51,7 @@ pub(super) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) {
58 51
59#[cfg(test)] 52#[cfg(test)]
60mod tests { 53mod tests {
61 use crate::completion::{CompletionKind, check_completion}; 54 use crate::completion::{check_completion, CompletionKind};
62 55
63 fn check_snippet_completion(test_name: &str, code: &str) { 56 fn check_snippet_completion(test_name: &str, code: &str) {
64 check_completion(test_name, code, CompletionKind::Postfix); 57 check_completion(test_name, code, CompletionKind::Postfix);
diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs
index 0f8cfaae8..1ba871257 100644
--- a/crates/ra_ide_api/src/completion/complete_scope.rs
+++ b/crates/ra_ide_api/src/completion/complete_scope.rs
@@ -1,9 +1,9 @@
1use rustc_hash::FxHashMap;
2use ra_text_edit::TextEditBuilder;
3use ra_syntax::{SmolStr, ast, AstNode};
4use ra_assists::auto_import; 1use ra_assists::auto_import;
2use ra_syntax::{ast, AstNode, SmolStr};
3use ra_text_edit::TextEditBuilder;
4use rustc_hash::FxHashMap;
5 5
6use crate::completion::{CompletionItem, Completions, CompletionKind, CompletionContext}; 6use crate::completion::{CompletionContext, CompletionItem, CompletionKind, Completions};
7 7
8pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) { 8pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) {
9 if ctx.is_trivial_path { 9 if ctx.is_trivial_path {
@@ -121,7 +121,7 @@ impl ImportResolver {
121 121
122#[cfg(test)] 122#[cfg(test)]
123mod tests { 123mod tests {
124 use crate::completion::{CompletionKind, check_completion}; 124 use crate::completion::{check_completion, CompletionKind};
125 125
126 fn check_reference_completion(name: &str, code: &str) { 126 fn check_reference_completion(name: &str, code: &str) {
127 check_completion(name, code, CompletionKind::Reference); 127 check_completion(name, code, CompletionKind::Reference);
diff --git a/crates/ra_ide_api/src/completion/complete_snippet.rs b/crates/ra_ide_api/src/completion/complete_snippet.rs
index e1df9e625..d2d364b57 100644
--- a/crates/ra_ide_api/src/completion/complete_snippet.rs
+++ b/crates/ra_ide_api/src/completion/complete_snippet.rs
@@ -1,4 +1,7 @@
1use crate::completion::{CompletionItem, Completions, CompletionKind, CompletionItemKind, CompletionContext, completion_item::Builder}; 1use crate::completion::{
2 completion_item::Builder, CompletionContext, CompletionItem, CompletionItemKind,
3 CompletionKind, Completions,
4};
2 5
3fn snippet(ctx: &CompletionContext, label: &str, snippet: &str) -> Builder { 6fn snippet(ctx: &CompletionContext, label: &str, snippet: &str) -> Builder {
4 CompletionItem::new(CompletionKind::Snippet, ctx.source_range(), label) 7 CompletionItem::new(CompletionKind::Snippet, ctx.source_range(), label)
@@ -36,7 +39,7 @@ fn ${1:feature}() {
36 39
37#[cfg(test)] 40#[cfg(test)]
38mod tests { 41mod tests {
39 use crate::completion::{CompletionKind, check_completion}; 42 use crate::completion::{check_completion, CompletionKind};
40 43
41 fn check_snippet_completion(name: &str, code: &str) { 44 fn check_snippet_completion(name: &str, code: &str) {
42 check_completion(name, code, CompletionKind::Snippet); 45 check_completion(name, code, CompletionKind::Snippet);
diff --git a/crates/ra_ide_api/src/completion/complete_struct_literal.rs b/crates/ra_ide_api/src/completion/complete_struct_literal.rs
index 1eeea58f6..35fb21113 100644
--- a/crates/ra_ide_api/src/completion/complete_struct_literal.rs
+++ b/crates/ra_ide_api/src/completion/complete_struct_literal.rs
@@ -27,8 +27,8 @@ pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionCon
27 27
28#[cfg(test)] 28#[cfg(test)]
29mod tests { 29mod tests {
30 use crate::completion::{do_completion, CompletionItem, CompletionKind};
30 use insta::assert_debug_snapshot_matches; 31 use insta::assert_debug_snapshot_matches;
31 use crate::completion::{CompletionItem, CompletionKind, do_completion};
32 32
33 fn complete(code: &str) -> Vec<CompletionItem> { 33 fn complete(code: &str) -> Vec<CompletionItem> {
34 do_completion(code, CompletionKind::Reference) 34 do_completion(code, CompletionKind::Reference)
diff --git a/crates/ra_ide_api/src/completion/completion_context.rs b/crates/ra_ide_api/src/completion/completion_context.rs
index bda7d9bb2..55fdba50d 100644
--- a/crates/ra_ide_api/src/completion/completion_context.rs
+++ b/crates/ra_ide_api/src/completion/completion_context.rs
@@ -1,11 +1,11 @@
1use ra_text_edit::AtomTextEdit; 1use hir::source_binder;
2use ra_syntax::{ 2use ra_syntax::{
3 AstNode, SyntaxNode, SourceFile, TextUnit, TextRange, SyntaxToken, Parse, 3 algo::{find_covering_element, find_node_at_offset, find_token_at_offset},
4 ast, 4 ast, AstNode, Parse, SourceFile,
5 algo::{find_token_at_offset, find_covering_element, find_node_at_offset},
6 SyntaxKind::*, 5 SyntaxKind::*,
6 SyntaxNode, SyntaxToken, TextRange, TextUnit,
7}; 7};
8use hir::source_binder; 8use ra_text_edit::AtomTextEdit;
9 9
10use crate::{db, FilePosition}; 10use crate::{db, FilePosition};
11 11
diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs
index 6f2a60640..f78c4c877 100644
--- a/crates/ra_ide_api/src/completion/completion_item.rs
+++ b/crates/ra_ide_api/src/completion/completion_item.rs
@@ -2,7 +2,7 @@ use std::fmt;
2 2
3use hir::Documentation; 3use hir::Documentation;
4use ra_syntax::TextRange; 4use ra_syntax::TextRange;
5use ra_text_edit::{TextEditBuilder, TextEdit}; 5use ra_text_edit::{TextEdit, TextEditBuilder};
6 6
7/// `CompletionItem` describes a single completion variant in the editor pop-up. 7/// `CompletionItem` describes a single completion variant in the editor pop-up.
8/// It is basically a POD with various properties. To construct a 8/// It is basically a POD with various properties. To construct a
@@ -285,8 +285,8 @@ impl Into<Vec<CompletionItem>> for Completions {
285 285
286#[cfg(test)] 286#[cfg(test)]
287pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec<CompletionItem> { 287pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec<CompletionItem> {
288 use crate::mock_analysis::{single_file_with_position, analysis_and_position};
289 use crate::completion::completions; 288 use crate::completion::completions;
289 use crate::mock_analysis::{analysis_and_position, single_file_with_position};
290 let (analysis, position) = if code.contains("//-") { 290 let (analysis, position) = if code.contains("//-") {
291 analysis_and_position(code) 291 analysis_and_position(code)
292 } else { 292 } else {
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs
index 973936736..98060947a 100644
--- a/crates/ra_ide_api/src/completion/presentation.rs
+++ b/crates/ra_ide_api/src/completion/presentation.rs
@@ -1,16 +1,14 @@
1//! This modules takes care of rendering various defenitions as completion items. 1//! This modules takes care of rendering various defenitions as completion items.
2use hir::{Docs, HasSource, HirDisplay, PerNs, Resolution};
2use join_to_string::join; 3use join_to_string::join;
3use test_utils::tested_by;
4use hir::{Docs, PerNs, Resolution, HirDisplay, HasSource};
5use ra_syntax::ast::NameOwner; 4use ra_syntax::ast::NameOwner;
5use test_utils::tested_by;
6 6
7use crate::completion::{ 7use crate::completion::{
8 Completions, CompletionKind, CompletionItemKind, CompletionContext, CompletionItem, 8 CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, Completions,
9}; 9};
10 10
11use crate::display::{ 11use crate::display::{const_label, function_label, type_label};
12 function_label, const_label, type_label,
13};
14 12
15impl Completions { 13impl Completions {
16 pub(crate) fn add_field( 14 pub(crate) fn add_field(
@@ -178,7 +176,7 @@ impl Completions {
178mod tests { 176mod tests {
179 use test_utils::covers; 177 use test_utils::covers;
180 178
181 use crate::completion::{CompletionKind, check_completion}; 179 use crate::completion::{check_completion, CompletionKind};
182 180
183 fn check_reference_completion(code: &str, expected_completions: &str) { 181 fn check_reference_completion(code: &str, expected_completions: &str) {
184 check_completion(code, expected_completions, CompletionKind::Reference); 182 check_completion(code, expected_completions, CompletionKind::Reference);
diff --git a/crates/ra_ide_api/src/db.rs b/crates/ra_ide_api/src/db.rs
index 94977764c..fc5b06ca8 100644
--- a/crates/ra_ide_api/src/db.rs
+++ b/crates/ra_ide_api/src/db.rs
@@ -1,14 +1,14 @@
1use std::{ 1use std::{sync::Arc, time};
2 sync::Arc,
3 time,
4};
5 2
6use ra_db::{ 3use ra_db::{
7 CheckCanceled, FileId, Canceled, SourceDatabase,
8 salsa::{self, Database}, 4 salsa::{self, Database},
5 Canceled, CheckCanceled, FileId, SourceDatabase,
9}; 6};
10 7
11use crate::{LineIndex, symbol_index::{self, SymbolsDatabase}}; 8use crate::{
9 symbol_index::{self, SymbolsDatabase},
10 LineIndex,
11};
12 12
13#[salsa::database( 13#[salsa::database(
14 ra_db::SourceDatabaseStorage, 14 ra_db::SourceDatabaseStorage,
diff --git a/crates/ra_ide_api/src/diagnostics.rs b/crates/ra_ide_api/src/diagnostics.rs
index 35b3d77df..9ab455b0e 100644
--- a/crates/ra_ide_api/src/diagnostics.rs
+++ b/crates/ra_ide_api/src/diagnostics.rs
@@ -1,17 +1,20 @@
1use std::cell::RefCell; 1use std::cell::RefCell;
2 2
3use hir::{
4 diagnostics::{Diagnostic as _, DiagnosticSink},
5 source_binder,
6};
3use itertools::Itertools; 7use itertools::Itertools;
4use hir::{source_binder, diagnostics::{Diagnostic as _, DiagnosticSink}}; 8use ra_assists::ast_editor::{AstBuilder, AstEditor};
5use ra_db::SourceDatabase; 9use ra_db::SourceDatabase;
10use ra_prof::profile;
6use ra_syntax::{ 11use ra_syntax::{
7 T, Location, TextRange, SyntaxNode, 12 ast::{self, AstNode, NamedField, NamedFieldList},
8 ast::{self, AstNode, NamedFieldList, NamedField}, 13 Location, SyntaxNode, TextRange, T,
9}; 14};
10use ra_assists::ast_editor::{AstEditor, AstBuilder};
11use ra_text_edit::{TextEdit, TextEditBuilder}; 15use ra_text_edit::{TextEdit, TextEditBuilder};
12use ra_prof::profile;
13 16
14use crate::{Diagnostic, FileId, FileSystemEdit, SourceChange, SourceFileEdit, db::RootDatabase}; 17use crate::{db::RootDatabase, Diagnostic, FileId, FileSystemEdit, SourceChange, SourceFileEdit};
15 18
16#[derive(Debug, Copy, Clone)] 19#[derive(Debug, Copy, Clone)]
17pub enum Severity { 20pub enum Severity {
@@ -170,9 +173,9 @@ fn check_struct_shorthand_initialization(
170 173
171#[cfg(test)] 174#[cfg(test)]
172mod tests { 175mod tests {
173 use test_utils::assert_eq_text;
174 use insta::assert_debug_snapshot_matches; 176 use insta::assert_debug_snapshot_matches;
175 use ra_syntax::SourceFile; 177 use ra_syntax::SourceFile;
178 use test_utils::assert_eq_text;
176 179
177 use crate::mock_analysis::single_file; 180 use crate::mock_analysis::single_file;
178 181
diff --git a/crates/ra_ide_api/src/display.rs b/crates/ra_ide_api/src/display.rs
index 882518838..cc59e99d8 100644
--- a/crates/ra_ide_api/src/display.rs
+++ b/crates/ra_ide_api/src/display.rs
@@ -6,14 +6,17 @@ mod navigation_target;
6mod structure; 6mod structure;
7mod short_label; 7mod short_label;
8 8
9use ra_syntax::{ast::{self, AstNode, TypeParamsOwner}, SyntaxKind::{ATTR, COMMENT}}; 9use ra_syntax::{
10 ast::{self, AstNode, TypeParamsOwner},
11 SyntaxKind::{ATTR, COMMENT},
12};
10 13
11pub use navigation_target::NavigationTarget;
12pub use structure::{StructureNode, file_structure};
13pub use function_signature::FunctionSignature; 14pub use function_signature::FunctionSignature;
15pub use navigation_target::NavigationTarget;
16pub use structure::{file_structure, StructureNode};
14 17
18pub(crate) use navigation_target::{description_from_symbol, docs_from_symbol};
15pub(crate) use short_label::ShortLabel; 19pub(crate) use short_label::ShortLabel;
16pub(crate) use navigation_target::{docs_from_symbol, description_from_symbol};
17 20
18pub(crate) fn function_label(node: &ast::FnDef) -> String { 21pub(crate) fn function_label(node: &ast::FnDef) -> String {
19 FunctionSignature::from(node).to_string() 22 FunctionSignature::from(node).to_string()
diff --git a/crates/ra_ide_api/src/display/function_signature.rs b/crates/ra_ide_api/src/display/function_signature.rs
index b0b0c7122..e7ad5a0d1 100644
--- a/crates/ra_ide_api/src/display/function_signature.rs
+++ b/crates/ra_ide_api/src/display/function_signature.rs
@@ -1,11 +1,14 @@
1use std::fmt::{self, Display}; 1use std::fmt::{self, Display};
2 2
3use hir::{Docs, Documentation, HasSource};
3use join_to_string::join; 4use join_to_string::join;
4use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner}; 5use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner};
5use std::convert::From; 6use std::convert::From;
6use hir::{Docs, Documentation, HasSource};
7 7
8use crate::{db, display::{where_predicates, generic_parameters}}; 8use crate::{
9 db,
10 display::{generic_parameters, where_predicates},
11};
9 12
10/// Contains information about a function signature 13/// Contains information about a function signature
11#[derive(Debug)] 14#[derive(Debug)]
diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs
index 823cdaaf3..1edb64e3d 100644
--- a/crates/ra_ide_api/src/display/navigation_target.rs
+++ b/crates/ra_ide_api/src/display/navigation_target.rs
@@ -1,14 +1,15 @@
1use hir::{FieldSource, HasSource, ImplItem, ModuleSource};
1use ra_db::{FileId, SourceDatabase}; 2use ra_db::{FileId, SourceDatabase};
2use ra_syntax::{ 3use ra_syntax::{
3 SyntaxNode, AstNode, SmolStr, TextRange, AstPtr, TreeArc,
4 SyntaxKind::{self, NAME},
5 ast::{self, DocCommentsOwner},
6 algo::visit::{visitor, Visitor}, 4 algo::visit::{visitor, Visitor},
5 ast::{self, DocCommentsOwner},
6 AstNode, AstPtr, SmolStr,
7 SyntaxKind::{self, NAME},
8 SyntaxNode, TextRange, TreeArc,
7}; 9};
8use hir::{ModuleSource, FieldSource, ImplItem, HasSource};
9 10
10use crate::{FileSymbol, db::RootDatabase};
11use super::short_label::ShortLabel; 11use super::short_label::ShortLabel;
12use crate::{db::RootDatabase, FileSymbol};
12 13
13/// `NavigationTarget` represents and element in the editor's UI which you can 14/// `NavigationTarget` represents and element in the editor's UI which you can
14/// click on to navigate to a particular piece of code. 15/// click on to navigate to a particular piece of code.
diff --git a/crates/ra_ide_api/src/display/short_label.rs b/crates/ra_ide_api/src/display/short_label.rs
index dc8245c34..f926f631f 100644
--- a/crates/ra_ide_api/src/display/short_label.rs
+++ b/crates/ra_ide_api/src/display/short_label.rs
@@ -1,6 +1,4 @@
1use ra_syntax::{ 1use ra_syntax::ast::{self, AstNode, NameOwner, TypeAscriptionOwner, VisibilityOwner};
2 ast::{self, NameOwner, VisibilityOwner, TypeAscriptionOwner, AstNode},
3};
4 2
5pub(crate) trait ShortLabel { 3pub(crate) trait ShortLabel {
6 fn short_label(&self) -> Option<String>; 4 fn short_label(&self) -> Option<String>;
diff --git a/crates/ra_ide_api/src/display/structure.rs b/crates/ra_ide_api/src/display/structure.rs
index e5057e833..e5b257b9b 100644
--- a/crates/ra_ide_api/src/display/structure.rs
+++ b/crates/ra_ide_api/src/display/structure.rs
@@ -2,7 +2,7 @@ use crate::TextRange;
2 2
3use ra_syntax::{ 3use ra_syntax::{
4 algo::visit::{visitor, Visitor}, 4 algo::visit::{visitor, Visitor},
5 ast::{self, AttrsOwner, NameOwner, TypeParamsOwner, TypeAscriptionOwner}, 5 ast::{self, AttrsOwner, NameOwner, TypeAscriptionOwner, TypeParamsOwner},
6 AstNode, SourceFile, SyntaxKind, SyntaxNode, WalkEvent, 6 AstNode, SourceFile, SyntaxKind, SyntaxNode, WalkEvent,
7}; 7};
8 8
diff --git a/crates/ra_ide_api/src/extend_selection.rs b/crates/ra_ide_api/src/extend_selection.rs
index a713b762c..655852514 100644
--- a/crates/ra_ide_api/src/extend_selection.rs
+++ b/crates/ra_ide_api/src/extend_selection.rs
@@ -1,13 +1,13 @@
1use ra_db::SourceDatabase; 1use ra_db::SourceDatabase;
2use ra_syntax::{ 2use ra_syntax::{
3 Direction, SyntaxNode, TextRange, TextUnit, SyntaxElement,
4 algo::{find_covering_element, find_token_at_offset, TokenAtOffset}, 3 algo::{find_covering_element, find_token_at_offset, TokenAtOffset},
5 SyntaxKind::*, SyntaxToken,
6 ast::{self, AstNode, AstToken}, 4 ast::{self, AstNode, AstToken},
7 T 5 Direction, SyntaxElement,
6 SyntaxKind::*,
7 SyntaxNode, SyntaxToken, TextRange, TextUnit, T,
8}; 8};
9 9
10use crate::{FileRange, db::RootDatabase}; 10use crate::{db::RootDatabase, FileRange};
11 11
12// FIXME: restore macro support 12// FIXME: restore macro support
13pub(crate) fn extend_selection(db: &RootDatabase, frange: FileRange) -> TextRange { 13pub(crate) fn extend_selection(db: &RootDatabase, frange: FileRange) -> TextRange {
@@ -205,7 +205,7 @@ fn adj_comments(comment: ast::Comment, dir: Direction) -> ast::Comment {
205 205
206#[cfg(test)] 206#[cfg(test)]
207mod tests { 207mod tests {
208 use ra_syntax::{SourceFile, AstNode}; 208 use ra_syntax::{AstNode, SourceFile};
209 use test_utils::extract_offset; 209 use test_utils::extract_offset;
210 210
211 use super::*; 211 use super::*;
diff --git a/crates/ra_ide_api/src/folding_ranges.rs b/crates/ra_ide_api/src/folding_ranges.rs
index 4400ff232..a1e6f94e0 100644
--- a/crates/ra_ide_api/src/folding_ranges.rs
+++ b/crates/ra_ide_api/src/folding_ranges.rs
@@ -1,9 +1,10 @@
1use rustc_hash::FxHashSet; 1use rustc_hash::FxHashSet;
2 2
3use ra_syntax::{ 3use ra_syntax::{
4 SourceFile, SyntaxNode, TextRange, Direction, SyntaxElement,
5 SyntaxKind::{self, *},
6 ast::{self, AstNode, AstToken, VisibilityOwner}, 4 ast::{self, AstNode, AstToken, VisibilityOwner},
5 Direction, SourceFile, SyntaxElement,
6 SyntaxKind::{self, *},
7 SyntaxNode, TextRange,
7}; 8};
8 9
9#[derive(Debug, PartialEq, Eq)] 10#[derive(Debug, PartialEq, Eq)]
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs
index 63ba6cf9d..08feed7dc 100644
--- a/crates/ra_ide_api/src/goto_definition.rs
+++ b/crates/ra_ide_api/src/goto_definition.rs
@@ -1,19 +1,18 @@
1use ra_db::{FileId, SourceDatabase}; 1use ra_db::{FileId, SourceDatabase};
2use ra_syntax::{ 2use ra_syntax::{
3 AstNode, ast::{self, DocCommentsOwner},
4 algo::{ 3 algo::{
5 find_node_at_offset, 4 find_node_at_offset,
6 visit::{visitor, Visitor}, 5 visit::{visitor, Visitor},
7 }, 6 },
8 SyntaxNode, 7 ast::{self, DocCommentsOwner},
8 AstNode, SyntaxNode,
9}; 9};
10 10
11use crate::{ 11use crate::{
12 FilePosition, NavigationTarget,
13 db::RootDatabase, 12 db::RootDatabase,
14 RangeInfo,
15 name_ref_kind::{NameRefKind::*, classify_name_ref},
16 display::ShortLabel, 13 display::ShortLabel,
14 name_ref_kind::{classify_name_ref, NameRefKind::*},
15 FilePosition, NavigationTarget, RangeInfo,
17}; 16};
18 17
19pub(crate) fn goto_definition( 18pub(crate) fn goto_definition(
diff --git a/crates/ra_ide_api/src/goto_type_definition.rs b/crates/ra_ide_api/src/goto_type_definition.rs
index 6f5164e0b..d2d5eae9a 100644
--- a/crates/ra_ide_api/src/goto_type_definition.rs
+++ b/crates/ra_ide_api/src/goto_type_definition.rs
@@ -1,10 +1,7 @@
1use ra_db::SourceDatabase; 1use ra_db::SourceDatabase;
2use ra_syntax::{ 2use ra_syntax::{algo::find_token_at_offset, ast, AstNode};
3 AstNode, ast,
4 algo::find_token_at_offset
5};
6 3
7use crate::{FilePosition, NavigationTarget, db::RootDatabase, RangeInfo}; 4use crate::{db::RootDatabase, FilePosition, NavigationTarget, RangeInfo};
8 5
9pub(crate) fn goto_type_definition( 6pub(crate) fn goto_type_definition(
10 db: &RootDatabase, 7 db: &RootDatabase,
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs
index df877c324..1edeb7579 100644
--- a/crates/ra_ide_api/src/hover.rs
+++ b/crates/ra_ide_api/src/hover.rs
@@ -1,16 +1,22 @@
1use hir::{HasSource, HirDisplay};
1use ra_db::SourceDatabase; 2use ra_db::SourceDatabase;
2use ra_syntax::{ 3use ra_syntax::{
3 AstNode, TreeArc, 4 algo::{
5 ancestors_at_offset, find_covering_element, find_node_at_offset,
6 visit::{visitor, Visitor},
7 },
4 ast::{self, DocCommentsOwner}, 8 ast::{self, DocCommentsOwner},
5 algo::{find_covering_element, find_node_at_offset, ancestors_at_offset, visit::{visitor, Visitor}}, 9 AstNode, TreeArc,
6}; 10};
7use hir::{HirDisplay, HasSource};
8 11
9use crate::{ 12use crate::{
10 db::RootDatabase, 13 db::RootDatabase,
11 RangeInfo, FilePosition, FileRange, 14 display::{
12 display::{rust_code_markup, rust_code_markup_with_doc, ShortLabel, docs_from_symbol, description_from_symbol}, 15 description_from_symbol, docs_from_symbol, rust_code_markup, rust_code_markup_with_doc,
13 name_ref_kind::{NameRefKind::*, classify_name_ref}, 16 ShortLabel,
17 },
18 name_ref_kind::{classify_name_ref, NameRefKind::*},
19 FilePosition, FileRange, RangeInfo,
14}; 20};
15 21
16/// Contains the results when hovering over an item 22/// Contains the results when hovering over an item
@@ -256,8 +262,10 @@ pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Option<String> {
256 262
257#[cfg(test)] 263#[cfg(test)]
258mod tests { 264mod tests {
265 use crate::mock_analysis::{
266 analysis_and_position, single_file_with_position, single_file_with_range,
267 };
259 use ra_syntax::TextRange; 268 use ra_syntax::TextRange;
260 use crate::mock_analysis::{single_file_with_position, single_file_with_range, analysis_and_position};
261 269
262 fn trim_markup(s: &str) -> &str { 270 fn trim_markup(s: &str) -> &str {
263 s.trim_start_matches("```rust\n").trim_end_matches("\n```") 271 s.trim_start_matches("```rust\n").trim_end_matches("\n```")
diff --git a/crates/ra_ide_api/src/impls.rs b/crates/ra_ide_api/src/impls.rs
index b80238d9e..f8a62bd71 100644
--- a/crates/ra_ide_api/src/impls.rs
+++ b/crates/ra_ide_api/src/impls.rs
@@ -1,11 +1,8 @@
1use ra_db::SourceDatabase;
2use ra_syntax::{
3 AstNode, ast,
4 algo::find_node_at_offset,
5};
6use hir::{db::HirDatabase, source_binder}; 1use hir::{db::HirDatabase, source_binder};
2use ra_db::SourceDatabase;
3use ra_syntax::{algo::find_node_at_offset, ast, AstNode};
7 4
8use crate::{FilePosition, NavigationTarget, db::RootDatabase, RangeInfo}; 5use crate::{db::RootDatabase, FilePosition, NavigationTarget, RangeInfo};
9 6
10pub(crate) fn goto_implementation( 7pub(crate) fn goto_implementation(
11 db: &RootDatabase, 8 db: &RootDatabase,
diff --git a/crates/ra_ide_api/src/join_lines.rs b/crates/ra_ide_api/src/join_lines.rs
index 3978e9635..8ab485adb 100644
--- a/crates/ra_ide_api/src/join_lines.rs
+++ b/crates/ra_ide_api/src/join_lines.rs
@@ -1,14 +1,11 @@
1use itertools::Itertools; 1use itertools::Itertools;
2use ra_fmt::{compute_ws, extract_trivial_expression};
2use ra_syntax::{ 3use ra_syntax::{
3 T,
4 SourceFile, TextRange, TextUnit, SyntaxNode, SyntaxElement, SyntaxToken,
5 SyntaxKind::{self, WHITESPACE},
6 algo::{find_covering_element, non_trivia_sibling}, 4 algo::{find_covering_element, non_trivia_sibling},
7 ast::{self, AstNode, AstToken}, 5 ast::{self, AstNode, AstToken},
8 Direction, 6 Direction, SourceFile, SyntaxElement,
9}; 7 SyntaxKind::{self, WHITESPACE},
10use ra_fmt::{ 8 SyntaxNode, SyntaxToken, TextRange, TextUnit, T,
11 compute_ws, extract_trivial_expression
12}; 9};
13use ra_text_edit::{TextEdit, TextEditBuilder}; 10use ra_text_edit::{TextEdit, TextEditBuilder};
14 11
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs
index 817e65df0..95de9bcb8 100644
--- a/crates/ra_ide_api/src/lib.rs
+++ b/crates/ra_ide_api/src/lib.rs
@@ -46,33 +46,35 @@ mod test_utils;
46 46
47use std::sync::Arc; 47use std::sync::Arc;
48 48
49use ra_syntax::{SourceFile, TreeArc, TextRange, TextUnit};
50use ra_text_edit::TextEdit;
51use ra_db::{ 49use ra_db::{
52 SourceDatabase, CheckCanceled,
53 salsa::{self, ParallelDatabase}, 50 salsa::{self, ParallelDatabase},
51 CheckCanceled, SourceDatabase,
54}; 52};
53use ra_syntax::{SourceFile, TextRange, TextUnit, TreeArc};
54use ra_text_edit::TextEdit;
55use relative_path::RelativePathBuf; 55use relative_path::RelativePathBuf;
56 56
57use crate::{symbol_index::FileSymbol, db::LineIndexDatabase}; 57use crate::{db::LineIndexDatabase, symbol_index::FileSymbol};
58 58
59pub use crate::{ 59pub use crate::{
60 assists::{Assist, AssistId},
60 change::{AnalysisChange, LibraryData}, 61 change::{AnalysisChange, LibraryData},
61 completion::{CompletionItem, CompletionItemKind, InsertTextFormat}, 62 completion::{CompletionItem, CompletionItemKind, InsertTextFormat},
62 runnables::{Runnable, RunnableKind}, 63 diagnostics::Severity,
63 references::ReferenceSearchResult, 64 display::{file_structure, FunctionSignature, NavigationTarget, StructureNode},
64 assists::{Assist, AssistId},
65 hover::{HoverResult},
66 line_index::{LineIndex, LineCol},
67 line_index_utils::translate_offset_with_edit,
68 folding_ranges::{Fold, FoldKind}, 65 folding_ranges::{Fold, FoldKind},
66 hover::HoverResult,
67 line_index::{LineCol, LineIndex},
68 line_index_utils::translate_offset_with_edit,
69 references::ReferenceSearchResult,
70 runnables::{Runnable, RunnableKind},
69 syntax_highlighting::HighlightedRange, 71 syntax_highlighting::HighlightedRange,
70 diagnostics::Severity,
71 display::{FunctionSignature, NavigationTarget, StructureNode, file_structure},
72}; 72};
73 73
74pub use ra_db::{Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, SourceRootId, Edition};
75pub use hir::Documentation; 74pub use hir::Documentation;
75pub use ra_db::{
76 Canceled, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange, SourceRootId,
77};
76 78
77pub type Cancelable<T> = Result<T, Canceled>; 79pub type Cancelable<T> = Result<T, Canceled>;
78 80
diff --git a/crates/ra_ide_api/src/line_index.rs b/crates/ra_ide_api/src/line_index.rs
index a53cf9ee0..71de8a928 100644
--- a/crates/ra_ide_api/src/line_index.rs
+++ b/crates/ra_ide_api/src/line_index.rs
@@ -145,7 +145,7 @@ pub fn to_line_col(text: &str, offset: TextUnit) -> LineCol {
145mod test_line_index { 145mod test_line_index {
146 use super::*; 146 use super::*;
147 use proptest::{prelude::*, proptest}; 147 use proptest::{prelude::*, proptest};
148 use ra_text_edit::test_utils::{arb_text, arb_offset}; 148 use ra_text_edit::test_utils::{arb_offset, arb_text};
149 149
150 #[test] 150 #[test]
151 fn test_line_index() { 151 fn test_line_index() {
diff --git a/crates/ra_ide_api/src/line_index_utils.rs b/crates/ra_ide_api/src/line_index_utils.rs
index a03467011..f9073dca2 100644
--- a/crates/ra_ide_api/src/line_index_utils.rs
+++ b/crates/ra_ide_api/src/line_index_utils.rs
@@ -1,6 +1,6 @@
1use crate::{line_index::Utf16Char, LineCol, LineIndex};
2use ra_syntax::{TextRange, TextUnit};
1use ra_text_edit::{AtomTextEdit, TextEdit}; 3use ra_text_edit::{AtomTextEdit, TextEdit};
2use ra_syntax::{TextUnit, TextRange};
3use crate::{LineIndex, LineCol, line_index::Utf16Char};
4 4
5#[derive(Debug, Clone)] 5#[derive(Debug, Clone)]
6enum Step { 6enum Step {
@@ -292,8 +292,8 @@ pub fn translate_offset_with_edit(
292#[cfg(test)] 292#[cfg(test)]
293mod test { 293mod test {
294 use super::*; 294 use super::*;
295 use proptest::{prelude::*, proptest};
296 use crate::line_index; 295 use crate::line_index;
296 use proptest::{prelude::*, proptest};
297 use ra_text_edit::test_utils::{arb_offset, arb_text_with_edit}; 297 use ra_text_edit::test_utils::{arb_offset, arb_text_with_edit};
298 use ra_text_edit::TextEdit; 298 use ra_text_edit::TextEdit;
299 299
diff --git a/crates/ra_ide_api/src/matching_brace.rs b/crates/ra_ide_api/src/matching_brace.rs
index 7f3e65b46..438b07896 100644
--- a/crates/ra_ide_api/src/matching_brace.rs
+++ b/crates/ra_ide_api/src/matching_brace.rs
@@ -1,10 +1,4 @@
1use ra_syntax::{ 1use ra_syntax::{algo::find_token_at_offset, ast::AstNode, SourceFile, SyntaxKind, TextUnit, T};
2 SourceFile, TextUnit,
3 algo::find_token_at_offset,
4 SyntaxKind::{self},
5 ast::AstNode,
6 T
7};
8 2
9pub fn matching_brace(file: &SourceFile, offset: TextUnit) -> Option<TextUnit> { 3pub fn matching_brace(file: &SourceFile, offset: TextUnit) -> Option<TextUnit> {
10 const BRACES: &[SyntaxKind] = 4 const BRACES: &[SyntaxKind] =
diff --git a/crates/ra_ide_api/src/mock_analysis.rs b/crates/ra_ide_api/src/mock_analysis.rs
index cb12dd0b1..4dbbd489a 100644
--- a/crates/ra_ide_api/src/mock_analysis.rs
+++ b/crates/ra_ide_api/src/mock_analysis.rs
@@ -3,7 +3,10 @@ use std::sync::Arc;
3use relative_path::RelativePathBuf; 3use relative_path::RelativePathBuf;
4use test_utils::{extract_offset, extract_range, parse_fixture, CURSOR_MARKER}; 4use test_utils::{extract_offset, extract_range, parse_fixture, CURSOR_MARKER};
5 5
6use crate::{Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, FilePosition, FileRange, SourceRootId, Edition::Edition2018}; 6use crate::{
7 Analysis, AnalysisChange, AnalysisHost, CrateGraph, Edition::Edition2018, FileId, FilePosition,
8 FileRange, SourceRootId,
9};
7 10
8/// Mock analysis is used in test to bootstrap an AnalysisHost/Analysis 11/// Mock analysis is used in test to bootstrap an AnalysisHost/Analysis
9/// from a set of in-memory files. 12/// from a set of in-memory files.
diff --git a/crates/ra_ide_api/src/name_ref_kind.rs b/crates/ra_ide_api/src/name_ref_kind.rs
index 000036db4..67381c9c8 100644
--- a/crates/ra_ide_api/src/name_ref_kind.rs
+++ b/crates/ra_ide_api/src/name_ref_kind.rs
@@ -1,5 +1,5 @@
1use ra_syntax::{AstNode, AstPtr, ast};
2use hir::Either; 1use hir::Either;
2use ra_syntax::{ast, AstNode, AstPtr};
3use test_utils::tested_by; 3use test_utils::tested_by;
4 4
5use crate::db::RootDatabase; 5use crate::db::RootDatabase;
diff --git a/crates/ra_ide_api/src/parent_module.rs b/crates/ra_ide_api/src/parent_module.rs
index 27788c984..7d5f9ea2c 100644
--- a/crates/ra_ide_api/src/parent_module.rs
+++ b/crates/ra_ide_api/src/parent_module.rs
@@ -1,6 +1,6 @@
1use ra_db::{FilePosition, FileId, CrateId}; 1use ra_db::{CrateId, FileId, FilePosition};
2 2
3use crate::{NavigationTarget, db::RootDatabase}; 3use crate::{db::RootDatabase, NavigationTarget};
4 4
5/// This returns `Vec` because a module may be included from several places. We 5/// This returns `Vec` because a module may be included from several places. We
6/// don't handle this case yet though, so the Vec has length at most one. 6/// don't handle this case yet though, so the Vec has length at most one.
@@ -29,10 +29,10 @@ pub(crate) fn crate_for(db: &RootDatabase, file_id: FileId) -> Vec<CrateId> {
29#[cfg(test)] 29#[cfg(test)]
30mod tests { 30mod tests {
31 use crate::{ 31 use crate::{
32 AnalysisChange, CrateGraph,
33 mock_analysis::{analysis_and_position, MockAnalysis}, 32 mock_analysis::{analysis_and_position, MockAnalysis},
33 AnalysisChange, CrateGraph,
34 Edition::Edition2018, 34 Edition::Edition2018,
35}; 35 };
36 36
37 #[test] 37 #[test]
38 fn test_resolve_parent_module() { 38 fn test_resolve_parent_module() {
diff --git a/crates/ra_ide_api/src/references.rs b/crates/ra_ide_api/src/references.rs
index 12cdc6a6d..766c0ad74 100644
--- a/crates/ra_ide_api/src/references.rs
+++ b/crates/ra_ide_api/src/references.rs
@@ -1,22 +1,11 @@
1use hir::{source_binder, Either, ModuleSource};
2use ra_db::SourceDatabase;
3use ra_syntax::{algo::find_node_at_offset, ast, AstNode, SourceFile, SyntaxNode};
1use relative_path::{RelativePath, RelativePathBuf}; 4use relative_path::{RelativePath, RelativePathBuf};
2use hir::{ModuleSource, source_binder, Either};
3use ra_db::{SourceDatabase};
4use ra_syntax::{
5 AstNode, SyntaxNode, SourceFile,
6 ast,
7 algo::find_node_at_offset,
8};
9 5
10use crate::{ 6use crate::{
11 db::RootDatabase, 7 db::RootDatabase, FileId, FilePosition, FileRange, FileSystemEdit, NavigationTarget,
12 FilePosition, 8 SourceChange, SourceFileEdit, TextRange,
13 FileRange,
14 FileId,
15 NavigationTarget,
16 FileSystemEdit,
17 SourceChange,
18 SourceFileEdit,
19 TextRange,
20}; 9};
21 10
22#[derive(Debug, Clone)] 11#[derive(Debug, Clone)]
@@ -210,13 +199,12 @@ fn rename_reference(
210 199
211#[cfg(test)] 200#[cfg(test)]
212mod tests { 201mod tests {
202 use crate::{
203 mock_analysis::analysis_and_position, mock_analysis::single_file_with_position, FileId,
204 ReferenceSearchResult,
205 };
213 use insta::assert_debug_snapshot_matches; 206 use insta::assert_debug_snapshot_matches;
214 use test_utils::assert_eq_text; 207 use test_utils::assert_eq_text;
215 use crate::{
216 mock_analysis::single_file_with_position,
217 mock_analysis::analysis_and_position,
218 FileId, ReferenceSearchResult
219};
220 208
221 #[test] 209 #[test]
222 fn test_find_all_refs_for_local() { 210 fn test_find_all_refs_for_local() {
diff --git a/crates/ra_ide_api/src/runnables.rs b/crates/ra_ide_api/src/runnables.rs
index afe629d50..2d2d0b40e 100644
--- a/crates/ra_ide_api/src/runnables.rs
+++ b/crates/ra_ide_api/src/runnables.rs
@@ -1,9 +1,9 @@
1use itertools::Itertools; 1use itertools::Itertools;
2use ra_db::SourceDatabase;
2use ra_syntax::{ 3use ra_syntax::{
3 TextRange, SyntaxNode, 4 ast::{self, AstNode, AttrsOwner, ModuleItemOwner, NameOwner},
4 ast::{self, AstNode, NameOwner, ModuleItemOwner, AttrsOwner}, 5 SyntaxNode, TextRange,
5}; 6};
6use ra_db::SourceDatabase;
7 7
8use crate::{db::RootDatabase, FileId}; 8use crate::{db::RootDatabase, FileId};
9 9
diff --git a/crates/ra_ide_api/src/status.rs b/crates/ra_ide_api/src/status.rs
index ce25f4a87..1bcba0b8b 100644
--- a/crates/ra_ide_api/src/status.rs
+++ b/crates/ra_ide_api/src/status.rs
@@ -1,20 +1,20 @@
1use std::{ 1use std::{fmt, iter::FromIterator, sync::Arc};
2 fmt,
3 iter::FromIterator,
4 sync::Arc,
5};
6 2
7use ra_syntax::{TreeArc, SyntaxNode, Parse, AstNode}; 3use hir::MacroFile;
8use ra_db::{ 4use ra_db::{
5 salsa::{
6 debug::{DebugQueryTable, TableEntry},
7 Database,
8 },
9 FileTextQuery, SourceRootId, 9 FileTextQuery, SourceRootId,
10 salsa::{Database, debug::{DebugQueryTable, TableEntry}},
11}; 10};
12use ra_prof::{Bytes, memory_usage}; 11use ra_prof::{memory_usage, Bytes};
13use hir::MacroFile; 12use ra_syntax::{AstNode, Parse, SyntaxNode, TreeArc};
14 13
15use crate::{ 14use crate::{
16 FileId, db::RootDatabase, 15 db::RootDatabase,
17 symbol_index::{SymbolIndex, LibrarySymbolsQuery}, 16 symbol_index::{LibrarySymbolsQuery, SymbolIndex},
17 FileId,
18}; 18};
19 19
20pub(crate) fn syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats { 20pub(crate) fn syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats {
diff --git a/crates/ra_ide_api/src/symbol_index.rs b/crates/ra_ide_api/src/symbol_index.rs
index a6cd7bf61..2ca0a25d4 100644
--- a/crates/ra_ide_api/src/symbol_index.rs
+++ b/crates/ra_ide_api/src/symbol_index.rs
@@ -20,31 +20,27 @@
20//! file in the current workspace, and run a query against the union of all 20//! file in the current workspace, and run a query against the union of all
21//! those FSTs. 21//! those FSTs.
22use std::{ 22use std::{
23 fmt,
23 hash::{Hash, Hasher}, 24 hash::{Hash, Hasher},
24 sync::Arc,
25 mem, 25 mem,
26 fmt, 26 sync::Arc,
27}; 27};
28 28
29use fst::{self, Streamer}; 29use fst::{self, Streamer};
30use ra_syntax::{
31 SyntaxNode, SyntaxNodePtr, SourceFile, SmolStr, TreeArc, AstNode,
32 algo::{visit::{visitor, Visitor}},
33 SyntaxKind::{self, *},
34 ast::{self, NameOwner},
35 WalkEvent,
36 TextRange,
37};
38use ra_db::{ 30use ra_db::{
39 SourceRootId, SourceDatabase,
40 salsa::{self, ParallelDatabase}, 31 salsa::{self, ParallelDatabase},
32 SourceDatabase, SourceRootId,
33};
34use ra_syntax::{
35 algo::visit::{visitor, Visitor},
36 ast::{self, NameOwner},
37 AstNode, SmolStr, SourceFile,
38 SyntaxKind::{self, *},
39 SyntaxNode, SyntaxNodePtr, TextRange, TreeArc, WalkEvent,
41}; 40};
42use rayon::prelude::*; 41use rayon::prelude::*;
43 42
44use crate::{ 43use crate::{db::RootDatabase, FileId, Query};
45 FileId, Query,
46 db::RootDatabase,
47};
48 44
49#[salsa::query_group(SymbolsDatabaseStorage)] 45#[salsa::query_group(SymbolsDatabaseStorage)]
50pub(crate) trait SymbolsDatabase: hir::db::HirDatabase { 46pub(crate) trait SymbolsDatabase: hir::db::HirDatabase {
@@ -305,15 +301,11 @@ fn to_file_symbol(node: &SyntaxNode, file_id: FileId) -> Option<FileSymbol> {
305 301
306#[cfg(test)] 302#[cfg(test)]
307mod tests { 303mod tests {
304 use crate::{display::NavigationTarget, mock_analysis::single_file, Query};
308 use ra_syntax::{ 305 use ra_syntax::{
309 SmolStr, 306 SmolStr,
310 SyntaxKind::{FN_DEF, STRUCT_DEF} 307 SyntaxKind::{FN_DEF, STRUCT_DEF},
311}; 308 };
312 use crate::{
313 display::NavigationTarget,
314 mock_analysis::single_file,
315 Query,
316};
317 309
318 #[test] 310 #[test]
319 fn test_world_symbols_with_no_container() { 311 fn test_world_symbols_with_no_container() {
diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs
index 3a04a51cd..7c4285b02 100644
--- a/crates/ra_ide_api/src/syntax_highlighting.rs
+++ b/crates/ra_ide_api/src/syntax_highlighting.rs
@@ -1,12 +1,12 @@
1use rustc_hash::{FxHashSet, FxHashMap}; 1use rustc_hash::{FxHashMap, FxHashSet};
2 2
3use ra_syntax::{
4 ast, AstNode, TextRange, Direction, SmolStr, SyntaxKind, SyntaxKind::*, SyntaxElement, T,
5};
6use ra_db::SourceDatabase; 3use ra_db::SourceDatabase;
7use ra_prof::profile; 4use ra_prof::profile;
5use ra_syntax::{
6 ast, AstNode, Direction, SmolStr, SyntaxElement, SyntaxKind, SyntaxKind::*, TextRange, T,
7};
8 8
9use crate::{FileId, db::RootDatabase}; 9use crate::{db::RootDatabase, FileId};
10 10
11#[derive(Debug)] 11#[derive(Debug)]
12pub struct HighlightedRange { 12pub struct HighlightedRange {
@@ -64,7 +64,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
64 if let Some(name_ref) = node.as_node().and_then(ast::NameRef::cast) { 64 if let Some(name_ref) = node.as_node().and_then(ast::NameRef::cast) {
65 // FIXME: revisit this after #1340 65 // FIXME: revisit this after #1340
66 use crate::name_ref_kind::{classify_name_ref, NameRefKind::*}; 66 use crate::name_ref_kind::{classify_name_ref, NameRefKind::*};
67 use hir::{ModuleDef, ImplItem}; 67 use hir::{ImplItem, ModuleDef};
68 68
69 // FIXME: try to reuse the SourceAnalyzers 69 // FIXME: try to reuse the SourceAnalyzers
70 let analyzer = hir::SourceAnalyzer::new(db, file_id, name_ref.syntax(), None); 70 let analyzer = hir::SourceAnalyzer::new(db, file_id, name_ref.syntax(), None);
@@ -264,8 +264,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4e
264 264
265#[cfg(test)] 265#[cfg(test)]
266mod tests { 266mod tests {
267 use test_utils::{project_dir, read_text, assert_eq_text};
268 use crate::mock_analysis::single_file; 267 use crate::mock_analysis::single_file;
268 use test_utils::{assert_eq_text, project_dir, read_text};
269 269
270 #[test] 270 #[test]
271 fn test_highlighting() { 271 fn test_highlighting() {
diff --git a/crates/ra_ide_api/src/syntax_tree.rs b/crates/ra_ide_api/src/syntax_tree.rs
index 7165fa97a..8bdd08d58 100644
--- a/crates/ra_ide_api/src/syntax_tree.rs
+++ b/crates/ra_ide_api/src/syntax_tree.rs
@@ -1,9 +1,9 @@
1use ra_db::SourceDatabase;
2use crate::db::RootDatabase; 1use crate::db::RootDatabase;
2use ra_db::SourceDatabase;
3use ra_syntax::{ 3use ra_syntax::{
4 SourceFile, TextRange, AstNode, SyntaxToken, SyntaxElement, 4 algo, AstNode, SourceFile, SyntaxElement,
5 algo, 5 SyntaxKind::{RAW_STRING, STRING},
6 SyntaxKind::{STRING, RAW_STRING}, 6 SyntaxToken, TextRange,
7}; 7};
8 8
9pub use ra_db::FileId; 9pub use ra_db::FileId;
diff --git a/crates/ra_ide_api/src/typing.rs b/crates/ra_ide_api/src/typing.rs
index 3e35d8352..d3cb71ddb 100644
--- a/crates/ra_ide_api/src/typing.rs
+++ b/crates/ra_ide_api/src/typing.rs
@@ -1,13 +1,14 @@
1use crate::{db::RootDatabase, SourceChange, SourceFileEdit};
2use ra_db::{FilePosition, SourceDatabase};
3use ra_fmt::leading_indent;
1use ra_syntax::{ 4use ra_syntax::{
2 AstNode, SourceFile, SyntaxKind::*,
3 TextUnit, TextRange, SyntaxToken,
4 algo::{find_node_at_offset, find_token_at_offset, TokenAtOffset}, 5 algo::{find_node_at_offset, find_token_at_offset, TokenAtOffset},
5 ast::{self, AstToken}, 6 ast::{self, AstToken},
7 AstNode, SourceFile,
8 SyntaxKind::*,
9 SyntaxToken, TextRange, TextUnit,
6}; 10};
7use ra_fmt::leading_indent;
8use ra_text_edit::{TextEdit, TextEditBuilder}; 11use ra_text_edit::{TextEdit, TextEditBuilder};
9use ra_db::{FilePosition, SourceDatabase};
10use crate::{db::RootDatabase, SourceChange, SourceFileEdit};
11 12
12pub(crate) fn on_enter(db: &RootDatabase, position: FilePosition) -> Option<SourceChange> { 13pub(crate) fn on_enter(db: &RootDatabase, position: FilePosition) -> Option<SourceChange> {
13 let file = db.parse(position.file_id).tree; 14 let file = db.parse(position.file_id).tree;