diff options
Diffstat (limited to 'crates/completion/src/render.rs')
-rw-r--r-- | crates/completion/src/render.rs | 64 |
1 files changed, 46 insertions, 18 deletions
diff --git a/crates/completion/src/render.rs b/crates/completion/src/render.rs index 4b3c9702a..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 | ||
11 | mod builder_ext; | 11 | mod builder_ext; |
12 | 12 | ||
13 | use hir::{Documentation, HasAttrs, HirDisplay, ModuleDef, Mutability, ScopeDef, Type}; | 13 | use hir::{ |
14 | AsAssocItem, Documentation, HasAttrs, HirDisplay, ModuleDef, Mutability, ScopeDef, Type, | ||
15 | }; | ||
14 | use ide_db::{helpers::SnippetCap, RootDatabase}; | 16 | use ide_db::{helpers::SnippetCap, RootDatabase}; |
15 | use syntax::TextRange; | 17 | use syntax::TextRange; |
16 | use test_utils::mark; | 18 | use test_utils::mark; |
@@ -87,7 +89,24 @@ impl<'a> RenderContext<'a> { | |||
87 | } | 89 | } |
88 | 90 | ||
89 | fn is_deprecated(&self, node: impl HasAttrs) -> bool { | 91 | fn is_deprecated(&self, node: impl HasAttrs) -> bool { |
90 | node.attrs(self.db()).by_key("deprecated").exists() | 92 | let attrs = node.attrs(self.db()); |
93 | attrs.by_key("deprecated").exists() || attrs.by_key("rustc_deprecated").exists() | ||
94 | } | ||
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) | ||
91 | } | 110 | } |
92 | 111 | ||
93 | fn docs(&self, node: impl HasAttrs) -> Option<Documentation> { | 112 | fn docs(&self, node: impl HasAttrs) -> Option<Documentation> { |
@@ -206,8 +225,6 @@ impl<'a> Render<'a> { | |||
206 | } | 225 | } |
207 | }; | 226 | }; |
208 | 227 | ||
209 | let docs = self.docs(resolution); | ||
210 | |||
211 | let mut item = | 228 | let mut item = |
212 | CompletionItem::new(completion_kind, self.ctx.source_range(), local_name.clone()); | 229 | CompletionItem::new(completion_kind, self.ctx.source_range(), local_name.clone()); |
213 | if let ScopeDef::Local(local) = resolution { | 230 | if let ScopeDef::Local(local) = resolution { |
@@ -253,13 +270,14 @@ impl<'a> Render<'a> { | |||
253 | } | 270 | } |
254 | } | 271 | } |
255 | 272 | ||
256 | let item = item | 273 | Some( |
257 | .kind(kind) | 274 | item.kind(kind) |
258 | .add_import(import_to_add) | 275 | .add_import(import_to_add) |
259 | .set_documentation(docs) | 276 | .set_ref_match(ref_match) |
260 | .set_ref_match(ref_match) | 277 | .set_documentation(self.docs(resolution)) |
261 | .build(); | 278 | .set_deprecated(self.is_deprecated(resolution)) |
262 | Some(item) | 279 | .build(), |
280 | ) | ||
263 | } | 281 | } |
264 | 282 | ||
265 | fn docs(&self, resolution: &ScopeDef) -> Option<Documentation> { | 283 | fn docs(&self, resolution: &ScopeDef) -> Option<Documentation> { |
@@ -275,6 +293,16 @@ impl<'a> Render<'a> { | |||
275 | _ => None, | 293 | _ => None, |
276 | } | 294 | } |
277 | } | 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 | } | ||
278 | } | 306 | } |
279 | 307 | ||
280 | fn compute_score_from_active( | 308 | fn compute_score_from_active( |
@@ -485,7 +513,7 @@ fn main() { let _: m::Spam = S$0 } | |||
485 | r#" | 513 | r#" |
486 | #[deprecated] | 514 | #[deprecated] |
487 | fn something_deprecated() {} | 515 | fn something_deprecated() {} |
488 | #[deprecated(since = "1.0.0")] | 516 | #[rustc_deprecated(since = "1.0.0")] |
489 | fn something_else_deprecated() {} | 517 | fn something_else_deprecated() {} |
490 | 518 | ||
491 | fn main() { som$0 } | 519 | fn main() { som$0 } |
@@ -494,8 +522,8 @@ fn main() { som$0 } | |||
494 | [ | 522 | [ |
495 | CompletionItem { | 523 | CompletionItem { |
496 | label: "main()", | 524 | label: "main()", |
497 | source_range: 121..124, | 525 | source_range: 127..130, |
498 | delete: 121..124, | 526 | delete: 127..130, |
499 | insert: "main()$0", | 527 | insert: "main()$0", |
500 | kind: Function, | 528 | kind: Function, |
501 | lookup: "main", | 529 | lookup: "main", |
@@ -503,8 +531,8 @@ fn main() { som$0 } | |||
503 | }, | 531 | }, |
504 | CompletionItem { | 532 | CompletionItem { |
505 | label: "something_deprecated()", | 533 | label: "something_deprecated()", |
506 | source_range: 121..124, | 534 | source_range: 127..130, |
507 | delete: 121..124, | 535 | delete: 127..130, |
508 | insert: "something_deprecated()$0", | 536 | insert: "something_deprecated()$0", |
509 | kind: Function, | 537 | kind: Function, |
510 | lookup: "something_deprecated", | 538 | lookup: "something_deprecated", |
@@ -513,8 +541,8 @@ fn main() { som$0 } | |||
513 | }, | 541 | }, |
514 | CompletionItem { | 542 | CompletionItem { |
515 | label: "something_else_deprecated()", | 543 | label: "something_else_deprecated()", |
516 | source_range: 121..124, | 544 | source_range: 127..130, |
517 | delete: 121..124, | 545 | delete: 127..130, |
518 | insert: "something_else_deprecated()$0", | 546 | insert: "something_else_deprecated()$0", |
519 | kind: Function, | 547 | kind: Function, |
520 | lookup: "something_else_deprecated", | 548 | lookup: "something_else_deprecated", |