mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
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},
|
ast::{self, ArgListOwner},
|
||||||
algo::find_node_at_offset,
|
algo::find_node_at_offset,
|
||||||
};
|
};
|
||||||
use hir::Docs;
|
|
||||||
|
|
||||||
use crate::{FilePosition, CallInfo, FunctionSignature, db::RootDatabase};
|
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 fn_def = ast::FnDef::cast(fn_def).unwrap();
|
||||||
let function = hir::source_binder::function_from_source(db, symbol.file_id, fn_def)?;
|
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
|
// If we have a calling expression let's find which argument we are on
|
||||||
let num_params = call_info.parameters().len();
|
let num_params = call_info.parameters().len();
|
||||||
|
@ -107,11 +106,10 @@ impl<'a> FnCallNode<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CallInfo {
|
impl CallInfo {
|
||||||
fn new(db: &RootDatabase, function: hir::Function, node: &ast::FnDef) -> Option<Self> {
|
fn new(db: &RootDatabase, function: hir::Function) -> Self {
|
||||||
let doc = function.docs(db);
|
let signature = FunctionSignature::from_hir(db, function);
|
||||||
let signature = FunctionSignature::from(node).with_doc_opt(doc);
|
|
||||||
|
|
||||||
Some(CallInfo { signature, active_parameter: None })
|
CallInfo { signature, active_parameter: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parameters(&self) -> &[String] {
|
fn parameters(&self) -> &[String] {
|
||||||
|
|
|
@ -5,6 +5,7 @@ use std::fmt::{self, Display};
|
||||||
use join_to_string::join;
|
use join_to_string::join;
|
||||||
use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner, TypeParamsOwner};
|
use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner, TypeParamsOwner};
|
||||||
use std::convert::From;
|
use std::convert::From;
|
||||||
|
use hir::Docs;
|
||||||
|
|
||||||
/// Contains information about a function signature
|
/// Contains information about a function signature
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -30,6 +31,12 @@ impl FunctionSignature {
|
||||||
self.doc = doc;
|
self.doc = doc;
|
||||||
self
|
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 {
|
impl From<&'_ ast::FnDef> for FunctionSignature {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue