From 55d4b06a53246c144be900877e6ac03237d6f8b4 Mon Sep 17 00:00:00 2001 From: Jeremy Kolb Date: Sun, 27 Oct 2019 20:11:02 -0400 Subject: Add disciminant --- crates/ra_ide_api/src/call_info.rs | 10 ++++------ crates/ra_ide_api/src/display/function_signature.rs | 14 +++++++++++++- 2 files changed, 17 insertions(+), 7 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs index dfd6e69c5..29ae2f552 100644 --- a/crates/ra_ide_api/src/call_info.rs +++ b/crates/ra_ide_api/src/call_info.rs @@ -29,8 +29,7 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option (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)); } diff --git a/crates/ra_ide_api/src/display/function_signature.rs b/crates/ra_ide_api/src/display/function_signature.rs index 0697a0727..6555f8619 100644 --- a/crates/ra_ide_api/src/display/function_signature.rs +++ b/crates/ra_ide_api/src/display/function_signature.rs @@ -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, /// 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() { -- cgit v1.2.3