aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/completion
diff options
context:
space:
mode:
authorMartin Asquino <[email protected]>2019-11-04 13:33:10 +0000
committerMartin Asquino <[email protected]>2019-11-04 21:16:35 +0000
commitcb3767f28a2f9e443b816b17d5d07b6a1cff90ab (patch)
treeffae5e26ef1b5e96a41a6aff40e9a17c5179aeb2 /crates/ra_ide_api/src/completion
parentcc2d75d0f88bdcb1b3e20db36decb6ee6eca517a (diff)
HirDatabase stored attributes
Diffstat (limited to 'crates/ra_ide_api/src/completion')
-rw-r--r--crates/ra_ide_api/src/completion/presentation.rs27
1 files changed, 13 insertions, 14 deletions
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs
index cb55d1875..d861303b7 100644
--- a/crates/ra_ide_api/src/completion/presentation.rs
+++ b/crates/ra_ide_api/src/completion/presentation.rs
@@ -1,8 +1,8 @@
1//! This modules takes care of rendering various definitions as completion items. 1//! This modules takes care of rendering various definitions as completion items.
2 2
3use hir::{db::HirDatabase, Docs, HasSource, HirDisplay, ScopeDef, Ty, TypeWalk}; 3use hir::{db::HirDatabase, Attrs, Docs, HasSource, HirDisplay, ScopeDef, Ty, TypeWalk};
4use join_to_string::join; 4use join_to_string::join;
5use ra_syntax::ast::{AttrsOwner, NameOwner}; 5use ra_syntax::ast::NameOwner;
6use test_utils::tested_by; 6use test_utils::tested_by;
7 7
8use crate::completion::{ 8use crate::completion::{
@@ -18,11 +18,7 @@ impl Completions {
18 field: hir::StructField, 18 field: hir::StructField,
19 substs: &hir::Substs, 19 substs: &hir::Substs,
20 ) { 20 ) {
21 let ast_node = field.source(ctx.db).ast; 21 let is_deprecated = is_deprecated(field, ctx.db);
22 let is_deprecated = match ast_node {
23 hir::FieldSource::Named(m) => is_deprecated(m),
24 hir::FieldSource::Pos(m) => is_deprecated(m),
25 };
26 CompletionItem::new( 22 CompletionItem::new(
27 CompletionKind::Reference, 23 CompletionKind::Reference,
28 ctx.source_range(), 24 ctx.source_range(),
@@ -185,7 +181,7 @@ impl Completions {
185 CompletionItem::new(CompletionKind::Reference, ctx.source_range(), &macro_declaration) 181 CompletionItem::new(CompletionKind::Reference, ctx.source_range(), &macro_declaration)
186 .kind(CompletionItemKind::Macro) 182 .kind(CompletionItemKind::Macro)
187 .set_documentation(docs.clone()) 183 .set_documentation(docs.clone())
188 .set_deprecated(is_deprecated(ast_node)) 184 .set_deprecated(is_deprecated(macro_, ctx.db))
189 .detail(detail); 185 .detail(detail);
190 186
191 builder = if ctx.use_item_syntax.is_some() { 187 builder = if ctx.use_item_syntax.is_some() {
@@ -218,7 +214,7 @@ impl Completions {
218 CompletionItemKind::Function 214 CompletionItemKind::Function
219 }) 215 })
220 .set_documentation(func.docs(ctx.db)) 216 .set_documentation(func.docs(ctx.db))
221 .set_deprecated(is_deprecated(ast_node)) 217 .set_deprecated(is_deprecated(func, ctx.db))
222 .detail(detail); 218 .detail(detail);
223 219
224 // Add `<>` for generic types 220 // Add `<>` for generic types
@@ -250,7 +246,7 @@ impl Completions {
250 CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.text().to_string()) 246 CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.text().to_string())
251 .kind(CompletionItemKind::Const) 247 .kind(CompletionItemKind::Const)
252 .set_documentation(constant.docs(ctx.db)) 248 .set_documentation(constant.docs(ctx.db))
253 .set_deprecated(is_deprecated(ast_node)) 249 .set_deprecated(is_deprecated(constant, ctx.db))
254 .detail(detail) 250 .detail(detail)
255 .add_to(self); 251 .add_to(self);
256 } 252 }
@@ -266,13 +262,13 @@ impl Completions {
266 CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.text().to_string()) 262 CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.text().to_string())
267 .kind(CompletionItemKind::TypeAlias) 263 .kind(CompletionItemKind::TypeAlias)
268 .set_documentation(type_alias.docs(ctx.db)) 264 .set_documentation(type_alias.docs(ctx.db))
269 .set_deprecated(is_deprecated(type_def)) 265 .set_deprecated(is_deprecated(type_alias, ctx.db))
270 .detail(detail) 266 .detail(detail)
271 .add_to(self); 267 .add_to(self);
272 } 268 }
273 269
274 pub(crate) fn add_enum_variant(&mut self, ctx: &CompletionContext, variant: hir::EnumVariant) { 270 pub(crate) fn add_enum_variant(&mut self, ctx: &CompletionContext, variant: hir::EnumVariant) {
275 let is_deprecated = is_deprecated(variant.source(ctx.db).ast); 271 let is_deprecated = is_deprecated(variant, ctx.db);
276 let name = match variant.name(ctx.db) { 272 let name = match variant.name(ctx.db) {
277 Some(it) => it, 273 Some(it) => it,
278 None => return, 274 None => return,
@@ -291,8 +287,11 @@ impl Completions {
291 } 287 }
292} 288}
293 289
294fn is_deprecated(node: impl AttrsOwner) -> bool { 290fn is_deprecated(node: impl Attrs, db: &impl HirDatabase) -> bool {
295 node.attrs().filter_map(|x| x.simple_name()).any(|x| x == "deprecated") 291 match node.attrs(db) {
292 None => false,
293 Some(attrs) => attrs.iter().any(|x| x.is_simple_atom("deprecated")),
294 }
296} 295}
297 296
298fn has_non_default_type_params(def: hir::GenericDef, db: &db::RootDatabase) -> bool { 297fn has_non_default_type_params(def: hir::GenericDef, db: &db::RootDatabase) -> bool {