aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-05-31 13:13:09 +0100
committerLukas Wirth <[email protected]>2021-05-31 13:15:15 +0100
commit971b0836ef425d8b962ecac70a974887a8356567 (patch)
tree8649259da32910831c45aee3ba9b68abce8f5b37 /crates
parent3cb3f1d17b54a7e144db495e073551049c9c482c (diff)
Use `Name`s instead of Strings in the completion rendering api
Diffstat (limited to 'crates')
-rw-r--r--crates/ide_completion/src/completions.rs27
-rw-r--r--crates/ide_completion/src/completions/lifetime.rs7
-rw-r--r--crates/ide_completion/src/completions/macro_in_item_position.rs4
-rw-r--r--crates/ide_completion/src/completions/pattern.rs2
-rw-r--r--crates/ide_completion/src/completions/qualified_path.rs38
-rw-r--r--crates/ide_completion/src/completions/unqualified_path.rs8
-rw-r--r--crates/ide_completion/src/render.rs143
-rw-r--r--crates/ide_completion/src/render/enum_variant.rs55
-rw-r--r--crates/ide_completion/src/render/function.rs14
-rw-r--r--crates/ide_completion/src/render/macro_.rs9
10 files changed, 165 insertions, 142 deletions
diff --git a/crates/ide_completion/src/completions.rs b/crates/ide_completion/src/completions.rs
index 78154bf3e..151bf3783 100644
--- a/crates/ide_completion/src/completions.rs
+++ b/crates/ide_completion/src/completions.rs
@@ -18,7 +18,7 @@ pub(crate) mod unqualified_path;
18 18
19use std::iter; 19use std::iter;
20 20
21use hir::{known, ModPath, ScopeDef, Type}; 21use hir::known;
22use ide_db::SymbolKind; 22use ide_db::SymbolKind;
23 23
24use crate::{ 24use crate::{
@@ -69,12 +69,17 @@ impl Completions {
69 items.into_iter().for_each(|item| self.add(item.into())) 69 items.into_iter().for_each(|item| self.add(item.into()))
70 } 70 }
71 71
72 pub(crate) fn add_field(&mut self, ctx: &CompletionContext, field: hir::Field, ty: &Type) { 72 pub(crate) fn add_field(&mut self, ctx: &CompletionContext, field: hir::Field, ty: &hir::Type) {
73 let item = render_field(RenderContext::new(ctx), field, ty); 73 let item = render_field(RenderContext::new(ctx), field, ty);
74 self.add(item); 74 self.add(item);
75 } 75 }
76 76
77 pub(crate) fn add_tuple_field(&mut self, ctx: &CompletionContext, field: usize, ty: &Type) { 77 pub(crate) fn add_tuple_field(
78 &mut self,
79 ctx: &CompletionContext,
80 field: usize,
81 ty: &hir::Type,
82 ) {
78 let item = render_tuple_field(RenderContext::new(ctx), field, ty); 83 let item = render_tuple_field(RenderContext::new(ctx), field, ty);
79 self.add(item); 84 self.add(item);
80 } 85 }
@@ -89,8 +94,8 @@ impl Completions {
89 pub(crate) fn add_resolution( 94 pub(crate) fn add_resolution(
90 &mut self, 95 &mut self,
91 ctx: &CompletionContext, 96 ctx: &CompletionContext,
92 local_name: String, 97 local_name: hir::Name,
93 resolution: &ScopeDef, 98 resolution: &hir::ScopeDef,
94 ) { 99 ) {
95 if let Some(item) = render_resolution(RenderContext::new(ctx), local_name, resolution) { 100 if let Some(item) = render_resolution(RenderContext::new(ctx), local_name, resolution) {
96 self.add(item); 101 self.add(item);
@@ -100,7 +105,7 @@ impl Completions {
100 pub(crate) fn add_macro( 105 pub(crate) fn add_macro(
101 &mut self, 106 &mut self,
102 ctx: &CompletionContext, 107 ctx: &CompletionContext,
103 name: Option<String>, 108 name: Option<hir::Name>,
104 macro_: hir::MacroDef, 109 macro_: hir::MacroDef,
105 ) { 110 ) {
106 let name = match name { 111 let name = match name {
@@ -116,7 +121,7 @@ impl Completions {
116 &mut self, 121 &mut self,
117 ctx: &CompletionContext, 122 ctx: &CompletionContext,
118 func: hir::Function, 123 func: hir::Function,
119 local_name: Option<String>, 124 local_name: Option<hir::Name>,
120 ) { 125 ) {
121 if let Some(item) = render_fn(RenderContext::new(ctx), None, local_name, func) { 126 if let Some(item) = render_fn(RenderContext::new(ctx), None, local_name, func) {
122 self.add(item) 127 self.add(item)
@@ -127,7 +132,7 @@ impl Completions {
127 &mut self, 132 &mut self,
128 ctx: &CompletionContext, 133 ctx: &CompletionContext,
129 func: hir::Function, 134 func: hir::Function,
130 local_name: Option<String>, 135 local_name: Option<hir::Name>,
131 ) { 136 ) {
132 if let Some(item) = render_method(RenderContext::new(ctx), None, local_name, func) { 137 if let Some(item) = render_method(RenderContext::new(ctx), None, local_name, func) {
133 self.add(item) 138 self.add(item)
@@ -149,7 +154,7 @@ impl Completions {
149 &mut self, 154 &mut self,
150 ctx: &CompletionContext, 155 ctx: &CompletionContext,
151 variant: hir::Variant, 156 variant: hir::Variant,
152 path: ModPath, 157 path: hir::ModPath,
153 ) { 158 ) {
154 if let Some(item) = render_variant_pat(RenderContext::new(ctx), variant, None, Some(path)) { 159 if let Some(item) = render_variant_pat(RenderContext::new(ctx), variant, None, Some(path)) {
155 self.add(item); 160 self.add(item);
@@ -183,7 +188,7 @@ impl Completions {
183 &mut self, 188 &mut self,
184 ctx: &CompletionContext, 189 ctx: &CompletionContext,
185 variant: hir::Variant, 190 variant: hir::Variant,
186 path: ModPath, 191 path: hir::ModPath,
187 ) { 192 ) {
188 let item = render_variant(RenderContext::new(ctx), None, None, variant, Some(path)); 193 let item = render_variant(RenderContext::new(ctx), None, None, variant, Some(path));
189 self.add(item); 194 self.add(item);
@@ -193,7 +198,7 @@ impl Completions {
193 &mut self, 198 &mut self,
194 ctx: &CompletionContext, 199 ctx: &CompletionContext,
195 variant: hir::Variant, 200 variant: hir::Variant,
196 local_name: Option<String>, 201 local_name: Option<hir::Name>,
197 ) { 202 ) {
198 let item = render_variant(RenderContext::new(ctx), None, local_name, variant, None); 203 let item = render_variant(RenderContext::new(ctx), None, local_name, variant, None);
199 self.add(item); 204 self.add(item);
diff --git a/crates/ide_completion/src/completions/lifetime.rs b/crates/ide_completion/src/completions/lifetime.rs
index 5f6285b84..8ccccb646 100644
--- a/crates/ide_completion/src/completions/lifetime.rs
+++ b/crates/ide_completion/src/completions/lifetime.rs
@@ -16,15 +16,14 @@ pub(crate) fn complete_lifetime(acc: &mut Completions, ctx: &CompletionContext)
16 (Some(lt), Some(lp)) if lp == lt.clone() => return, 16 (Some(lt), Some(lp)) if lp == lt.clone() => return,
17 (Some(_), Some(lp)) => { 17 (Some(_), Some(lp)) => {
18 lp_string = lp.to_string(); 18 lp_string = lp.to_string();
19 Some(&lp_string) 19 Some(&*lp_string)
20 } 20 }
21 _ => None, 21 _ => None,
22 }; 22 };
23 23
24 ctx.scope.process_all_names(&mut |name, res| { 24 ctx.scope.process_all_names(&mut |name, res| {
25 if let ScopeDef::GenericParam(hir::GenericParam::LifetimeParam(_)) = res { 25 if let ScopeDef::GenericParam(hir::GenericParam::LifetimeParam(_)) = res {
26 let name = name.to_string(); 26 if param_lifetime != Some(&*name.to_string()) {
27 if param_lifetime != Some(&name) {
28 acc.add_resolution(ctx, name, &res); 27 acc.add_resolution(ctx, name, &res);
29 } 28 }
30 } 29 }
@@ -41,7 +40,7 @@ pub(crate) fn complete_label(acc: &mut Completions, ctx: &CompletionContext) {
41 } 40 }
42 ctx.scope.process_all_names(&mut |name, res| { 41 ctx.scope.process_all_names(&mut |name, res| {
43 if let ScopeDef::Label(_) = res { 42 if let ScopeDef::Label(_) = res {
44 acc.add_resolution(ctx, name.to_string(), &res); 43 acc.add_resolution(ctx, name, &res);
45 } 44 }
46 }); 45 });
47} 46}
diff --git a/crates/ide_completion/src/completions/macro_in_item_position.rs b/crates/ide_completion/src/completions/macro_in_item_position.rs
index ec57aee30..202e71215 100644
--- a/crates/ide_completion/src/completions/macro_in_item_position.rs
+++ b/crates/ide_completion/src/completions/macro_in_item_position.rs
@@ -11,11 +11,11 @@ pub(crate) fn complete_macro_in_item_position(acc: &mut Completions, ctx: &Compl
11 11
12 ctx.scope.process_all_names(&mut |name, res| { 12 ctx.scope.process_all_names(&mut |name, res| {
13 if let hir::ScopeDef::MacroDef(mac) = res { 13 if let hir::ScopeDef::MacroDef(mac) = res {
14 acc.add_macro(ctx, Some(name.to_string()), mac); 14 acc.add_macro(ctx, Some(name.clone()), mac);
15 } 15 }
16 // FIXME: This should be done in qualified_path/unqualified_path instead? 16 // FIXME: This should be done in qualified_path/unqualified_path instead?
17 if let hir::ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = res { 17 if let hir::ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = res {
18 acc.add_resolution(ctx, name.to_string(), &res); 18 acc.add_resolution(ctx, name, &res);
19 } 19 }
20 }) 20 })
21} 21}
diff --git a/crates/ide_completion/src/completions/pattern.rs b/crates/ide_completion/src/completions/pattern.rs
index b84e9a967..8a728c67e 100644
--- a/crates/ide_completion/src/completions/pattern.rs
+++ b/crates/ide_completion/src/completions/pattern.rs
@@ -51,7 +51,7 @@ pub(crate) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) {
51 _ => false, 51 _ => false,
52 }; 52 };
53 if add_resolution { 53 if add_resolution {
54 acc.add_resolution(ctx, name.to_string(), &res); 54 acc.add_resolution(ctx, name, &res);
55 } 55 }
56 }); 56 });
57} 57}
diff --git a/crates/ide_completion/src/completions/qualified_path.rs b/crates/ide_completion/src/completions/qualified_path.rs
index 7a0e1ead3..de58ce1cd 100644
--- a/crates/ide_completion/src/completions/qualified_path.rs
+++ b/crates/ide_completion/src/completions/qualified_path.rs
@@ -1,6 +1,6 @@
1//! Completion of paths, i.e. `some::prefix::$0`. 1//! Completion of paths, i.e. `some::prefix::$0`.
2 2
3use hir::{Adt, HasVisibility, PathResolution, ScopeDef}; 3use hir::HasVisibility;
4use rustc_hash::FxHashSet; 4use rustc_hash::FxHashSet;
5use syntax::AstNode; 5use syntax::AstNode;
6 6
@@ -21,14 +21,14 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
21 }; 21 };
22 let context_module = ctx.scope.module(); 22 let context_module = ctx.scope.module();
23 if ctx.expects_assoc_item() { 23 if ctx.expects_assoc_item() {
24 if let PathResolution::Def(hir::ModuleDef::Module(module)) = resolution { 24 if let hir::PathResolution::Def(hir::ModuleDef::Module(module)) = resolution {
25 let module_scope = module.scope(ctx.db, context_module); 25 let module_scope = module.scope(ctx.db, context_module);
26 for (name, def) in module_scope { 26 for (name, def) in module_scope {
27 if let ScopeDef::MacroDef(macro_def) = def { 27 if let hir::ScopeDef::MacroDef(macro_def) = def {
28 acc.add_macro(ctx, Some(name.to_string()), macro_def); 28 acc.add_macro(ctx, Some(name.clone()), macro_def);
29 } 29 }
30 if let ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = def { 30 if let hir::ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = def {
31 acc.add_resolution(ctx, name.to_string(), &def); 31 acc.add_resolution(ctx, name, &def);
32 } 32 }
33 } 33 }
34 } 34 }
@@ -42,11 +42,11 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
42 }); 42 });
43 43
44 match resolution { 44 match resolution {
45 PathResolution::Def(hir::ModuleDef::Module(module)) => { 45 hir::PathResolution::Def(hir::ModuleDef::Module(module)) => {
46 let module_scope = module.scope(ctx.db, context_module); 46 let module_scope = module.scope(ctx.db, context_module);
47 for (name, def) in module_scope { 47 for (name, def) in module_scope {
48 if ctx.use_item_syntax.is_some() { 48 if ctx.use_item_syntax.is_some() {
49 if let ScopeDef::Unknown = def { 49 if let hir::ScopeDef::Unknown = def {
50 if let Some(name_ref) = ctx.name_ref_syntax.as_ref() { 50 if let Some(name_ref) = ctx.name_ref_syntax.as_ref() {
51 if name_ref.syntax().text() == name.to_string().as_str() { 51 if name_ref.syntax().text() == name.to_string().as_str() {
52 // for `use self::foo$0`, don't suggest `foo` as a completion 52 // for `use self::foo$0`, don't suggest `foo` as a completion
@@ -57,20 +57,20 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
57 } 57 }
58 } 58 }
59 59
60 acc.add_resolution(ctx, name.to_string(), &def); 60 acc.add_resolution(ctx, name, &def);
61 } 61 }
62 } 62 }
63 PathResolution::Def(def @ hir::ModuleDef::Adt(_)) 63 hir::PathResolution::Def(def @ hir::ModuleDef::Adt(_))
64 | PathResolution::Def(def @ hir::ModuleDef::TypeAlias(_)) 64 | hir::PathResolution::Def(def @ hir::ModuleDef::TypeAlias(_))
65 | PathResolution::Def(def @ hir::ModuleDef::BuiltinType(_)) => { 65 | hir::PathResolution::Def(def @ hir::ModuleDef::BuiltinType(_)) => {
66 if let hir::ModuleDef::Adt(Adt::Enum(e)) = def { 66 if let hir::ModuleDef::Adt(hir::Adt::Enum(e)) = def {
67 add_enum_variants(ctx, acc, e); 67 add_enum_variants(ctx, acc, e);
68 } 68 }
69 let ty = match def { 69 let ty = match def {
70 hir::ModuleDef::Adt(adt) => adt.ty(ctx.db), 70 hir::ModuleDef::Adt(adt) => adt.ty(ctx.db),
71 hir::ModuleDef::TypeAlias(a) => { 71 hir::ModuleDef::TypeAlias(a) => {
72 let ty = a.ty(ctx.db); 72 let ty = a.ty(ctx.db);
73 if let Some(Adt::Enum(e)) = ty.as_adt() { 73 if let Some(hir::Adt::Enum(e)) = ty.as_adt() {
74 cov_mark::hit!(completes_variant_through_alias); 74 cov_mark::hit!(completes_variant_through_alias);
75 add_enum_variants(ctx, acc, e); 75 add_enum_variants(ctx, acc, e);
76 } 76 }
@@ -117,7 +117,7 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
117 }); 117 });
118 } 118 }
119 } 119 }
120 PathResolution::Def(hir::ModuleDef::Trait(t)) => { 120 hir::PathResolution::Def(hir::ModuleDef::Trait(t)) => {
121 // Handles `Trait::assoc` as well as `<Ty as Trait>::assoc`. 121 // Handles `Trait::assoc` as well as `<Ty as Trait>::assoc`.
122 for item in t.items(ctx.db) { 122 for item in t.items(ctx.db) {
123 if context_module.map_or(false, |m| !item.is_visible_from(ctx.db, m)) { 123 if context_module.map_or(false, |m| !item.is_visible_from(ctx.db, m)) {
@@ -130,15 +130,15 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
130 } 130 }
131 } 131 }
132 } 132 }
133 PathResolution::TypeParam(_) | PathResolution::SelfType(_) => { 133 hir::PathResolution::TypeParam(_) | hir::PathResolution::SelfType(_) => {
134 if let Some(krate) = ctx.krate { 134 if let Some(krate) = ctx.krate {
135 let ty = match resolution { 135 let ty = match resolution {
136 PathResolution::TypeParam(param) => param.ty(ctx.db), 136 hir::PathResolution::TypeParam(param) => param.ty(ctx.db),
137 PathResolution::SelfType(impl_def) => impl_def.self_ty(ctx.db), 137 hir::PathResolution::SelfType(impl_def) => impl_def.self_ty(ctx.db),
138 _ => return, 138 _ => return,
139 }; 139 };
140 140
141 if let Some(Adt::Enum(e)) = ty.as_adt() { 141 if let Some(hir::Adt::Enum(e)) = ty.as_adt() {
142 add_enum_variants(ctx, acc, e); 142 add_enum_variants(ctx, acc, e);
143 } 143 }
144 144
diff --git a/crates/ide_completion/src/completions/unqualified_path.rs b/crates/ide_completion/src/completions/unqualified_path.rs
index ede07f605..9db8516d0 100644
--- a/crates/ide_completion/src/completions/unqualified_path.rs
+++ b/crates/ide_completion/src/completions/unqualified_path.rs
@@ -14,10 +14,10 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC
14 if ctx.expects_assoc_item() { 14 if ctx.expects_assoc_item() {
15 ctx.scope.process_all_names(&mut |name, def| { 15 ctx.scope.process_all_names(&mut |name, def| {
16 if let ScopeDef::MacroDef(macro_def) = def { 16 if let ScopeDef::MacroDef(macro_def) = def {
17 acc.add_macro(ctx, Some(name.to_string()), macro_def); 17 acc.add_macro(ctx, Some(name.clone()), macro_def);
18 } 18 }
19 if let ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = def { 19 if let ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = def {
20 acc.add_resolution(ctx, name.to_string(), &def); 20 acc.add_resolution(ctx, name, &def);
21 } 21 }
22 }); 22 });
23 return; 23 return;
@@ -27,7 +27,7 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC
27 cov_mark::hit!(only_completes_modules_in_import); 27 cov_mark::hit!(only_completes_modules_in_import);
28 ctx.scope.process_all_names(&mut |name, res| { 28 ctx.scope.process_all_names(&mut |name, res| {
29 if let ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = res { 29 if let ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = res {
30 acc.add_resolution(ctx, name.to_string(), &res); 30 acc.add_resolution(ctx, name, &res);
31 } 31 }
32 }); 32 });
33 return; 33 return;
@@ -45,7 +45,7 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC
45 cov_mark::hit!(skip_lifetime_completion); 45 cov_mark::hit!(skip_lifetime_completion);
46 return; 46 return;
47 } 47 }
48 acc.add_resolution(ctx, name.to_string(), &res); 48 acc.add_resolution(ctx, name, &res);
49 }); 49 });
50} 50}
51 51
diff --git a/crates/ide_completion/src/render.rs b/crates/ide_completion/src/render.rs
index 91300c56e..425dd0247 100644
--- a/crates/ide_completion/src/render.rs
+++ b/crates/ide_completion/src/render.rs
@@ -10,9 +10,7 @@ pub(crate) mod type_alias;
10 10
11mod builder_ext; 11mod builder_ext;
12 12
13use hir::{ 13use hir::{AsAssocItem, HasAttrs, HirDisplay};
14 AsAssocItem, Documentation, HasAttrs, HirDisplay, ModuleDef, Mutability, ScopeDef, Type,
15};
16use ide_db::{ 14use ide_db::{
17 helpers::{item_name, SnippetCap}, 15 helpers::{item_name, SnippetCap},
18 RootDatabase, SymbolKind, 16 RootDatabase, SymbolKind,
@@ -21,31 +19,30 @@ use syntax::TextRange;
21 19
22use crate::{ 20use crate::{
23 item::{CompletionRelevanceTypeMatch, ImportEdit}, 21 item::{CompletionRelevanceTypeMatch, ImportEdit},
22 render::{enum_variant::render_variant, function::render_fn, macro_::render_macro},
24 CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, CompletionRelevance, 23 CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, CompletionRelevance,
25}; 24};
26 25
27use crate::render::{enum_variant::render_variant, function::render_fn, macro_::render_macro};
28
29pub(crate) fn render_field<'a>( 26pub(crate) fn render_field<'a>(
30 ctx: RenderContext<'a>, 27 ctx: RenderContext<'a>,
31 field: hir::Field, 28 field: hir::Field,
32 ty: &Type, 29 ty: &hir::Type,
33) -> CompletionItem { 30) -> CompletionItem {
34 Render::new(ctx).add_field(field, ty) 31 Render::new(ctx).render_field(field, ty)
35} 32}
36 33
37pub(crate) fn render_tuple_field<'a>( 34pub(crate) fn render_tuple_field<'a>(
38 ctx: RenderContext<'a>, 35 ctx: RenderContext<'a>,
39 field: usize, 36 field: usize,
40 ty: &Type, 37 ty: &hir::Type,
41) -> CompletionItem { 38) -> CompletionItem {
42 Render::new(ctx).add_tuple_field(field, ty) 39 Render::new(ctx).render_tuple_field(field, ty)
43} 40}
44 41
45pub(crate) fn render_resolution<'a>( 42pub(crate) fn render_resolution<'a>(
46 ctx: RenderContext<'a>, 43 ctx: RenderContext<'a>,
47 local_name: String, 44 local_name: hir::Name,
48 resolution: &ScopeDef, 45 resolution: &hir::ScopeDef,
49) -> Option<CompletionItem> { 46) -> Option<CompletionItem> {
50 Render::new(ctx).render_resolution(local_name, None, resolution) 47 Render::new(ctx).render_resolution(local_name, None, resolution)
51} 48}
@@ -54,12 +51,12 @@ pub(crate) fn render_resolution_with_import<'a>(
54 ctx: RenderContext<'a>, 51 ctx: RenderContext<'a>,
55 import_edit: ImportEdit, 52 import_edit: ImportEdit,
56) -> Option<CompletionItem> { 53) -> Option<CompletionItem> {
57 let resolution = ScopeDef::from(import_edit.import.original_item); 54 let resolution = hir::ScopeDef::from(import_edit.import.original_item);
58 let local_name = match resolution { 55 let local_name = match resolution {
59 ScopeDef::ModuleDef(ModuleDef::Function(f)) => f.name(ctx.completion.db).to_string(), 56 hir::ScopeDef::ModuleDef(hir::ModuleDef::Function(f)) => f.name(ctx.completion.db),
60 ScopeDef::ModuleDef(ModuleDef::Const(c)) => c.name(ctx.completion.db)?.to_string(), 57 hir::ScopeDef::ModuleDef(hir::ModuleDef::Const(c)) => c.name(ctx.completion.db)?,
61 ScopeDef::ModuleDef(ModuleDef::TypeAlias(t)) => t.name(ctx.completion.db).to_string(), 58 hir::ScopeDef::ModuleDef(hir::ModuleDef::TypeAlias(t)) => t.name(ctx.completion.db),
62 _ => item_name(ctx.db(), import_edit.import.original_item)?.to_string(), 59 _ => item_name(ctx.db(), import_edit.import.original_item)?,
63 }; 60 };
64 Render::new(ctx).render_resolution(local_name, Some(import_edit), &resolution).map( 61 Render::new(ctx).render_resolution(local_name, Some(import_edit), &resolution).map(
65 |mut item| { 62 |mut item| {
@@ -113,7 +110,7 @@ impl<'a> RenderContext<'a> {
113 || assoc.containing_trait(db).map(|trait_| self.is_deprecated(trait_)).unwrap_or(false) 110 || assoc.containing_trait(db).map(|trait_| self.is_deprecated(trait_)).unwrap_or(false)
114 } 111 }
115 112
116 fn docs(&self, node: impl HasAttrs) -> Option<Documentation> { 113 fn docs(&self, node: impl HasAttrs) -> Option<hir::Documentation> {
117 node.docs(self.db()) 114 node.docs(self.db())
118 } 115 }
119} 116}
@@ -129,14 +126,11 @@ impl<'a> Render<'a> {
129 Render { ctx } 126 Render { ctx }
130 } 127 }
131 128
132 fn add_field(&mut self, field: hir::Field, ty: &Type) -> CompletionItem { 129 fn render_field(&self, field: hir::Field, ty: &hir::Type) -> CompletionItem {
133 let is_deprecated = self.ctx.is_deprecated(field); 130 let is_deprecated = self.ctx.is_deprecated(field);
134 let name = field.name(self.ctx.db()); 131 let name = field.name(self.ctx.db()).to_string();
135 let mut item = CompletionItem::new( 132 let mut item =
136 CompletionKind::Reference, 133 CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), name.clone());
137 self.ctx.source_range(),
138 name.to_string(),
139 );
140 item.kind(SymbolKind::Field) 134 item.kind(SymbolKind::Field)
141 .detail(ty.display(self.ctx.db()).to_string()) 135 .detail(ty.display(self.ctx.db()).to_string())
142 .set_documentation(field.docs(self.ctx.db())) 136 .set_documentation(field.docs(self.ctx.db()))
@@ -144,7 +138,7 @@ impl<'a> Render<'a> {
144 138
145 item.set_relevance(CompletionRelevance { 139 item.set_relevance(CompletionRelevance {
146 type_match: compute_type_match(self.ctx.completion, ty), 140 type_match: compute_type_match(self.ctx.completion, ty),
147 exact_name_match: compute_exact_name_match(self.ctx.completion, name.to_string()), 141 exact_name_match: compute_exact_name_match(self.ctx.completion, &name),
148 ..CompletionRelevance::default() 142 ..CompletionRelevance::default()
149 }); 143 });
150 144
@@ -157,7 +151,7 @@ impl<'a> Render<'a> {
157 item.build() 151 item.build()
158 } 152 }
159 153
160 fn add_tuple_field(&mut self, field: usize, ty: &Type) -> CompletionItem { 154 fn render_tuple_field(&self, field: usize, ty: &hir::Type) -> CompletionItem {
161 let mut item = CompletionItem::new( 155 let mut item = CompletionItem::new(
162 CompletionKind::Reference, 156 CompletionKind::Reference,
163 self.ctx.source_range(), 157 self.ctx.source_range(),
@@ -171,71 +165,82 @@ impl<'a> Render<'a> {
171 165
172 fn render_resolution( 166 fn render_resolution(
173 self, 167 self,
174 local_name: String, 168 local_name: hir::Name,
175 import_to_add: Option<ImportEdit>, 169 import_to_add: Option<ImportEdit>,
176 resolution: &ScopeDef, 170 resolution: &hir::ScopeDef,
177 ) -> Option<CompletionItem> { 171 ) -> Option<CompletionItem> {
178 let _p = profile::span("render_resolution"); 172 let _p = profile::span("render_resolution");
179 use hir::ModuleDef::*; 173 use hir::ModuleDef::*;
180 174
181 let completion_kind = match resolution { 175 let completion_kind = match resolution {
182 ScopeDef::ModuleDef(BuiltinType(..)) => CompletionKind::BuiltinType, 176 hir::ScopeDef::ModuleDef(BuiltinType(..)) => CompletionKind::BuiltinType,
183 _ => CompletionKind::Reference, 177 _ => CompletionKind::Reference,
184 }; 178 };
185 179
186 let kind = match resolution { 180 let kind = match resolution {
187 ScopeDef::ModuleDef(Function(func)) => { 181 hir::ScopeDef::ModuleDef(Function(func)) => {
188 return render_fn(self.ctx, import_to_add, Some(local_name), *func); 182 return render_fn(self.ctx, import_to_add, Some(local_name), *func);
189 } 183 }
190 ScopeDef::ModuleDef(Variant(_)) if self.ctx.completion.is_pat_or_const.is_some() => { 184 hir::ScopeDef::ModuleDef(Variant(_))
185 if self.ctx.completion.is_pat_or_const.is_some() =>
186 {
191 CompletionItemKind::SymbolKind(SymbolKind::Variant) 187 CompletionItemKind::SymbolKind(SymbolKind::Variant)
192 } 188 }
193 ScopeDef::ModuleDef(Variant(var)) => { 189 hir::ScopeDef::ModuleDef(Variant(var)) => {
194 let item = render_variant(self.ctx, import_to_add, Some(local_name), *var, None); 190 let item = render_variant(self.ctx, import_to_add, Some(local_name), *var, None);
195 return Some(item); 191 return Some(item);
196 } 192 }
197 ScopeDef::MacroDef(mac) => { 193 hir::ScopeDef::MacroDef(mac) => {
198 let item = render_macro(self.ctx, import_to_add, local_name, *mac); 194 let item = render_macro(self.ctx, import_to_add, local_name, *mac);
199 return item; 195 return item;
200 } 196 }
201 197
202 ScopeDef::ModuleDef(Module(..)) => CompletionItemKind::SymbolKind(SymbolKind::Module), 198 hir::ScopeDef::ModuleDef(Module(..)) => {
203 ScopeDef::ModuleDef(Adt(adt)) => CompletionItemKind::SymbolKind(match adt { 199 CompletionItemKind::SymbolKind(SymbolKind::Module)
200 }
201 hir::ScopeDef::ModuleDef(Adt(adt)) => CompletionItemKind::SymbolKind(match adt {
204 hir::Adt::Struct(_) => SymbolKind::Struct, 202 hir::Adt::Struct(_) => SymbolKind::Struct,
205 hir::Adt::Union(_) => SymbolKind::Union, 203 hir::Adt::Union(_) => SymbolKind::Union,
206 hir::Adt::Enum(_) => SymbolKind::Enum, 204 hir::Adt::Enum(_) => SymbolKind::Enum,
207 }), 205 }),
208 ScopeDef::ModuleDef(Const(..)) => CompletionItemKind::SymbolKind(SymbolKind::Const), 206 hir::ScopeDef::ModuleDef(Const(..)) => {
209 ScopeDef::ModuleDef(Static(..)) => CompletionItemKind::SymbolKind(SymbolKind::Static), 207 CompletionItemKind::SymbolKind(SymbolKind::Const)
210 ScopeDef::ModuleDef(Trait(..)) => CompletionItemKind::SymbolKind(SymbolKind::Trait), 208 }
211 ScopeDef::ModuleDef(TypeAlias(..)) => { 209 hir::ScopeDef::ModuleDef(Static(..)) => {
210 CompletionItemKind::SymbolKind(SymbolKind::Static)
211 }
212 hir::ScopeDef::ModuleDef(Trait(..)) => {
213 CompletionItemKind::SymbolKind(SymbolKind::Trait)
214 }
215 hir::ScopeDef::ModuleDef(TypeAlias(..)) => {
212 CompletionItemKind::SymbolKind(SymbolKind::TypeAlias) 216 CompletionItemKind::SymbolKind(SymbolKind::TypeAlias)
213 } 217 }
214 ScopeDef::ModuleDef(BuiltinType(..)) => CompletionItemKind::BuiltinType, 218 hir::ScopeDef::ModuleDef(BuiltinType(..)) => CompletionItemKind::BuiltinType,
215 ScopeDef::GenericParam(param) => CompletionItemKind::SymbolKind(match param { 219 hir::ScopeDef::GenericParam(param) => CompletionItemKind::SymbolKind(match param {
216 hir::GenericParam::TypeParam(_) => SymbolKind::TypeParam, 220 hir::GenericParam::TypeParam(_) => SymbolKind::TypeParam,
217 hir::GenericParam::LifetimeParam(_) => SymbolKind::LifetimeParam, 221 hir::GenericParam::LifetimeParam(_) => SymbolKind::LifetimeParam,
218 hir::GenericParam::ConstParam(_) => SymbolKind::ConstParam, 222 hir::GenericParam::ConstParam(_) => SymbolKind::ConstParam,
219 }), 223 }),
220 ScopeDef::Local(..) => CompletionItemKind::SymbolKind(SymbolKind::Local), 224 hir::ScopeDef::Local(..) => CompletionItemKind::SymbolKind(SymbolKind::Local),
221 ScopeDef::Label(..) => CompletionItemKind::SymbolKind(SymbolKind::Label), 225 hir::ScopeDef::Label(..) => CompletionItemKind::SymbolKind(SymbolKind::Label),
222 ScopeDef::AdtSelfType(..) | ScopeDef::ImplSelfType(..) => { 226 hir::ScopeDef::AdtSelfType(..) | hir::ScopeDef::ImplSelfType(..) => {
223 CompletionItemKind::SymbolKind(SymbolKind::SelfParam) 227 CompletionItemKind::SymbolKind(SymbolKind::SelfParam)
224 } 228 }
225 ScopeDef::Unknown => { 229 hir::ScopeDef::Unknown => {
226 let mut item = CompletionItem::new( 230 let mut item = CompletionItem::new(
227 CompletionKind::Reference, 231 CompletionKind::Reference,
228 self.ctx.source_range(), 232 self.ctx.source_range(),
229 local_name, 233 local_name.to_string(),
230 ); 234 );
231 item.kind(CompletionItemKind::UnresolvedReference).add_import(import_to_add); 235 item.kind(CompletionItemKind::UnresolvedReference).add_import(import_to_add);
232 return Some(item.build()); 236 return Some(item.build());
233 } 237 }
234 }; 238 };
235 239
240 let local_name = local_name.to_string();
236 let mut item = 241 let mut item =
237 CompletionItem::new(completion_kind, self.ctx.source_range(), local_name.clone()); 242 CompletionItem::new(completion_kind, self.ctx.source_range(), local_name.clone());
238 if let ScopeDef::Local(local) = resolution { 243 if let hir::ScopeDef::Local(local) = resolution {
239 let ty = local.ty(self.ctx.db()); 244 let ty = local.ty(self.ctx.db());
240 if !ty.is_unknown() { 245 if !ty.is_unknown() {
241 item.detail(ty.display(self.ctx.db()).to_string()); 246 item.detail(ty.display(self.ctx.db()).to_string());
@@ -260,8 +265,10 @@ impl<'a> Render<'a> {
260 { 265 {
261 if let Some(cap) = self.ctx.snippet_cap() { 266 if let Some(cap) = self.ctx.snippet_cap() {
262 let has_non_default_type_params = match resolution { 267 let has_non_default_type_params = match resolution {
263 ScopeDef::ModuleDef(Adt(it)) => it.has_non_default_type_params(self.ctx.db()), 268 hir::ScopeDef::ModuleDef(Adt(it)) => {
264 ScopeDef::ModuleDef(TypeAlias(it)) => { 269 it.has_non_default_type_params(self.ctx.db())
270 }
271 hir::ScopeDef::ModuleDef(TypeAlias(it)) => {
265 it.has_non_default_type_params(self.ctx.db()) 272 it.has_non_default_type_params(self.ctx.db())
266 } 273 }
267 _ => false, 274 _ => false,
@@ -281,26 +288,26 @@ impl<'a> Render<'a> {
281 Some(item.build()) 288 Some(item.build())
282 } 289 }
283 290
284 fn docs(&self, resolution: &ScopeDef) -> Option<Documentation> { 291 fn docs(&self, resolution: &hir::ScopeDef) -> Option<hir::Documentation> {
285 use hir::ModuleDef::*; 292 use hir::ModuleDef::*;
286 match resolution { 293 match resolution {
287 ScopeDef::ModuleDef(Module(it)) => it.docs(self.ctx.db()), 294 hir::ScopeDef::ModuleDef(Module(it)) => it.docs(self.ctx.db()),
288 ScopeDef::ModuleDef(Adt(it)) => it.docs(self.ctx.db()), 295 hir::ScopeDef::ModuleDef(Adt(it)) => it.docs(self.ctx.db()),
289 ScopeDef::ModuleDef(Variant(it)) => it.docs(self.ctx.db()), 296 hir::ScopeDef::ModuleDef(Variant(it)) => it.docs(self.ctx.db()),
290 ScopeDef::ModuleDef(Const(it)) => it.docs(self.ctx.db()), 297 hir::ScopeDef::ModuleDef(Const(it)) => it.docs(self.ctx.db()),
291 ScopeDef::ModuleDef(Static(it)) => it.docs(self.ctx.db()), 298 hir::ScopeDef::ModuleDef(Static(it)) => it.docs(self.ctx.db()),
292 ScopeDef::ModuleDef(Trait(it)) => it.docs(self.ctx.db()), 299 hir::ScopeDef::ModuleDef(Trait(it)) => it.docs(self.ctx.db()),
293 ScopeDef::ModuleDef(TypeAlias(it)) => it.docs(self.ctx.db()), 300 hir::ScopeDef::ModuleDef(TypeAlias(it)) => it.docs(self.ctx.db()),
294 _ => None, 301 _ => None,
295 } 302 }
296 } 303 }
297 304
298 fn is_deprecated(&self, resolution: &ScopeDef) -> bool { 305 fn is_deprecated(&self, resolution: &hir::ScopeDef) -> bool {
299 match resolution { 306 match resolution {
300 ScopeDef::ModuleDef(it) => self.ctx.is_deprecated_assoc_item(*it), 307 hir::ScopeDef::ModuleDef(it) => self.ctx.is_deprecated_assoc_item(*it),
301 ScopeDef::MacroDef(it) => self.ctx.is_deprecated(*it), 308 hir::ScopeDef::MacroDef(it) => self.ctx.is_deprecated(*it),
302 ScopeDef::GenericParam(it) => self.ctx.is_deprecated(*it), 309 hir::ScopeDef::GenericParam(it) => self.ctx.is_deprecated(*it),
303 ScopeDef::AdtSelfType(it) => self.ctx.is_deprecated(*it), 310 hir::ScopeDef::AdtSelfType(it) => self.ctx.is_deprecated(*it),
304 _ => false, 311 _ => false,
305 } 312 }
306 } 313 }
@@ -327,21 +334,23 @@ fn compute_type_match(
327 } 334 }
328} 335}
329 336
330fn compute_exact_name_match(ctx: &CompletionContext, completion_name: impl Into<String>) -> bool { 337fn compute_exact_name_match(ctx: &CompletionContext, completion_name: &str) -> bool {
331 let completion_name = completion_name.into();
332 ctx.expected_name.as_ref().map_or(false, |name| name.text() == completion_name) 338 ctx.expected_name.as_ref().map_or(false, |name| name.text() == completion_name)
333} 339}
334 340
335fn compute_ref_match(ctx: &CompletionContext, completion_ty: &hir::Type) -> Option<Mutability> { 341fn compute_ref_match(
342 ctx: &CompletionContext,
343 completion_ty: &hir::Type,
344) -> Option<hir::Mutability> {
336 let expected_type = ctx.expected_type.as_ref()?; 345 let expected_type = ctx.expected_type.as_ref()?;
337 if completion_ty != expected_type { 346 if completion_ty != expected_type {
338 let expected_type_without_ref = expected_type.remove_ref()?; 347 let expected_type_without_ref = expected_type.remove_ref()?;
339 if completion_ty.autoderef(ctx.db).any(|deref_ty| deref_ty == expected_type_without_ref) { 348 if completion_ty.autoderef(ctx.db).any(|deref_ty| deref_ty == expected_type_without_ref) {
340 cov_mark::hit!(suggest_ref); 349 cov_mark::hit!(suggest_ref);
341 let mutability = if expected_type.is_mutable_reference() { 350 let mutability = if expected_type.is_mutable_reference() {
342 Mutability::Mut 351 hir::Mutability::Mut
343 } else { 352 } else {
344 Mutability::Shared 353 hir::Mutability::Shared
345 }; 354 };
346 return Some(mutability); 355 return Some(mutability);
347 }; 356 };
diff --git a/crates/ide_completion/src/render/enum_variant.rs b/crates/ide_completion/src/render/enum_variant.rs
index 0c0c71134..28f056e77 100644
--- a/crates/ide_completion/src/render/enum_variant.rs
+++ b/crates/ide_completion/src/render/enum_variant.rs
@@ -1,6 +1,8 @@
1//! Renderer for `enum` variants. 1//! Renderer for `enum` variants.
2 2
3use hir::{HasAttrs, HirDisplay, ModPath, StructKind}; 3use std::iter;
4
5use hir::{HasAttrs, HirDisplay};
4use ide_db::SymbolKind; 6use ide_db::SymbolKind;
5use itertools::Itertools; 7use itertools::Itertools;
6 8
@@ -13,9 +15,9 @@ use crate::{
13pub(crate) fn render_variant<'a>( 15pub(crate) fn render_variant<'a>(
14 ctx: RenderContext<'a>, 16 ctx: RenderContext<'a>,
15 import_to_add: Option<ImportEdit>, 17 import_to_add: Option<ImportEdit>,
16 local_name: Option<String>, 18 local_name: Option<hir::Name>,
17 variant: hir::Variant, 19 variant: hir::Variant,
18 path: Option<ModPath>, 20 path: Option<hir::ModPath>,
19) -> CompletionItem { 21) -> CompletionItem {
20 let _p = profile::span("render_enum_variant"); 22 let _p = profile::span("render_enum_variant");
21 EnumRender::new(ctx, local_name, variant, path).render(import_to_add) 23 EnumRender::new(ctx, local_name, variant, path).render(import_to_add)
@@ -24,42 +26,45 @@ pub(crate) fn render_variant<'a>(
24#[derive(Debug)] 26#[derive(Debug)]
25struct EnumRender<'a> { 27struct EnumRender<'a> {
26 ctx: RenderContext<'a>, 28 ctx: RenderContext<'a>,
27 name: String, 29 name: hir::Name,
28 variant: hir::Variant, 30 variant: hir::Variant,
29 path: Option<ModPath>, 31 path: Option<hir::ModPath>,
30 qualified_name: String, 32 qualified_name: hir::ModPath,
31 short_qualified_name: String, 33 short_qualified_name: hir::ModPath,
32 variant_kind: StructKind, 34 variant_kind: hir::StructKind,
33} 35}
34 36
35impl<'a> EnumRender<'a> { 37impl<'a> EnumRender<'a> {
36 fn new( 38 fn new(
37 ctx: RenderContext<'a>, 39 ctx: RenderContext<'a>,
38 local_name: Option<String>, 40 local_name: Option<hir::Name>,
39 variant: hir::Variant, 41 variant: hir::Variant,
40 path: Option<ModPath>, 42 path: Option<hir::ModPath>,
41 ) -> EnumRender<'a> { 43 ) -> EnumRender<'a> {
42 let name = local_name.unwrap_or_else(|| variant.name(ctx.db()).to_string()); 44 let name = local_name.unwrap_or_else(|| variant.name(ctx.db()));
43 let variant_kind = variant.kind(ctx.db()); 45 let variant_kind = variant.kind(ctx.db());
44 46
45 let (qualified_name, short_qualified_name) = match &path { 47 let (qualified_name, short_qualified_name) = match &path {
46 Some(path) => { 48 Some(path) => {
47 let full = path.to_string(); 49 let short = hir::ModPath::from_segments(
48 let segments = path.segments(); 50 hir::PathKind::Plain,
49 let short = segments[segments.len().saturating_sub(2)..].iter().join("::"); 51 path.segments().iter().skip(path.segments().len().saturating_sub(2)).cloned(),
50 (full, short) 52 );
53 (path.clone(), short)
51 } 54 }
52 None => (name.to_string(), name.to_string()), 55 None => (
56 hir::ModPath::from_segments(hir::PathKind::Plain, iter::once(name.clone())),
57 hir::ModPath::from_segments(hir::PathKind::Plain, iter::once(name.clone())),
58 ),
53 }; 59 };
54 60
55 EnumRender { ctx, name, variant, path, qualified_name, short_qualified_name, variant_kind } 61 EnumRender { ctx, name, variant, path, qualified_name, short_qualified_name, variant_kind }
56 } 62 }
57
58 fn render(self, import_to_add: Option<ImportEdit>) -> CompletionItem { 63 fn render(self, import_to_add: Option<ImportEdit>) -> CompletionItem {
59 let mut item = CompletionItem::new( 64 let mut item = CompletionItem::new(
60 CompletionKind::Reference, 65 CompletionKind::Reference,
61 self.ctx.source_range(), 66 self.ctx.source_range(),
62 self.qualified_name.clone(), 67 self.qualified_name.to_string(),
63 ); 68 );
64 item.kind(SymbolKind::Variant) 69 item.kind(SymbolKind::Variant)
65 .set_documentation(self.variant.docs(self.ctx.db())) 70 .set_documentation(self.variant.docs(self.ctx.db()))
@@ -67,12 +72,16 @@ impl<'a> EnumRender<'a> {
67 .add_import(import_to_add) 72 .add_import(import_to_add)
68 .detail(self.detail()); 73 .detail(self.detail());
69 74
70 if self.variant_kind == StructKind::Tuple { 75 if self.variant_kind == hir::StructKind::Tuple {
71 cov_mark::hit!(inserts_parens_for_tuple_enums); 76 cov_mark::hit!(inserts_parens_for_tuple_enums);
72 let params = Params::Anonymous(self.variant.fields(self.ctx.db()).len()); 77 let params = Params::Anonymous(self.variant.fields(self.ctx.db()).len());
73 item.add_call_parens(self.ctx.completion, self.short_qualified_name, params); 78 item.add_call_parens(
79 self.ctx.completion,
80 self.short_qualified_name.to_string(),
81 params,
82 );
74 } else if self.path.is_some() { 83 } else if self.path.is_some() {
75 item.lookup_by(self.short_qualified_name); 84 item.lookup_by(self.short_qualified_name.to_string());
76 } 85 }
77 86
78 let ty = self.variant.parent_enum(self.ctx.completion.db).ty(self.ctx.completion.db); 87 let ty = self.variant.parent_enum(self.ctx.completion.db).ty(self.ctx.completion.db);
@@ -96,11 +105,11 @@ impl<'a> EnumRender<'a> {
96 .map(|field| (field.name(self.ctx.db()), field.ty(self.ctx.db()))); 105 .map(|field| (field.name(self.ctx.db()), field.ty(self.ctx.db())));
97 106
98 match self.variant_kind { 107 match self.variant_kind {
99 StructKind::Tuple | StructKind::Unit => format!( 108 hir::StructKind::Tuple | hir::StructKind::Unit => format!(
100 "({})", 109 "({})",
101 detail_types.map(|(_, t)| t.display(self.ctx.db()).to_string()).format(", ") 110 detail_types.map(|(_, t)| t.display(self.ctx.db()).to_string()).format(", ")
102 ), 111 ),
103 StructKind::Record => format!( 112 hir::StructKind::Record => format!(
104 "{{ {} }}", 113 "{{ {} }}",
105 detail_types 114 detail_types
106 .map(|(n, t)| format!("{}: {}", n, t.display(self.ctx.db()).to_string())) 115 .map(|(n, t)| format!("{}: {}", n, t.display(self.ctx.db()).to_string()))
diff --git a/crates/ide_completion/src/render/function.rs b/crates/ide_completion/src/render/function.rs
index d681e2c91..63bd66926 100644
--- a/crates/ide_completion/src/render/function.rs
+++ b/crates/ide_completion/src/render/function.rs
@@ -1,6 +1,6 @@
1//! Renderer for function calls. 1//! Renderer for function calls.
2 2
3use hir::{HasSource, HirDisplay, Type}; 3use hir::{HasSource, HirDisplay};
4use ide_db::SymbolKind; 4use ide_db::SymbolKind;
5use itertools::Itertools; 5use itertools::Itertools;
6use syntax::ast::Fn; 6use syntax::ast::Fn;
@@ -16,7 +16,7 @@ use crate::{
16pub(crate) fn render_fn<'a>( 16pub(crate) fn render_fn<'a>(
17 ctx: RenderContext<'a>, 17 ctx: RenderContext<'a>,
18 import_to_add: Option<ImportEdit>, 18 import_to_add: Option<ImportEdit>,
19 local_name: Option<String>, 19 local_name: Option<hir::Name>,
20 fn_: hir::Function, 20 fn_: hir::Function,
21) -> Option<CompletionItem> { 21) -> Option<CompletionItem> {
22 let _p = profile::span("render_fn"); 22 let _p = profile::span("render_fn");
@@ -26,7 +26,7 @@ pub(crate) fn render_fn<'a>(
26pub(crate) fn render_method<'a>( 26pub(crate) fn render_method<'a>(
27 ctx: RenderContext<'a>, 27 ctx: RenderContext<'a>,
28 import_to_add: Option<ImportEdit>, 28 import_to_add: Option<ImportEdit>,
29 local_name: Option<String>, 29 local_name: Option<hir::Name>,
30 fn_: hir::Function, 30 fn_: hir::Function,
31) -> Option<CompletionItem> { 31) -> Option<CompletionItem> {
32 let _p = profile::span("render_method"); 32 let _p = profile::span("render_method");
@@ -45,11 +45,11 @@ struct FunctionRender<'a> {
45impl<'a> FunctionRender<'a> { 45impl<'a> FunctionRender<'a> {
46 fn new( 46 fn new(
47 ctx: RenderContext<'a>, 47 ctx: RenderContext<'a>,
48 local_name: Option<String>, 48 local_name: Option<hir::Name>,
49 fn_: hir::Function, 49 fn_: hir::Function,
50 is_method: bool, 50 is_method: bool,
51 ) -> Option<FunctionRender<'a>> { 51 ) -> Option<FunctionRender<'a>> {
52 let name = local_name.unwrap_or_else(|| fn_.name(ctx.db()).to_string()); 52 let name = local_name.unwrap_or_else(|| fn_.name(ctx.db())).to_string();
53 let ast_node = fn_.source(ctx.db())?.value; 53 let ast_node = fn_.source(ctx.db())?.value;
54 54
55 Some(FunctionRender { ctx, name, func: fn_, ast_node, is_method }) 55 Some(FunctionRender { ctx, name, func: fn_, ast_node, is_method })
@@ -74,7 +74,7 @@ impl<'a> FunctionRender<'a> {
74 let ret_type = self.func.ret_type(self.ctx.db()); 74 let ret_type = self.func.ret_type(self.ctx.db());
75 item.set_relevance(CompletionRelevance { 75 item.set_relevance(CompletionRelevance {
76 type_match: compute_type_match(self.ctx.completion, &ret_type), 76 type_match: compute_type_match(self.ctx.completion, &ret_type),
77 exact_name_match: compute_exact_name_match(self.ctx.completion, self.name.clone()), 77 exact_name_match: compute_exact_name_match(self.ctx.completion, &self.name),
78 ..CompletionRelevance::default() 78 ..CompletionRelevance::default()
79 }); 79 });
80 80
@@ -129,7 +129,7 @@ impl<'a> FunctionRender<'a> {
129 format!("-> {}", ret_ty.display(self.ctx.db())) 129 format!("-> {}", ret_ty.display(self.ctx.db()))
130 } 130 }
131 131
132 fn add_arg(&self, arg: &str, ty: &Type) -> String { 132 fn add_arg(&self, arg: &str, ty: &hir::Type) -> String {
133 if let Some(derefed_ty) = ty.remove_ref() { 133 if let Some(derefed_ty) = ty.remove_ref() {
134 for (name, local) in self.ctx.completion.locals.iter() { 134 for (name, local) in self.ctx.completion.locals.iter() {
135 if name == arg && local.ty(self.ctx.db()) == derefed_ty { 135 if name == arg && local.ty(self.ctx.db()) == derefed_ty {
diff --git a/crates/ide_completion/src/render/macro_.rs b/crates/ide_completion/src/render/macro_.rs
index b90fd3890..0dfba8acc 100644
--- a/crates/ide_completion/src/render/macro_.rs
+++ b/crates/ide_completion/src/render/macro_.rs
@@ -1,6 +1,6 @@
1//! Renderer for macro invocations. 1//! Renderer for macro invocations.
2 2
3use hir::{Documentation, HasSource}; 3use hir::HasSource;
4use ide_db::SymbolKind; 4use ide_db::SymbolKind;
5use syntax::display::macro_label; 5use syntax::display::macro_label;
6 6
@@ -12,7 +12,7 @@ use crate::{
12pub(crate) fn render_macro<'a>( 12pub(crate) fn render_macro<'a>(
13 ctx: RenderContext<'a>, 13 ctx: RenderContext<'a>,
14 import_to_add: Option<ImportEdit>, 14 import_to_add: Option<ImportEdit>,
15 name: String, 15 name: hir::Name,
16 macro_: hir::MacroDef, 16 macro_: hir::MacroDef,
17) -> Option<CompletionItem> { 17) -> Option<CompletionItem> {
18 let _p = profile::span("render_macro"); 18 let _p = profile::span("render_macro");
@@ -24,13 +24,14 @@ struct MacroRender<'a> {
24 ctx: RenderContext<'a>, 24 ctx: RenderContext<'a>,
25 name: String, 25 name: String,
26 macro_: hir::MacroDef, 26 macro_: hir::MacroDef,
27 docs: Option<Documentation>, 27 docs: Option<hir::Documentation>,
28 bra: &'static str, 28 bra: &'static str,
29 ket: &'static str, 29 ket: &'static str,
30} 30}
31 31
32impl<'a> MacroRender<'a> { 32impl<'a> MacroRender<'a> {
33 fn new(ctx: RenderContext<'a>, name: String, macro_: hir::MacroDef) -> MacroRender<'a> { 33 fn new(ctx: RenderContext<'a>, name: hir::Name, macro_: hir::MacroDef) -> MacroRender<'a> {
34 let name = name.to_string();
34 let docs = ctx.docs(macro_); 35 let docs = ctx.docs(macro_);
35 let docs_str = docs.as_ref().map_or("", |s| s.as_str()); 36 let docs_str = docs.as_ref().map_or("", |s| s.as_str());
36 let (bra, ket) = guess_macro_braces(&name, docs_str); 37 let (bra, ket) = guess_macro_braces(&name, docs_str);