aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r--crates/ra_ide_api/src/completion/complete_path.rs39
-rw-r--r--crates/ra_ide_api/src/completion/complete_scope.rs8
-rw-r--r--crates/ra_ide_api/src/completion/presentation.rs36
3 files changed, 42 insertions, 41 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs
index 8713fb0f0..8e453b0e0 100644
--- a/crates/ra_ide_api/src/completion/complete_path.rs
+++ b/crates/ra_ide_api/src/completion/complete_path.rs
@@ -1,8 +1,8 @@
1use hir::Resolution; 1use hir::Resolution;
2use ra_syntax::{AstNode, ast::NameOwner}; 2use ra_syntax::AstNode;
3use test_utils::tested_by; 3use test_utils::tested_by;
4 4
5use crate::completion::{CompletionItem, Completions, CompletionKind, CompletionContext}; 5use crate::completion::{Completions, CompletionContext};
6 6
7pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { 7pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
8 let path = match &ctx.path_prefix { 8 let path = match &ctx.path_prefix {
@@ -27,14 +27,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
27 } 27 }
28 } 28 }
29 } 29 }
30 30 acc.add_resolution(ctx, name.to_string(), &res.def.map(hir::Resolution::Def));
31 CompletionItem::new(
32 CompletionKind::Reference,
33 ctx.source_range(),
34 name.to_string(),
35 )
36 .from_resolution(ctx, &res.def.map(hir::Resolution::Def))
37 .add_to(acc);
38 } 31 }
39 } 32 }
40 hir::ModuleDef::Enum(e) => { 33 hir::ModuleDef::Enum(e) => {
@@ -52,30 +45,8 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
52 acc.add_function(ctx, func); 45 acc.add_function(ctx, func);
53 } 46 }
54 } 47 }
55 hir::ImplItem::Const(ct) => { 48 hir::ImplItem::Const(ct) => acc.add_const(ctx, ct),
56 let source = ct.source(ctx.db); 49 hir::ImplItem::Type(ty) => acc.add_type(ctx, ty),
57 if let Some(name) = source.1.name() {
58 CompletionItem::new(
59 CompletionKind::Reference,
60 ctx.source_range(),
61 name.text().to_string(),
62 )
63 .from_const(ctx, ct)
64 .add_to(acc);
65 }
66 }
67 hir::ImplItem::Type(ty) => {
68 let source = ty.source(ctx.db);
69 if let Some(name) = source.1.name() {
70 CompletionItem::new(
71 CompletionKind::Reference,
72 ctx.source_range(),
73 name.text().to_string(),
74 )
75 .from_type(ctx, ty)
76 .add_to(acc);
77 }
78 }
79 } 50 }
80 None::<()> 51 None::<()>
81 }); 52 });
diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs
index eeaf26d93..b44b943ae 100644
--- a/crates/ra_ide_api/src/completion/complete_scope.rs
+++ b/crates/ra_ide_api/src/completion/complete_scope.rs
@@ -1,4 +1,4 @@
1use crate::completion::{CompletionItem, Completions, CompletionKind, CompletionContext}; 1use crate::completion::{Completions, CompletionContext};
2 2
3pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) { 3pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) {
4 if !ctx.is_trivial_path { 4 if !ctx.is_trivial_path {
@@ -6,11 +6,7 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) {
6 } 6 }
7 let names = ctx.resolver.all_names(ctx.db); 7 let names = ctx.resolver.all_names(ctx.db);
8 8
9 names.into_iter().for_each(|(name, res)| { 9 names.into_iter().for_each(|(name, res)| acc.add_resolution(ctx, name.to_string(), &res));
10 CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.to_string())
11 .from_resolution(ctx, &res)
12 .add_to(acc)
13 });
14} 10}
15 11
16#[cfg(test)] 12#[cfg(test)]
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs
index bc2cb4a0f..232ec80cd 100644
--- a/crates/ra_ide_api/src/completion/presentation.rs
+++ b/crates/ra_ide_api/src/completion/presentation.rs
@@ -1,7 +1,8 @@
1//! This modules takes care of rendering various defenitions as completion items. 1//! This modules takes care of rendering various defenitions as completion items.
2use join_to_string::join; 2use join_to_string::join;
3use test_utils::tested_by; 3use test_utils::tested_by;
4use hir::Docs; 4use hir::{Docs, PerNs, Resolution};
5use ra_syntax::ast::NameOwner;
5 6
6use crate::completion::{ 7use crate::completion::{
7 Completions, CompletionKind, CompletionItemKind, CompletionContext, CompletionItem, 8 Completions, CompletionKind, CompletionItemKind, CompletionContext, CompletionItem,
@@ -33,6 +34,17 @@ impl Completions {
33 .add_to(self); 34 .add_to(self);
34 } 35 }
35 36
37 pub(crate) fn add_resolution(
38 &mut self,
39 ctx: &CompletionContext,
40 local_name: String,
41 res: &PerNs<Resolution>,
42 ) {
43 CompletionItem::new(CompletionKind::Reference, ctx.source_range(), local_name)
44 .from_resolution(ctx, res)
45 .add_to(self);
46 }
47
36 pub(crate) fn add_function(&mut self, ctx: &CompletionContext, func: hir::Function) { 48 pub(crate) fn add_function(&mut self, ctx: &CompletionContext, func: hir::Function) {
37 let sig = func.signature(ctx.db); 49 let sig = func.signature(ctx.db);
38 50
@@ -62,6 +74,28 @@ impl Completions {
62 self.add(builder) 74 self.add(builder)
63 } 75 }
64 76
77 pub(crate) fn add_const(&mut self, ctx: &CompletionContext, constant: hir::Const) {
78 let (_file_id, cosnt_def) = constant.source(ctx.db);
79 let name = match cosnt_def.name() {
80 Some(name) => name,
81 _ => return,
82 };
83 CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.text().to_string())
84 .from_const(ctx, constant)
85 .add_to(self);
86 }
87
88 pub(crate) fn add_type(&mut self, ctx: &CompletionContext, type_alias: hir::Type) {
89 let (_file_id, type_def) = type_alias.source(ctx.db);
90 let name = match type_def.name() {
91 Some(name) => name,
92 _ => return,
93 };
94 CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.text().to_string())
95 .from_type(ctx, type_alias)
96 .add_to(self);
97 }
98
65 pub(crate) fn add_enum_variant(&mut self, ctx: &CompletionContext, variant: hir::EnumVariant) { 99 pub(crate) fn add_enum_variant(&mut self, ctx: &CompletionContext, variant: hir::EnumVariant) {
66 let name = match variant.name(ctx.db) { 100 let name = match variant.name(ctx.db) {
67 Some(it) => it, 101 Some(it) => it,