From b5404514834a27c682dc22d86bc5585c0cae3076 Mon Sep 17 00:00:00 2001 From: Jeremy Kolb Date: Tue, 22 Jan 2019 08:55:05 -0500 Subject: Move docs to Function --- crates/ra_hir/src/code_model_api.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'crates/ra_hir/src/code_model_api.rs') diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index 57f405f4f..9ae620efd 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, @@ -297,7 +297,6 @@ pub struct FnSignature { /// True if the first param is `self`. This is relevant to decide whether this /// can be called as a method. pub(crate) has_self_param: bool, - pub(crate) documentation: String, } impl FnSignature { @@ -318,10 +317,6 @@ impl FnSignature { pub fn has_self_param(&self) -> bool { self.has_self_param } - - pub fn documentation(&self) -> &String { - &self.documentation - } } impl Function { @@ -357,6 +352,20 @@ impl Function { pub fn generic_params(&self, db: &impl HirDatabase) -> Arc { db.generic_params(self.def_id) } + + pub fn docs(&self, db: &impl HirDatabase) -> Option { + 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)] -- cgit v1.2.3