Thread documentation through FnSignature and CompletionItem

This commit is contained in:
Jeremy Kolb 2019-01-21 21:42:37 -05:00
parent 5d110c0ee2
commit b77d780f0e
3 changed files with 15 additions and 1 deletions

View File

@ -297,6 +297,7 @@ pub struct FnSignature {
/// True if the first param is `self`. This is relevant to decide whether this /// True if the first param is `self`. This is relevant to decide whether this
/// can be called as a method. /// can be called as a method.
pub(crate) has_self_param: bool, pub(crate) has_self_param: bool,
pub(crate) documentation: String,
} }
impl FnSignature { impl FnSignature {
@ -317,6 +318,10 @@ impl FnSignature {
pub fn has_self_param(&self) -> bool { pub fn has_self_param(&self) -> bool {
self.has_self_param self.has_self_param
} }
pub fn documentation(&self) -> &String {
&self.documentation
}
} }
impl Function { impl Function {

View File

@ -2,7 +2,7 @@ mod scope;
use std::sync::Arc; use std::sync::Arc;
use ra_syntax::{TreeArc, ast::{self, NameOwner}}; use ra_syntax::{TreeArc, ast::{self, NameOwner, DocCommentsOwner}};
use crate::{ use crate::{
DefId, HirDatabase, Name, AsName, Function, FnSignature, Module, DefId, HirDatabase, Name, AsName, Function, FnSignature, Module,
@ -72,11 +72,15 @@ impl FnSignature {
} else { } else {
TypeRef::unit() TypeRef::unit()
}; };
let comments = node.doc_comment_text();
let sig = FnSignature { let sig = FnSignature {
name, name,
params, params,
ret_type, ret_type,
has_self_param, has_self_param,
documentation: comments,
}; };
Arc::new(sig) Arc::new(sig)
} }

View File

@ -259,6 +259,11 @@ impl Builder {
} }
self.insert_text_format = InsertTextFormat::Snippet; self.insert_text_format = InsertTextFormat::Snippet;
} }
let sig = function.signature(ctx.db);
if !sig.documentation().is_empty() {
self.documentation = Some(sig.documentation().clone());
}
self.kind = Some(CompletionItemKind::Function); self.kind = Some(CompletionItemKind::Function);
self self
} }