mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +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 ra_editor::find_node_at_offset;
|
||||||
use hir::FnSignatureInfo;
|
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.
|
/// Computes parameter information for the given call expression.
|
||||||
pub(crate) fn call_info(
|
fn call_info_(
|
||||||
db: &RootDatabase,
|
db: &RootDatabase,
|
||||||
position: FilePosition,
|
position: FilePosition,
|
||||||
) -> Cancelable<Option<(FnSignatureInfo, Option<usize>)>> {
|
) -> 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.
|
/// `AnalysisHost` stores the current state of the world.
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct AnalysisHost {
|
pub struct AnalysisHost {
|
||||||
|
@ -393,10 +401,7 @@ impl Analysis {
|
||||||
hover::hover(&*self.db, position)
|
hover::hover(&*self.db, position)
|
||||||
}
|
}
|
||||||
/// Computes parameter information for the given call expression.
|
/// Computes parameter information for the given call expression.
|
||||||
pub fn call_info(
|
pub fn call_info(&self, position: FilePosition) -> Cancelable<Option<CallInfo>> {
|
||||||
&self,
|
|
||||||
position: FilePosition,
|
|
||||||
) -> Cancelable<Option<(FnSignatureInfo, Option<usize>)>> {
|
|
||||||
call_info::call_info(&*self.db, position)
|
call_info::call_info(&*self.db, position)
|
||||||
}
|
}
|
||||||
/// Returns a `mod name;` declaration which created the current module.
|
/// Returns a `mod name;` declaration which created the current module.
|
||||||
|
|
|
@ -475,36 +475,30 @@ pub fn handle_signature_help(
|
||||||
params: req::TextDocumentPositionParams,
|
params: req::TextDocumentPositionParams,
|
||||||
) -> Result<Option<req::SignatureHelp>> {
|
) -> Result<Option<req::SignatureHelp>> {
|
||||||
let position = params.try_conv_with(&world)?;
|
let position = params.try_conv_with(&world)?;
|
||||||
|
if let Some(call_info) = world.analysis().call_info(position)? {
|
||||||
if let Some((descriptor, active_param)) = world.analysis().resolve_callable(position)? {
|
let parameters: Vec<ParameterInformation> = call_info
|
||||||
let parameters: Vec<ParameterInformation> = descriptor
|
.parameters
|
||||||
.params
|
.into_iter()
|
||||||
.iter()
|
|
||||||
.map(|param| ParameterInformation {
|
.map(|param| ParameterInformation {
|
||||||
label: ParameterLabel::Simple(param.clone()),
|
label: ParameterLabel::Simple(param.clone()),
|
||||||
documentation: None,
|
documentation: None,
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
let documentation = call_info.doc.map(|value| {
|
||||||
let documentation = if let Some(doc) = descriptor.doc {
|
Documentation::MarkupContent(MarkupContent {
|
||||||
Some(Documentation::MarkupContent(MarkupContent {
|
|
||||||
kind: MarkupKind::Markdown,
|
kind: MarkupKind::Markdown,
|
||||||
value: doc,
|
value,
|
||||||
}))
|
})
|
||||||
} else {
|
});
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
let sig_info = SignatureInformation {
|
let sig_info = SignatureInformation {
|
||||||
label: descriptor.label,
|
label: call_info.label,
|
||||||
documentation,
|
documentation,
|
||||||
parameters: Some(parameters),
|
parameters: Some(parameters),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Some(req::SignatureHelp {
|
Ok(Some(req::SignatureHelp {
|
||||||
signatures: vec![sig_info],
|
signatures: vec![sig_info],
|
||||||
active_signature: Some(0),
|
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 {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue