aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/code_model_api.rs21
-rw-r--r--crates/ra_hir/src/code_model_impl/function.rs5
2 files changed, 16 insertions, 10 deletions
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;
2 2
3use relative_path::RelativePathBuf; 3use relative_path::RelativePathBuf;
4use ra_db::{CrateId, FileId}; 4use ra_db::{CrateId, FileId};
5use ra_syntax::{ast, TreeArc, SyntaxNode}; 5use ra_syntax::{ast::{self, AstNode, DocCommentsOwner}, TreeArc, SyntaxNode};
6 6
7use crate::{ 7use crate::{
8 Name, DefId, Path, PerNs, ScopesWithSyntaxMapping, Ty, HirFileId, 8 Name, DefId, Path, PerNs, ScopesWithSyntaxMapping, Ty, HirFileId,
@@ -297,7 +297,6 @@ pub struct FnSignature {
297 /// True if the first param is `self`. This is relevant to decide whether this 297 /// True if the first param is `self`. This is relevant to decide whether this
298 /// can be called as a method. 298 /// can be called as a method.
299 pub(crate) has_self_param: bool, 299 pub(crate) has_self_param: bool,
300 pub(crate) documentation: String,
301} 300}
302 301
303impl FnSignature { 302impl FnSignature {
@@ -318,10 +317,6 @@ impl FnSignature {
318 pub fn has_self_param(&self) -> bool { 317 pub fn has_self_param(&self) -> bool {
319 self.has_self_param 318 self.has_self_param
320 } 319 }
321
322 pub fn documentation(&self) -> &String {
323 &self.documentation
324 }
325} 320}
326 321
327impl Function { 322impl Function {
@@ -357,6 +352,20 @@ impl Function {
357 pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> { 352 pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> {
358 db.generic_params(self.def_id) 353 db.generic_params(self.def_id)
359 } 354 }
355
356 pub fn docs(&self, db: &impl HirDatabase) -> Option<String> {
357 let def_loc = self.def_id.loc(db);
358 let syntax = db.file_item(def_loc.source_item_id);
359 let fn_def = ast::FnDef::cast(&syntax).expect("fn def should point to FnDef node");
360
361 // doc_comment_text unconditionally returns a String
362 let comments = fn_def.doc_comment_text();
363 if comments.is_empty() {
364 None
365 } else {
366 Some(comments)
367 }
368 }
360} 369}
361 370
362#[derive(Debug, Clone, PartialEq, Eq, Hash)] 371#[derive(Debug, Clone, PartialEq, Eq, Hash)]
diff --git a/crates/ra_hir/src/code_model_impl/function.rs b/crates/ra_hir/src/code_model_impl/function.rs
index c848f7a82..c68c6bfbf 100644
--- a/crates/ra_hir/src/code_model_impl/function.rs
+++ b/crates/ra_hir/src/code_model_impl/function.rs
@@ -2,7 +2,7 @@ mod scope;
2 2
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use ra_syntax::{TreeArc, ast::{self, NameOwner, DocCommentsOwner}}; 5use ra_syntax::{TreeArc, ast::{self, NameOwner}};
6 6
7use crate::{ 7use crate::{
8 DefId, HirDatabase, Name, AsName, Function, FnSignature, Module, 8 DefId, HirDatabase, Name, AsName, Function, FnSignature, Module,
@@ -73,14 +73,11 @@ impl FnSignature {
73 TypeRef::unit() 73 TypeRef::unit()
74 }; 74 };
75 75
76 let comments = node.doc_comment_text();
77
78 let sig = FnSignature { 76 let sig = FnSignature {
79 name, 77 name,
80 params, 78 params,
81 ret_type, 79 ret_type,
82 has_self_param, 80 has_self_param,
83 documentation: comments,
84 }; 81 };
85 Arc::new(sig) 82 Arc::new(sig)
86 } 83 }