Add FunctionSignature::from_hir
This commit is contained in:
parent
2fe075f56e
commit
dfaebd76ab
2 changed files with 11 additions and 6 deletions
|
@ -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<Cal
|
|||
let fn_def = ast::FnDef::cast(fn_def).unwrap();
|
||||
let function = hir::source_binder::function_from_source(db, symbol.file_id, fn_def)?;
|
||||
|
||||
let mut call_info = CallInfo::new(db, function, fn_def)?;
|
||||
let mut call_info = CallInfo::new(db, function);
|
||||
|
||||
// If we have a calling expression let's find which argument we are on
|
||||
let num_params = call_info.parameters().len();
|
||||
|
@ -107,11 +106,10 @@ impl<'a> FnCallNode<'a> {
|
|||
}
|
||||
|
||||
impl CallInfo {
|
||||
fn new(db: &RootDatabase, function: hir::Function, node: &ast::FnDef) -> Option<Self> {
|
||||
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] {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue