diff options
| author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-22 15:06:32 +0000 |
|---|---|---|
| committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-22 15:06:32 +0000 |
| commit | 595a2f9900d052d0c5cc3529602aec0cbcd52614 (patch) | |
| tree | 7af6dd503e1247952e3689b562c5470f4ae28613 /crates/ra_hir/src/code_model_api.rs | |
| parent | 9e0abfc0c9b9d36c45c9d8567c632c0167b31084 (diff) | |
| parent | 7c27e6d2b3133e4c37b176f0e13c15994eb16dfa (diff) | |
| download | rust-595a2f9900d052d0c5cc3529602aec0cbcd52614.tar.gz rust-595a2f9900d052d0c5cc3529602aec0cbcd52614.zip | |
Merge #593
593: Docs for completion r=matklad a=kjeremy The first commit adds documentation support to CompletionItems. The second one I am unsure about. Is that the right way to add docs for functions? If so should I do something similar for other `hir` types and CompletionItems? Co-authored-by: Jeremy Kolb <kjeremy@gmail.com> Co-authored-by: Jeremy A. Kolb <jkolb@ara.com>
Diffstat (limited to 'crates/ra_hir/src/code_model_api.rs')
| -rw-r--r-- | crates/ra_hir/src/code_model_api.rs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index 88eda5ed0fd..9ae620efd4c 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use relative_path::RelativePathBuf; use ra_db::{CrateId, FileId}; -use ra_syntax::{ast, TreeArc, SyntaxNode}; +use ra_syntax::{ast::{self, AstNode, DocCommentsOwner}, TreeArc, SyntaxNode}; use crate::{ Name, DefId, Path, PerNs, ScopesWithSyntaxMapping, Ty, HirFileId, @@ -352,6 +352,20 @@ impl Function { pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> { db.generic_params(self.def_id) } + + pub fn docs(&self, db: &impl HirDatabase) -> Option<String> { + let def_loc = self.def_id.loc(db); + let syntax = db.file_item(def_loc.source_item_id); + let fn_def = ast::FnDef::cast(&syntax).expect("fn def should point to FnDef node"); + + // doc_comment_text unconditionally returns a String + let comments = fn_def.doc_comment_text(); + if comments.is_empty() { + None + } else { + Some(comments) + } + } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
