From dfaebd76aba1cfd7ac13b940d7847eb44b953cac Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Mon, 8 Apr 2019 10:46:26 +0300 Subject: Add FunctionSignature::from_hir --- crates/ra_ide_api/src/call_info.rs | 10 ++++------ crates/ra_ide_api/src/display.rs | 7 +++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs index 66a769c73..dbb3853d0 100644 --- a/crates/ra_ide_api/src/call_info.rs +++ b/crates/ra_ide_api/src/call_info.rs @@ -6,7 +6,6 @@ use ra_syntax::{ ast::{self, ArgListOwner}, algo::find_node_at_offset, }; -use hir::Docs; use crate::{FilePosition, CallInfo, FunctionSignature, db::RootDatabase}; @@ -27,7 +26,7 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option FnCallNode<'a> { } impl CallInfo { - fn new(db: &RootDatabase, function: hir::Function, node: &ast::FnDef) -> Option { - let doc = function.docs(db); - let signature = FunctionSignature::from(node).with_doc_opt(doc); + fn new(db: &RootDatabase, function: hir::Function) -> Self { + let signature = FunctionSignature::from_hir(db, function); - Some(CallInfo { signature, active_parameter: None }) + CallInfo { signature, active_parameter: None } } fn parameters(&self) -> &[String] { diff --git a/crates/ra_ide_api/src/display.rs b/crates/ra_ide_api/src/display.rs index 4ce362ebb..c05d59689 100644 --- a/crates/ra_ide_api/src/display.rs +++ b/crates/ra_ide_api/src/display.rs @@ -5,6 +5,7 @@ use std::fmt::{self, Display}; use join_to_string::join; use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner, TypeParamsOwner}; use std::convert::From; +use hir::Docs; /// Contains information about a function signature #[derive(Debug)] @@ -30,6 +31,12 @@ impl FunctionSignature { self.doc = doc; self } + + pub(crate) fn from_hir(db: &db::RootDatabase, function: hir::Function) -> Self { + let doc = function.docs(db); + let (_, ast_node) = function.source(db); + FunctionSignature::from(&*ast_node).with_doc_opt(doc) + } } impl From<&'_ ast::FnDef> for FunctionSignature { -- cgit v1.2.3