aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorJeremy Kolb <[email protected]>2019-10-28 00:11:02 +0000
committerJeremy Kolb <[email protected]>2019-10-28 12:32:22 +0000
commit55d4b06a53246c144be900877e6ac03237d6f8b4 (patch)
treee31953e2db157710932d3c689b6e691d92bee6da /crates
parent5a59bc9fcbbacb3d214e5bb9490f66ccb0abf5cb (diff)
Add disciminant
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide_api/src/call_info.rs10
-rw-r--r--crates/ra_ide_api/src/display/function_signature.rs14
2 files changed, 17 insertions, 7 deletions
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<Cal
29 (CallInfo::with_fn(db, it), it.data(db).has_self_param()) 29 (CallInfo::with_fn(db, it), it.data(db).has_self_param())
30 } 30 }
31 hir::CallableDef::Struct(it) => (CallInfo::with_struct(db, it), false), 31 hir::CallableDef::Struct(it) => (CallInfo::with_struct(db, it), false),
32 //FIXME: handle other callables 32 hir::CallableDef::EnumVariant(_it) => return None,
33 _ => return None,
34 } 33 }
35 } 34 }
36 FnCallNode::MethodCallExpr(expr) => { 35 FnCallNode::MethodCallExpr(expr) => {
@@ -476,14 +475,13 @@ fn main() {
476 let info = call_info( 475 let info = call_info(
477 r#" 476 r#"
478/// A cool tuple struct 477/// A cool tuple struct
479struct TS(String, i32); 478struct TS(u32, i32);
480fn main() { 479fn main() {
481 let s = TS("".into(), <|>); 480 let s = TS(0, <|>);
482}"#, 481}"#,
483 ); 482 );
484 483
485 //assert_eq!(info.label(), "struct TS(String, i32)"); 484 assert_eq!(info.label(), "struct TS(0: u32, 1: i32) -> TS");
486 assert_eq!(info.label(), "fn TS(0: {unknown}, 1: i32) -> TS");
487 assert_eq!(info.doc().map(|it| it.into()), Some("A cool tuple struct".to_string())); 485 assert_eq!(info.doc().map(|it| it.into()), Some("A cool tuple struct".to_string()));
488 assert_eq!(info.active_parameter, Some(1)); 486 assert_eq!(info.active_parameter, Some(1));
489 } 487 }
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::{
12 display::{generic_parameters, where_predicates}, 12 display::{generic_parameters, where_predicates},
13}; 13};
14 14
15#[derive(Debug)]
16pub enum SigKind {
17 Function,
18 Struct,
19}
20
15/// Contains information about a function signature 21/// Contains information about a function signature
16#[derive(Debug)] 22#[derive(Debug)]
17pub struct FunctionSignature { 23pub struct FunctionSignature {
24 pub kind: SigKind,
18 /// Optional visibility 25 /// Optional visibility
19 pub visibility: Option<String>, 26 pub visibility: Option<String>,
20 /// Name of the function 27 /// Name of the function
@@ -59,6 +66,7 @@ impl FunctionSignature {
59 .collect(); 66 .collect();
60 67
61 FunctionSignature { 68 FunctionSignature {
69 kind: SigKind::Struct,
62 visibility: node.visibility().map(|n| n.syntax().text().to_string()), 70 visibility: node.visibility().map(|n| n.syntax().text().to_string()),
63 name: node.name().map(|n| n.text().to_string()), 71 name: node.name().map(|n| n.text().to_string()),
64 ret_type: node.name().map(|n| n.text().to_string()), 72 ret_type: node.name().map(|n| n.text().to_string()),
@@ -86,6 +94,7 @@ impl From<&'_ ast::FnDef> for FunctionSignature {
86 } 94 }
87 95
88 FunctionSignature { 96 FunctionSignature {
97 kind: SigKind::Function,
89 visibility: node.visibility().map(|n| n.syntax().text().to_string()), 98 visibility: node.visibility().map(|n| n.syntax().text().to_string()),
90 name: node.name().map(|n| n.text().to_string()), 99 name: node.name().map(|n| n.text().to_string()),
91 ret_type: node 100 ret_type: node
@@ -108,7 +117,10 @@ impl Display for FunctionSignature {
108 } 117 }
109 118
110 if let Some(name) = &self.name { 119 if let Some(name) = &self.name {
111 write!(f, "fn {}", name)?; 120 match self.kind {
121 SigKind::Function => write!(f, "fn {}", name)?,
122 SigKind::Struct => write!(f, "struct {}", name)?,
123 }
112 } 124 }
113 125
114 if !self.generic_parameters.is_empty() { 126 if !self.generic_parameters.is_empty() {