aboutsummaryrefslogtreecommitdiff
path: root/crates/completion/src/render.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/completion/src/render.rs')
-rw-r--r--crates/completion/src/render.rs47
1 files changed, 37 insertions, 10 deletions
diff --git a/crates/completion/src/render.rs b/crates/completion/src/render.rs
index dbb30d233..4f622d28a 100644
--- a/crates/completion/src/render.rs
+++ b/crates/completion/src/render.rs
@@ -10,7 +10,9 @@ pub(crate) mod type_alias;
10 10
11mod builder_ext; 11mod builder_ext;
12 12
13use hir::{Documentation, HasAttrs, HirDisplay, ModuleDef, Mutability, ScopeDef, Type}; 13use hir::{
14 AsAssocItem, Documentation, HasAttrs, HirDisplay, ModuleDef, Mutability, ScopeDef, Type,
15};
14use ide_db::{helpers::SnippetCap, RootDatabase}; 16use ide_db::{helpers::SnippetCap, RootDatabase};
15use syntax::TextRange; 17use syntax::TextRange;
16use test_utils::mark; 18use test_utils::mark;
@@ -91,6 +93,22 @@ impl<'a> RenderContext<'a> {
91 attrs.by_key("deprecated").exists() || attrs.by_key("rustc_deprecated").exists() 93 attrs.by_key("deprecated").exists() || attrs.by_key("rustc_deprecated").exists()
92 } 94 }
93 95
96 fn is_deprecated_assoc_item(&self, as_assoc_item: impl AsAssocItem) -> bool {
97 let db = self.db();
98 let assoc = match as_assoc_item.as_assoc_item(db) {
99 Some(assoc) => assoc,
100 None => return false,
101 };
102
103 let is_assoc_deprecated = match assoc {
104 hir::AssocItem::Function(it) => self.is_deprecated(it),
105 hir::AssocItem::Const(it) => self.is_deprecated(it),
106 hir::AssocItem::TypeAlias(it) => self.is_deprecated(it),
107 };
108 is_assoc_deprecated
109 || assoc.containing_trait(db).map(|trait_| self.is_deprecated(trait_)).unwrap_or(false)
110 }
111
94 fn docs(&self, node: impl HasAttrs) -> Option<Documentation> { 112 fn docs(&self, node: impl HasAttrs) -> Option<Documentation> {
95 node.docs(self.db()) 113 node.docs(self.db())
96 } 114 }
@@ -207,8 +225,6 @@ impl<'a> Render<'a> {
207 } 225 }
208 }; 226 };
209 227
210 let docs = self.docs(resolution);
211
212 let mut item = 228 let mut item =
213 CompletionItem::new(completion_kind, self.ctx.source_range(), local_name.clone()); 229 CompletionItem::new(completion_kind, self.ctx.source_range(), local_name.clone());
214 if let ScopeDef::Local(local) = resolution { 230 if let ScopeDef::Local(local) = resolution {
@@ -254,13 +270,14 @@ impl<'a> Render<'a> {
254 } 270 }
255 } 271 }
256 272
257 let item = item 273 Some(
258 .kind(kind) 274 item.kind(kind)
259 .add_import(import_to_add) 275 .add_import(import_to_add)
260 .set_documentation(docs) 276 .set_ref_match(ref_match)
261 .set_ref_match(ref_match) 277 .set_documentation(self.docs(resolution))
262 .build(); 278 .set_deprecated(self.is_deprecated(resolution))
263 Some(item) 279 .build(),
280 )
264 } 281 }
265 282
266 fn docs(&self, resolution: &ScopeDef) -> Option<Documentation> { 283 fn docs(&self, resolution: &ScopeDef) -> Option<Documentation> {
@@ -276,6 +293,16 @@ impl<'a> Render<'a> {
276 _ => None, 293 _ => None,
277 } 294 }
278 } 295 }
296
297 fn is_deprecated(&self, resolution: &ScopeDef) -> bool {
298 match resolution {
299 ScopeDef::ModuleDef(it) => self.ctx.is_deprecated_assoc_item(*it),
300 ScopeDef::MacroDef(it) => self.ctx.is_deprecated(*it),
301 ScopeDef::GenericParam(it) => self.ctx.is_deprecated(*it),
302 ScopeDef::AdtSelfType(it) => self.ctx.is_deprecated(*it),
303 _ => false,
304 }
305 }
279} 306}
280 307
281fn compute_score_from_active( 308fn compute_score_from_active(