mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-01 19:23:50 +00:00
Move docs to Function
This commit is contained in:
parent
b77d780f0e
commit
b540451483
@ -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<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)]
|
||||
|
@ -2,7 +2,7 @@ mod scope;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use ra_syntax::{TreeArc, ast::{self, NameOwner, DocCommentsOwner}};
|
||||
use ra_syntax::{TreeArc, ast::{self, NameOwner}};
|
||||
|
||||
use crate::{
|
||||
DefId, HirDatabase, Name, AsName, Function, FnSignature, Module,
|
||||
@ -73,14 +73,11 @@ impl FnSignature {
|
||||
TypeRef::unit()
|
||||
};
|
||||
|
||||
let comments = node.doc_comment_text();
|
||||
|
||||
let sig = FnSignature {
|
||||
name,
|
||||
params,
|
||||
ret_type,
|
||||
has_self_param,
|
||||
documentation: comments,
|
||||
};
|
||||
Arc::new(sig)
|
||||
}
|
||||
|
@ -259,9 +259,8 @@ impl Builder {
|
||||
}
|
||||
self.insert_text_format = InsertTextFormat::Snippet;
|
||||
}
|
||||
let sig = function.signature(ctx.db);
|
||||
if !sig.documentation().is_empty() {
|
||||
self.documentation = Some(sig.documentation().clone());
|
||||
if let Some(docs) = function.docs(ctx.db) {
|
||||
self.documentation = Some(docs);
|
||||
}
|
||||
|
||||
self.kind = Some(CompletionItemKind::Function);
|
||||
|
Loading…
Reference in New Issue
Block a user