aboutsummaryrefslogtreecommitdiff
path: root/crates/completion/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/completion/src')
-rw-r--r--crates/completion/src/completions/flyimport.rs12
-rw-r--r--crates/completion/src/render.rs64
-rw-r--r--crates/completion/src/render/const_.rs5
-rw-r--r--crates/completion/src/render/function.rs4
-rw-r--r--crates/completion/src/render/type_alias.rs5
-rw-r--r--crates/completion/src/test_utils.rs3
6 files changed, 67 insertions, 26 deletions
diff --git a/crates/completion/src/completions/flyimport.rs b/crates/completion/src/completions/flyimport.rs
index 47e797ac8..dc0b38a16 100644
--- a/crates/completion/src/completions/flyimport.rs
+++ b/crates/completion/src/completions/flyimport.rs
@@ -48,7 +48,7 @@
48//! Note that having this flag set to `true` does not guarantee that the feature is enabled: your client needs to have the corredponding 48//! Note that having this flag set to `true` does not guarantee that the feature is enabled: your client needs to have the corredponding
49//! capability enabled. 49//! capability enabled.
50 50
51use hir::{ModPath, ScopeDef}; 51use hir::{AsAssocItem, ModPath, ScopeDef};
52use ide_db::helpers::{ 52use ide_db::helpers::{
53 import_assets::{ImportAssets, ImportCandidate}, 53 import_assets::{ImportAssets, ImportCandidate},
54 insert_use::ImportScope, 54 insert_use::ImportScope,
@@ -601,11 +601,12 @@ fn main() {
601 } 601 }
602 602
603 #[test] 603 #[test]
604 fn zero_input_assoc_item_completion() { 604 fn zero_input_deprecated_assoc_item_completion() {
605 check( 605 check(
606 r#" 606 r#"
607//- /lib.rs crate:dep 607//- /lib.rs crate:dep
608pub mod test_mod { 608pub mod test_mod {
609 #[deprecated]
609 pub trait TestTrait { 610 pub trait TestTrait {
610 const SPECIAL_CONST: u8; 611 const SPECIAL_CONST: u8;
611 type HumbleType; 612 type HumbleType;
@@ -628,7 +629,7 @@ fn main() {
628} 629}
629 "#, 630 "#,
630 expect![[r#" 631 expect![[r#"
631 me random_method() (dep::test_mod::TestTrait) fn random_method(&self) 632 me random_method() (dep::test_mod::TestTrait) fn random_method(&self) DEPRECATED
632 "#]], 633 "#]],
633 ); 634 );
634 635
@@ -636,6 +637,7 @@ fn main() {
636 r#" 637 r#"
637//- /lib.rs crate:dep 638//- /lib.rs crate:dep
638pub mod test_mod { 639pub mod test_mod {
640 #[deprecated]
639 pub trait TestTrait { 641 pub trait TestTrait {
640 const SPECIAL_CONST: u8; 642 const SPECIAL_CONST: u8;
641 type HumbleType; 643 type HumbleType;
@@ -657,8 +659,8 @@ fn main() {
657} 659}
658"#, 660"#,
659 expect![[r#" 661 expect![[r#"
660 ct SPECIAL_CONST (dep::test_mod::TestTrait) 662 ct SPECIAL_CONST (dep::test_mod::TestTrait) DEPRECATED
661 fn weird_function() (dep::test_mod::TestTrait) fn weird_function() 663 fn weird_function() (dep::test_mod::TestTrait) fn weird_function() DEPRECATED
662 "#]], 664 "#]],
663 ); 665 );
664 } 666 }
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
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;
@@ -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
280fn compute_score_from_active( 308fn compute_score_from_active(
@@ -485,7 +513,7 @@ fn main() { let _: m::Spam = S$0 }
485 r#" 513 r#"
486#[deprecated] 514#[deprecated]
487fn something_deprecated() {} 515fn something_deprecated() {}
488#[deprecated(since = "1.0.0")] 516#[rustc_deprecated(since = "1.0.0")]
489fn something_else_deprecated() {} 517fn something_else_deprecated() {}
490 518
491fn main() { som$0 } 519fn 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",
diff --git a/crates/completion/src/render/const_.rs b/crates/completion/src/render/const_.rs
index ce924f309..e46452d4e 100644
--- a/crates/completion/src/render/const_.rs
+++ b/crates/completion/src/render/const_.rs
@@ -38,7 +38,10 @@ impl<'a> ConstRender<'a> {
38 let item = CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), name) 38 let item = CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), name)
39 .kind(CompletionItemKind::Const) 39 .kind(CompletionItemKind::Const)
40 .set_documentation(self.ctx.docs(self.const_)) 40 .set_documentation(self.ctx.docs(self.const_))
41 .set_deprecated(self.ctx.is_deprecated(self.const_)) 41 .set_deprecated(
42 self.ctx.is_deprecated(self.const_)
43 || self.ctx.is_deprecated_assoc_item(self.const_),
44 )
42 .detail(detail) 45 .detail(detail)
43 .build(); 46 .build();
44 47
diff --git a/crates/completion/src/render/function.rs b/crates/completion/src/render/function.rs
index f5b0ce3e3..8f4c66211 100644
--- a/crates/completion/src/render/function.rs
+++ b/crates/completion/src/render/function.rs
@@ -44,7 +44,9 @@ impl<'a> FunctionRender<'a> {
44 CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), self.name.clone()) 44 CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), self.name.clone())
45 .kind(self.kind()) 45 .kind(self.kind())
46 .set_documentation(self.ctx.docs(self.func)) 46 .set_documentation(self.ctx.docs(self.func))
47 .set_deprecated(self.ctx.is_deprecated(self.func)) 47 .set_deprecated(
48 self.ctx.is_deprecated(self.func) || self.ctx.is_deprecated_assoc_item(self.func),
49 )
48 .detail(self.detail()) 50 .detail(self.detail())
49 .add_call_parens(self.ctx.completion, self.name, params) 51 .add_call_parens(self.ctx.completion, self.name, params)
50 .add_import(import_to_add) 52 .add_import(import_to_add)
diff --git a/crates/completion/src/render/type_alias.rs b/crates/completion/src/render/type_alias.rs
index 69b445b9c..29287143a 100644
--- a/crates/completion/src/render/type_alias.rs
+++ b/crates/completion/src/render/type_alias.rs
@@ -38,7 +38,10 @@ impl<'a> TypeAliasRender<'a> {
38 let item = CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), name) 38 let item = CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), name)
39 .kind(CompletionItemKind::TypeAlias) 39 .kind(CompletionItemKind::TypeAlias)
40 .set_documentation(self.ctx.docs(self.type_alias)) 40 .set_documentation(self.ctx.docs(self.type_alias))
41 .set_deprecated(self.ctx.is_deprecated(self.type_alias)) 41 .set_deprecated(
42 self.ctx.is_deprecated(self.type_alias)
43 || self.ctx.is_deprecated_assoc_item(self.type_alias),
44 )
42 .detail(detail) 45 .detail(detail)
43 .build(); 46 .build();
44 47
diff --git a/crates/completion/src/test_utils.rs b/crates/completion/src/test_utils.rs
index 3faf861b9..baff83305 100644
--- a/crates/completion/src/test_utils.rs
+++ b/crates/completion/src/test_utils.rs
@@ -83,6 +83,9 @@ pub(crate) fn completion_list_with_config(
83 let width = label_width.saturating_sub(monospace_width(it.label())); 83 let width = label_width.saturating_sub(monospace_width(it.label()));
84 format_to!(buf, "{:width$} {}", "", detail, width = width); 84 format_to!(buf, "{:width$} {}", "", detail, width = width);
85 } 85 }
86 if it.deprecated() {
87 format_to!(buf, " DEPRECATED");
88 }
86 format_to!(buf, "\n"); 89 format_to!(buf, "\n");
87 buf 90 buf
88 }) 91 })