diff options
Diffstat (limited to 'crates/ra_ide_api/src/completion/completion_item.rs')
-rw-r--r-- | crates/ra_ide_api/src/completion/completion_item.rs | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs index e3bf82304..18c151932 100644 --- a/crates/ra_ide_api/src/completion/completion_item.rs +++ b/crates/ra_ide_api/src/completion/completion_item.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use hir::PerNs; | 1 | use hir::{Docs, Documentation, PerNs}; |
2 | 2 | ||
3 | use crate::completion::completion_context::CompletionContext; | 3 | use crate::completion::completion_context::CompletionContext; |
4 | use ra_syntax::{ | 4 | use ra_syntax::{ |
@@ -19,7 +19,7 @@ pub struct CompletionItem { | |||
19 | label: String, | 19 | label: String, |
20 | kind: Option<CompletionItemKind>, | 20 | kind: Option<CompletionItemKind>, |
21 | detail: Option<String>, | 21 | detail: Option<String>, |
22 | documentation: Option<String>, | 22 | documentation: Option<Documentation>, |
23 | lookup: Option<String>, | 23 | lookup: Option<String>, |
24 | insert_text: Option<String>, | 24 | insert_text: Option<String>, |
25 | insert_text_format: InsertTextFormat, | 25 | insert_text_format: InsertTextFormat, |
@@ -98,7 +98,7 @@ impl CompletionItem { | |||
98 | } | 98 | } |
99 | /// A doc-comment | 99 | /// A doc-comment |
100 | pub fn documentation(&self) -> Option<&str> { | 100 | pub fn documentation(&self) -> Option<&str> { |
101 | self.documentation.as_ref().map(|it| it.as_str()) | 101 | self.documentation.as_ref().map(|it| it.contents()) |
102 | } | 102 | } |
103 | /// What string is used for filtering. | 103 | /// What string is used for filtering. |
104 | pub fn lookup(&self) -> &str { | 104 | pub fn lookup(&self) -> &str { |
@@ -137,7 +137,7 @@ pub(crate) struct Builder { | |||
137 | insert_text: Option<String>, | 137 | insert_text: Option<String>, |
138 | insert_text_format: InsertTextFormat, | 138 | insert_text_format: InsertTextFormat, |
139 | detail: Option<String>, | 139 | detail: Option<String>, |
140 | documentation: Option<String>, | 140 | documentation: Option<Documentation>, |
141 | lookup: Option<String>, | 141 | lookup: Option<String>, |
142 | kind: Option<CompletionItemKind>, | 142 | kind: Option<CompletionItemKind>, |
143 | text_edit: Option<TextEdit>, | 143 | text_edit: Option<TextEdit>, |
@@ -197,10 +197,10 @@ impl Builder { | |||
197 | self | 197 | self |
198 | } | 198 | } |
199 | #[allow(unused)] | 199 | #[allow(unused)] |
200 | pub(crate) fn documentation(self, docs: impl Into<String>) -> Builder { | 200 | pub(crate) fn documentation(self, docs: Documentation) -> Builder { |
201 | self.set_documentation(Some(docs)) | 201 | self.set_documentation(Some(docs)) |
202 | } | 202 | } |
203 | pub(crate) fn set_documentation(mut self, docs: Option<impl Into<String>>) -> Builder { | 203 | pub(crate) fn set_documentation(mut self, docs: Option<Documentation>) -> Builder { |
204 | self.documentation = docs.map(Into::into); | 204 | self.documentation = docs.map(Into::into); |
205 | self | 205 | self |
206 | } | 206 | } |
@@ -210,35 +210,35 @@ impl Builder { | |||
210 | resolution: &hir::Resolution, | 210 | resolution: &hir::Resolution, |
211 | ) -> Builder { | 211 | ) -> Builder { |
212 | let resolved = resolution.def_id.map(|d| d.resolve(ctx.db)); | 212 | let resolved = resolution.def_id.map(|d| d.resolve(ctx.db)); |
213 | let kind = match resolved { | 213 | let (kind, docs) = match resolved { |
214 | PerNs { | 214 | PerNs { |
215 | types: Some(hir::Def::Module(..)), | 215 | types: Some(hir::Def::Module(..)), |
216 | .. | 216 | .. |
217 | } => CompletionItemKind::Module, | 217 | } => (CompletionItemKind::Module, None), |
218 | PerNs { | 218 | PerNs { |
219 | types: Some(hir::Def::Struct(..)), | 219 | types: Some(hir::Def::Struct(s)), |
220 | .. | 220 | .. |
221 | } => CompletionItemKind::Struct, | 221 | } => (CompletionItemKind::Struct, s.docs(ctx.db)), |
222 | PerNs { | 222 | PerNs { |
223 | types: Some(hir::Def::Enum(..)), | 223 | types: Some(hir::Def::Enum(e)), |
224 | .. | 224 | .. |
225 | } => CompletionItemKind::Enum, | 225 | } => (CompletionItemKind::Enum, e.docs(ctx.db)), |
226 | PerNs { | 226 | PerNs { |
227 | types: Some(hir::Def::Trait(..)), | 227 | types: Some(hir::Def::Trait(t)), |
228 | .. | 228 | .. |
229 | } => CompletionItemKind::Trait, | 229 | } => (CompletionItemKind::Trait, t.docs(ctx.db)), |
230 | PerNs { | 230 | PerNs { |
231 | types: Some(hir::Def::Type(..)), | 231 | types: Some(hir::Def::Type(t)), |
232 | .. | 232 | .. |
233 | } => CompletionItemKind::TypeAlias, | 233 | } => (CompletionItemKind::TypeAlias, t.docs(ctx.db)), |
234 | PerNs { | 234 | PerNs { |
235 | values: Some(hir::Def::Const(..)), | 235 | values: Some(hir::Def::Const(c)), |
236 | .. | 236 | .. |
237 | } => CompletionItemKind::Const, | 237 | } => (CompletionItemKind::Const, c.docs(ctx.db)), |
238 | PerNs { | 238 | PerNs { |
239 | values: Some(hir::Def::Static(..)), | 239 | values: Some(hir::Def::Static(s)), |
240 | .. | 240 | .. |
241 | } => CompletionItemKind::Static, | 241 | } => (CompletionItemKind::Static, s.docs(ctx.db)), |
242 | PerNs { | 242 | PerNs { |
243 | values: Some(hir::Def::Function(function)), | 243 | values: Some(hir::Def::Function(function)), |
244 | .. | 244 | .. |
@@ -246,6 +246,8 @@ impl Builder { | |||
246 | _ => return self, | 246 | _ => return self, |
247 | }; | 247 | }; |
248 | self.kind = Some(kind); | 248 | self.kind = Some(kind); |
249 | self.documentation = docs; | ||
250 | |||
249 | self | 251 | self |
250 | } | 252 | } |
251 | 253 | ||
@@ -265,6 +267,7 @@ impl Builder { | |||
265 | } | 267 | } |
266 | self.insert_text_format = InsertTextFormat::Snippet; | 268 | self.insert_text_format = InsertTextFormat::Snippet; |
267 | } | 269 | } |
270 | |||
268 | if let Some(docs) = function.docs(ctx.db) { | 271 | if let Some(docs) = function.docs(ctx.db) { |
269 | self.documentation = Some(docs); | 272 | self.documentation = Some(docs); |
270 | } | 273 | } |