aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2020-02-21 14:34:06 +0000
committerFlorian Diebold <[email protected]>2020-02-21 14:39:51 +0000
commit31af774254d1fb4e9105ba050546db16b9b54fb6 (patch)
tree587c84243cf6f4db8fa9d403f50178afab7ffe4f /crates/ra_ide
parente3037c2631ecb55996b676ce2c18b9df1858abaa (diff)
Refactor how builtins are resolved
This fixes autocompletion suggesting e.g. self::usize.
Diffstat (limited to 'crates/ra_ide')
-rw-r--r--crates/ra_ide/src/completion/complete_path.rs13
-rw-r--r--crates/ra_ide/src/marks.rs1
2 files changed, 7 insertions, 7 deletions
diff --git a/crates/ra_ide/src/completion/complete_path.rs b/crates/ra_ide/src/completion/complete_path.rs
index af24e9f48..2d7f09a6c 100644
--- a/crates/ra_ide/src/completion/complete_path.rs
+++ b/crates/ra_ide/src/completion/complete_path.rs
@@ -1,4 +1,4 @@
1//! FIXME: write short doc here 1//! Completion of paths, including when writing a single name.
2 2
3use hir::{Adt, PathResolution, ScopeDef}; 3use hir::{Adt, PathResolution, ScopeDef};
4use ra_syntax::AstNode; 4use ra_syntax::AstNode;
@@ -20,10 +20,6 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
20 let module_scope = module.scope(ctx.db); 20 let module_scope = module.scope(ctx.db);
21 for (name, def) in module_scope { 21 for (name, def) in module_scope {
22 if ctx.use_item_syntax.is_some() { 22 if ctx.use_item_syntax.is_some() {
23 if let hir::ScopeDef::ModuleDef(hir::ModuleDef::BuiltinType(..)) = def {
24 tested_by!(dont_complete_primitive_in_use);
25 continue;
26 }
27 if let ScopeDef::Unknown = def { 23 if let ScopeDef::Unknown = def {
28 if let Some(name_ref) = ctx.name_ref_syntax.as_ref() { 24 if let Some(name_ref) = ctx.name_ref_syntax.as_ref() {
29 if name_ref.syntax().text() == name.to_string().as_str() { 25 if name_ref.syntax().text() == name.to_string().as_str() {
@@ -125,12 +121,17 @@ mod tests {
125 121
126 #[test] 122 #[test]
127 fn dont_complete_primitive_in_use() { 123 fn dont_complete_primitive_in_use() {
128 covers!(dont_complete_primitive_in_use);
129 let completions = do_completion(r"use self::<|>;", CompletionKind::BuiltinType); 124 let completions = do_completion(r"use self::<|>;", CompletionKind::BuiltinType);
130 assert!(completions.is_empty()); 125 assert!(completions.is_empty());
131 } 126 }
132 127
133 #[test] 128 #[test]
129 fn dont_complete_primitive_in_module_scope() {
130 let completions = do_completion(r"fn foo() { self::<|> }", CompletionKind::BuiltinType);
131 assert!(completions.is_empty());
132 }
133
134 #[test]
134 fn completes_primitives() { 135 fn completes_primitives() {
135 let completions = 136 let completions =
136 do_completion(r"fn main() { let _: <|> = 92; }", CompletionKind::BuiltinType); 137 do_completion(r"fn main() { let _: <|> = 92; }", CompletionKind::BuiltinType);
diff --git a/crates/ra_ide/src/marks.rs b/crates/ra_ide/src/marks.rs
index 5bf4d2062..bcb67e373 100644
--- a/crates/ra_ide/src/marks.rs
+++ b/crates/ra_ide/src/marks.rs
@@ -10,6 +10,5 @@ test_utils::marks!(
10 goto_def_for_field_init_shorthand 10 goto_def_for_field_init_shorthand
11 call_info_bad_offset 11 call_info_bad_offset
12 dont_complete_current_use 12 dont_complete_current_use
13 dont_complete_primitive_in_use
14 test_resolve_parent_module_on_module_decl 13 test_resolve_parent_module_on_module_decl
15); 14);