mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-05 19:43:24 +00:00
Add disciminant
This commit is contained in:
parent
5a59bc9fcb
commit
55d4b06a53
@ -29,8 +29,7 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal
|
||||
(CallInfo::with_fn(db, it), it.data(db).has_self_param())
|
||||
}
|
||||
hir::CallableDef::Struct(it) => (CallInfo::with_struct(db, it), false),
|
||||
//FIXME: handle other callables
|
||||
_ => return None,
|
||||
hir::CallableDef::EnumVariant(_it) => return None,
|
||||
}
|
||||
}
|
||||
FnCallNode::MethodCallExpr(expr) => {
|
||||
@ -476,14 +475,13 @@ fn main() {
|
||||
let info = call_info(
|
||||
r#"
|
||||
/// A cool tuple struct
|
||||
struct TS(String, i32);
|
||||
struct TS(u32, i32);
|
||||
fn main() {
|
||||
let s = TS("".into(), <|>);
|
||||
let s = TS(0, <|>);
|
||||
}"#,
|
||||
);
|
||||
|
||||
//assert_eq!(info.label(), "struct TS(String, i32)");
|
||||
assert_eq!(info.label(), "fn TS(0: {unknown}, 1: i32) -> TS");
|
||||
assert_eq!(info.label(), "struct TS(0: u32, 1: i32) -> TS");
|
||||
assert_eq!(info.doc().map(|it| it.into()), Some("A cool tuple struct".to_string()));
|
||||
assert_eq!(info.active_parameter, Some(1));
|
||||
}
|
||||
|
@ -12,9 +12,16 @@ use crate::{
|
||||
display::{generic_parameters, where_predicates},
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum SigKind {
|
||||
Function,
|
||||
Struct,
|
||||
}
|
||||
|
||||
/// Contains information about a function signature
|
||||
#[derive(Debug)]
|
||||
pub struct FunctionSignature {
|
||||
pub kind: SigKind,
|
||||
/// Optional visibility
|
||||
pub visibility: Option<String>,
|
||||
/// Name of the function
|
||||
@ -59,6 +66,7 @@ impl FunctionSignature {
|
||||
.collect();
|
||||
|
||||
FunctionSignature {
|
||||
kind: SigKind::Struct,
|
||||
visibility: node.visibility().map(|n| n.syntax().text().to_string()),
|
||||
name: node.name().map(|n| n.text().to_string()),
|
||||
ret_type: node.name().map(|n| n.text().to_string()),
|
||||
@ -86,6 +94,7 @@ impl From<&'_ ast::FnDef> for FunctionSignature {
|
||||
}
|
||||
|
||||
FunctionSignature {
|
||||
kind: SigKind::Function,
|
||||
visibility: node.visibility().map(|n| n.syntax().text().to_string()),
|
||||
name: node.name().map(|n| n.text().to_string()),
|
||||
ret_type: node
|
||||
@ -108,7 +117,10 @@ impl Display for FunctionSignature {
|
||||
}
|
||||
|
||||
if let Some(name) = &self.name {
|
||||
write!(f, "fn {}", name)?;
|
||||
match self.kind {
|
||||
SigKind::Function => write!(f, "fn {}", name)?,
|
||||
SigKind::Struct => write!(f, "struct {}", name)?,
|
||||
}
|
||||
}
|
||||
|
||||
if !self.generic_parameters.is_empty() {
|
||||
|
Loading…
Reference in New Issue
Block a user