diff options
author | Aleksey Kladov <[email protected]> | 2019-05-30 14:10:07 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-05-30 14:10:07 +0100 |
commit | b6a854e161cc122e6d9ae12084b6a1d1f4d0f241 (patch) | |
tree | f01cf9c3589ae920c50696ce244c98b2454834b3 /crates/ra_ide_api/src/completion | |
parent | c6ee9d681c7c745e95f19badef271fec34ec2e36 (diff) |
update ra_ide_api to use builtins
Diffstat (limited to 'crates/ra_ide_api/src/completion')
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_path.rs | 20 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/completion_item.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/presentation.rs | 7 |
3 files changed, 28 insertions, 1 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index c41752ae7..99da24142 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs | |||
@@ -17,6 +17,12 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | |||
17 | hir::ModuleDef::Module(module) => { | 17 | hir::ModuleDef::Module(module) => { |
18 | let module_scope = module.scope(ctx.db); | 18 | let module_scope = module.scope(ctx.db); |
19 | for (name, res) in module_scope.entries() { | 19 | for (name, res) in module_scope.entries() { |
20 | if let Some(hir::ModuleDef::BuiltinType(..)) = res.def.as_ref().take_types() { | ||
21 | if ctx.use_item_syntax.is_some() { | ||
22 | tested_by!(dont_complete_primitive_in_use); | ||
23 | continue; | ||
24 | } | ||
25 | } | ||
20 | if Some(module) == ctx.module { | 26 | if Some(module) == ctx.module { |
21 | if let Some(import) = res.import { | 27 | if let Some(import) = res.import { |
22 | if let Either::A(use_tree) = module.import_source(ctx.db, import) { | 28 | if let Either::A(use_tree) = module.import_source(ctx.db, import) { |
@@ -89,6 +95,20 @@ mod tests { | |||
89 | } | 95 | } |
90 | 96 | ||
91 | #[test] | 97 | #[test] |
98 | fn dont_complete_primitive_in_use() { | ||
99 | covers!(dont_complete_primitive_in_use); | ||
100 | let completions = do_completion(r"use self::<|>;", CompletionKind::BuiltinType); | ||
101 | assert!(completions.is_empty()); | ||
102 | } | ||
103 | |||
104 | #[test] | ||
105 | fn completes_primitives() { | ||
106 | let completions = | ||
107 | do_completion(r"fn main() { let _: <|> = 92; }", CompletionKind::BuiltinType); | ||
108 | assert_eq!(completions.len(), 17); | ||
109 | } | ||
110 | |||
111 | #[test] | ||
92 | fn completes_mod_with_docs() { | 112 | fn completes_mod_with_docs() { |
93 | check_reference_completion( | 113 | check_reference_completion( |
94 | "mod_with_docs", | 114 | "mod_with_docs", |
diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs index 6f1392231..6f2a60640 100644 --- a/crates/ra_ide_api/src/completion/completion_item.rs +++ b/crates/ra_ide_api/src/completion/completion_item.rs | |||
@@ -78,6 +78,7 @@ pub enum CompletionItemKind { | |||
78 | Keyword, | 78 | Keyword, |
79 | Module, | 79 | Module, |
80 | Function, | 80 | Function, |
81 | BuiltinType, | ||
81 | Struct, | 82 | Struct, |
82 | Enum, | 83 | Enum, |
83 | EnumVariant, | 84 | EnumVariant, |
@@ -102,6 +103,7 @@ pub(crate) enum CompletionKind { | |||
102 | Magic, | 103 | Magic, |
103 | Snippet, | 104 | Snippet, |
104 | Postfix, | 105 | Postfix, |
106 | BuiltinType, | ||
105 | } | 107 | } |
106 | 108 | ||
107 | #[derive(Debug, PartialEq, Eq, Copy, Clone)] | 109 | #[derive(Debug, PartialEq, Eq, Copy, Clone)] |
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index 064d379a4..d405161d6 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs | |||
@@ -57,6 +57,7 @@ impl Completions { | |||
57 | } | 57 | } |
58 | Some(it) => it, | 58 | Some(it) => it, |
59 | }; | 59 | }; |
60 | let mut completion_kind = CompletionKind::Reference; | ||
60 | let (kind, docs) = match def { | 61 | let (kind, docs) = match def { |
61 | Resolution::Def(Module(it)) => (CompletionItemKind::Module, it.docs(ctx.db)), | 62 | Resolution::Def(Module(it)) => (CompletionItemKind::Module, it.docs(ctx.db)), |
62 | Resolution::Def(Function(func)) => { | 63 | Resolution::Def(Function(func)) => { |
@@ -70,6 +71,10 @@ impl Completions { | |||
70 | Resolution::Def(Static(it)) => (CompletionItemKind::Static, it.docs(ctx.db)), | 71 | Resolution::Def(Static(it)) => (CompletionItemKind::Static, it.docs(ctx.db)), |
71 | Resolution::Def(Trait(it)) => (CompletionItemKind::Trait, it.docs(ctx.db)), | 72 | Resolution::Def(Trait(it)) => (CompletionItemKind::Trait, it.docs(ctx.db)), |
72 | Resolution::Def(TypeAlias(it)) => (CompletionItemKind::TypeAlias, it.docs(ctx.db)), | 73 | Resolution::Def(TypeAlias(it)) => (CompletionItemKind::TypeAlias, it.docs(ctx.db)), |
74 | Resolution::Def(BuiltinType(..)) => { | ||
75 | completion_kind = CompletionKind::BuiltinType; | ||
76 | (CompletionItemKind::BuiltinType, None) | ||
77 | } | ||
73 | Resolution::GenericParam(..) => (CompletionItemKind::TypeParam, None), | 78 | Resolution::GenericParam(..) => (CompletionItemKind::TypeParam, None), |
74 | Resolution::LocalBinding(..) => (CompletionItemKind::Binding, None), | 79 | Resolution::LocalBinding(..) => (CompletionItemKind::Binding, None), |
75 | Resolution::SelfType(..) => ( | 80 | Resolution::SelfType(..) => ( |
@@ -77,7 +82,7 @@ impl Completions { | |||
77 | None, | 82 | None, |
78 | ), | 83 | ), |
79 | }; | 84 | }; |
80 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), local_name) | 85 | CompletionItem::new(completion_kind, ctx.source_range(), local_name) |
81 | .kind(kind) | 86 | .kind(kind) |
82 | .set_documentation(docs) | 87 | .set_documentation(docs) |
83 | .add_to(self) | 88 | .add_to(self) |