aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/completion/presentation.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-02-24 18:46:04 +0000
committerAleksey Kladov <[email protected]>2019-02-24 18:46:04 +0000
commit98510ec5d3478f3e9178bbff076532487292d8f8 (patch)
tree96053c129790cfab55f06912f4944154b851c2b8 /crates/ra_ide_api/src/completion/presentation.rs
parentb7a78729100aa2068827e5812aec03abd3a5df9a (diff)
move the rest of presentation to presentation
Diffstat (limited to 'crates/ra_ide_api/src/completion/presentation.rs')
-rw-r--r--crates/ra_ide_api/src/completion/presentation.rs29
1 files changed, 18 insertions, 11 deletions
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs
index d386288ed..0ead52032 100644
--- a/crates/ra_ide_api/src/completion/presentation.rs
+++ b/crates/ra_ide_api/src/completion/presentation.rs
@@ -6,7 +6,7 @@ use ra_syntax::ast::NameOwner;
6 6
7use crate::completion::{ 7use crate::completion::{
8 Completions, CompletionKind, CompletionItemKind, CompletionContext, CompletionItem, 8 Completions, CompletionKind, CompletionItemKind, CompletionContext, CompletionItem,
9 function_label, 9 function_label, const_label, type_label,
10}; 10};
11 11
12impl Completions { 12impl Completions {
@@ -91,6 +91,8 @@ impl Completions {
91 ) { 91 ) {
92 let sig = func.signature(ctx.db); 92 let sig = func.signature(ctx.db);
93 let name = name.unwrap_or_else(|| sig.name().to_string()); 93 let name = name.unwrap_or_else(|| sig.name().to_string());
94 let (_, ast_node) = func.source(ctx.db);
95 let detail = function_label(&ast_node);
94 96
95 let mut builder = CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name) 97 let mut builder = CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name)
96 .kind(if sig.has_self_param() { 98 .kind(if sig.has_self_param() {
@@ -99,7 +101,7 @@ impl Completions {
99 CompletionItemKind::Function 101 CompletionItemKind::Function
100 }) 102 })
101 .set_documentation(func.docs(ctx.db)) 103 .set_documentation(func.docs(ctx.db))
102 .set_detail(function_item_label(ctx, func)); 104 .set_detail(detail);
103 // If not an import, add parenthesis automatically. 105 // If not an import, add parenthesis automatically.
104 if ctx.use_item_syntax.is_none() && !ctx.is_call { 106 if ctx.use_item_syntax.is_none() && !ctx.is_call {
105 tested_by!(inserts_parens_for_function_calls); 107 tested_by!(inserts_parens_for_function_calls);
@@ -115,13 +117,18 @@ impl Completions {
115 } 117 }
116 118
117 pub(crate) fn add_const(&mut self, ctx: &CompletionContext, constant: hir::Const) { 119 pub(crate) fn add_const(&mut self, ctx: &CompletionContext, constant: hir::Const) {
118 let (_file_id, cosnt_def) = constant.source(ctx.db); 120 let (_file_id, ast_node) = constant.source(ctx.db);
119 let name = match cosnt_def.name() { 121 let name = match ast_node.name() {
120 Some(name) => name, 122 Some(name) => name,
121 _ => return, 123 _ => return,
122 }; 124 };
125 let (_, ast_node) = constant.source(ctx.db);
126 let detail = const_label(&ast_node);
127
123 CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.text().to_string()) 128 CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.text().to_string())
124 .from_const(ctx, constant) 129 .kind(CompletionItemKind::Const)
130 .set_documentation(constant.docs(ctx.db))
131 .detail(detail)
125 .add_to(self); 132 .add_to(self);
126 } 133 }
127 134
@@ -131,8 +138,13 @@ impl Completions {
131 Some(name) => name, 138 Some(name) => name,
132 _ => return, 139 _ => return,
133 }; 140 };
141 let (_, ast_node) = type_alias.source(ctx.db);
142 let detail = type_label(&ast_node);
143
134 CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.text().to_string()) 144 CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.text().to_string())
135 .from_type(ctx, type_alias) 145 .kind(CompletionItemKind::TypeAlias)
146 .set_documentation(type_alias.docs(ctx.db))
147 .detail(detail)
136 .add_to(self); 148 .add_to(self);
137 } 149 }
138 150
@@ -152,11 +164,6 @@ impl Completions {
152 } 164 }
153} 165}
154 166
155fn function_item_label(ctx: &CompletionContext, function: hir::Function) -> Option<String> {
156 let node = function.source(ctx.db).1;
157 function_label(&node)
158}
159
160#[cfg(test)] 167#[cfg(test)]
161mod tests { 168mod tests {
162 use test_utils::covers; 169 use test_utils::covers;