aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/display
diff options
context:
space:
mode:
authorJeremy Kolb <[email protected]>2019-10-27 23:12:21 +0000
committerJeremy Kolb <[email protected]>2019-10-28 12:32:22 +0000
commit5a59bc9fcbbacb3d214e5bb9490f66ccb0abf5cb (patch)
treeed2cae97531aaff1ddbd509858358aca33e46635 /crates/ra_ide_api/src/display
parent02828520a75f686d044cb9767572ea49e93c4828 (diff)
WIP: Expand signature help
This is hacky but works for tuple structs. Proof of concept.
Diffstat (limited to 'crates/ra_ide_api/src/display')
-rw-r--r--crates/ra_ide_api/src/display/function_signature.rs29
1 files changed, 28 insertions, 1 deletions
diff --git a/crates/ra_ide_api/src/display/function_signature.rs b/crates/ra_ide_api/src/display/function_signature.rs
index 43f022ccd..0697a0727 100644
--- a/crates/ra_ide_api/src/display/function_signature.rs
+++ b/crates/ra_ide_api/src/display/function_signature.rs
@@ -2,7 +2,7 @@
2 2
3use std::fmt::{self, Display}; 3use std::fmt::{self, Display};
4 4
5use hir::{Docs, Documentation, HasSource}; 5use hir::{Docs, Documentation, HasSource, HirDisplay};
6use join_to_string::join; 6use join_to_string::join;
7use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner}; 7use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner};
8use std::convert::From; 8use std::convert::From;
@@ -42,6 +42,33 @@ impl FunctionSignature {
42 let ast_node = function.source(db).ast; 42 let ast_node = function.source(db).ast;
43 FunctionSignature::from(&ast_node).with_doc_opt(doc) 43 FunctionSignature::from(&ast_node).with_doc_opt(doc)
44 } 44 }
45
46 pub(crate) fn from_struct(db: &db::RootDatabase, st: hir::Struct) -> Self {
47 let doc = st.docs(db);
48
49 let node: ast::StructDef = st.source(db).ast;
50
51 let params = st
52 .fields(db)
53 .into_iter()
54 .map(|field: hir::StructField| {
55 let name = field.name(db);
56 let ty = field.ty(db);
57 format!("{}: {}", name, ty.display(db))
58 })
59 .collect();
60
61 FunctionSignature {
62 visibility: node.visibility().map(|n| n.syntax().text().to_string()),
63 name: node.name().map(|n| n.text().to_string()),
64 ret_type: node.name().map(|n| n.text().to_string()),
65 parameters: /*param_list(node)*/ params,
66 generic_parameters: generic_parameters(&node),
67 where_predicates: where_predicates(&node),
68 doc: None,
69 }
70 .with_doc_opt(doc)
71 }
45} 72}
46 73
47impl From<&'_ ast::FnDef> for FunctionSignature { 74impl From<&'_ ast::FnDef> for FunctionSignature {