mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
introduce CallInfo
This commit is contained in:
parent
e6a4383bb4
commit
256ec6e8d4
3 changed files with 33 additions and 23 deletions
|
@ -7,10 +7,21 @@ use ra_syntax::{
|
|||
use ra_editor::find_node_at_offset;
|
||||
use hir::FnSignatureInfo;
|
||||
|
||||
use crate::{FilePosition, db::RootDatabase};
|
||||
use crate::{FilePosition, CallInfo, db::RootDatabase};
|
||||
|
||||
pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Cancelable<Option<CallInfo>> {
|
||||
let (sig_info, active_parameter) = ctry!(call_info_(db, position)?);
|
||||
let res = CallInfo {
|
||||
label: sig_info.label,
|
||||
doc: sig_info.doc,
|
||||
parameters: sig_info.params,
|
||||
active_parameter,
|
||||
};
|
||||
Ok(Some(res))
|
||||
}
|
||||
|
||||
/// Computes parameter information for the given call expression.
|
||||
pub(crate) fn call_info(
|
||||
fn call_info_(
|
||||
db: &RootDatabase,
|
||||
position: FilePosition,
|
||||
) -> Cancelable<Option<(FnSignatureInfo, Option<usize>)>> {
|
||||
|
|
|
@ -273,6 +273,14 @@ impl<T> RangeInfo<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct CallInfo {
|
||||
pub label: String,
|
||||
pub doc: Option<String>,
|
||||
pub parameters: Vec<String>,
|
||||
pub active_parameter: Option<usize>,
|
||||
}
|
||||
|
||||
/// `AnalysisHost` stores the current state of the world.
|
||||
#[derive(Debug, Default)]
|
||||
pub struct AnalysisHost {
|
||||
|
@ -393,10 +401,7 @@ impl Analysis {
|
|||
hover::hover(&*self.db, position)
|
||||
}
|
||||
/// Computes parameter information for the given call expression.
|
||||
pub fn call_info(
|
||||
&self,
|
||||
position: FilePosition,
|
||||
) -> Cancelable<Option<(FnSignatureInfo, Option<usize>)>> {
|
||||
pub fn call_info(&self, position: FilePosition) -> Cancelable<Option<CallInfo>> {
|
||||
call_info::call_info(&*self.db, position)
|
||||
}
|
||||
/// Returns a `mod name;` declaration which created the current module.
|
||||
|
|
|
@ -475,36 +475,30 @@ pub fn handle_signature_help(
|
|||
params: req::TextDocumentPositionParams,
|
||||
) -> Result<Option<req::SignatureHelp>> {
|
||||
let position = params.try_conv_with(&world)?;
|
||||
|
||||
if let Some((descriptor, active_param)) = world.analysis().resolve_callable(position)? {
|
||||
let parameters: Vec<ParameterInformation> = descriptor
|
||||
.params
|
||||
.iter()
|
||||
if let Some(call_info) = world.analysis().call_info(position)? {
|
||||
let parameters: Vec<ParameterInformation> = call_info
|
||||
.parameters
|
||||
.into_iter()
|
||||
.map(|param| ParameterInformation {
|
||||
label: ParameterLabel::Simple(param.clone()),
|
||||
documentation: None,
|
||||
})
|
||||
.collect();
|
||||
|
||||
let documentation = if let Some(doc) = descriptor.doc {
|
||||
Some(Documentation::MarkupContent(MarkupContent {
|
||||
let documentation = call_info.doc.map(|value| {
|
||||
Documentation::MarkupContent(MarkupContent {
|
||||
kind: MarkupKind::Markdown,
|
||||
value: doc,
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
value,
|
||||
})
|
||||
});
|
||||
let sig_info = SignatureInformation {
|
||||
label: descriptor.label,
|
||||
label: call_info.label,
|
||||
documentation,
|
||||
parameters: Some(parameters),
|
||||
};
|
||||
|
||||
Ok(Some(req::SignatureHelp {
|
||||
signatures: vec![sig_info],
|
||||
active_signature: Some(0),
|
||||
active_parameter: active_param.map(|a| a as u64),
|
||||
active_parameter: call_info.active_parameter.map(|it| it as u64),
|
||||
}))
|
||||
} else {
|
||||
Ok(None)
|
||||
|
|
Loading…
Reference in a new issue