diff options
author | Aleksey Kladov <[email protected]> | 2020-07-16 20:51:44 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-07-16 20:51:44 +0100 |
commit | a5ae8b8b92748e1b876002799d160136a7836212 (patch) | |
tree | d6d8bfd99ef8c33eba4e679d4556c84aaf69bebd /crates/ra_ide/src/display | |
parent | edc0190f7a2a701ef7c8534b053070212798cd8b (diff) |
Inlay hints use callables
Diffstat (limited to 'crates/ra_ide/src/display')
-rw-r--r-- | crates/ra_ide/src/display/function_signature.rs | 96 |
1 files changed, 1 insertions, 95 deletions
diff --git a/crates/ra_ide/src/display/function_signature.rs b/crates/ra_ide/src/display/function_signature.rs index 77551117b..f6e11357f 100644 --- a/crates/ra_ide/src/display/function_signature.rs +++ b/crates/ra_ide/src/display/function_signature.rs | |||
@@ -4,8 +4,7 @@ | |||
4 | // rewritten (matklad 2020-05-07) | 4 | // rewritten (matklad 2020-05-07) |
5 | use std::convert::From; | 5 | use std::convert::From; |
6 | 6 | ||
7 | use hir::{Docs, Documentation, HasSource, HirDisplay}; | 7 | use hir::Documentation; |
8 | use ra_ide_db::RootDatabase; | ||
9 | use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner}; | 8 | use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner}; |
10 | use stdx::split_delim; | 9 | use stdx::split_delim; |
11 | 10 | ||
@@ -14,8 +13,6 @@ use crate::display::{generic_parameters, where_predicates}; | |||
14 | #[derive(Debug)] | 13 | #[derive(Debug)] |
15 | pub(crate) enum CallableKind { | 14 | pub(crate) enum CallableKind { |
16 | Function, | 15 | Function, |
17 | StructConstructor, | ||
18 | VariantConstructor, | ||
19 | } | 16 | } |
20 | 17 | ||
21 | /// Contains information about a function signature | 18 | /// Contains information about a function signature |
@@ -56,97 +53,6 @@ pub(crate) struct FunctionQualifier { | |||
56 | pub(crate) extern_abi: Option<String>, | 53 | pub(crate) extern_abi: Option<String>, |
57 | } | 54 | } |
58 | 55 | ||
59 | impl FunctionSignature { | ||
60 | pub(crate) fn from_hir(db: &RootDatabase, function: hir::Function) -> Self { | ||
61 | let ast_node = function.source(db).value; | ||
62 | let mut res = FunctionSignature::from(&ast_node); | ||
63 | res.doc = function.docs(db); | ||
64 | res | ||
65 | } | ||
66 | |||
67 | pub(crate) fn from_struct(db: &RootDatabase, st: hir::Struct) -> Option<Self> { | ||
68 | let node: ast::StructDef = st.source(db).value; | ||
69 | if let ast::StructKind::Record(_) = node.kind() { | ||
70 | return None; | ||
71 | }; | ||
72 | |||
73 | let mut params = vec![]; | ||
74 | let mut parameter_types = vec![]; | ||
75 | for field in st.fields(db).into_iter() { | ||
76 | let ty = field.signature_ty(db); | ||
77 | let raw_param = format!("{}", ty.display(db)); | ||
78 | |||
79 | if let Some(param_type) = raw_param.split(':').nth(1).and_then(|it| it.get(1..)) { | ||
80 | parameter_types.push(param_type.to_string()); | ||
81 | } else { | ||
82 | // useful when you have tuple struct | ||
83 | parameter_types.push(raw_param.clone()); | ||
84 | } | ||
85 | params.push(raw_param); | ||
86 | } | ||
87 | |||
88 | Some(FunctionSignature { | ||
89 | kind: CallableKind::StructConstructor, | ||
90 | visibility: node.visibility().map(|n| n.syntax().text().to_string()), | ||
91 | // Do we need `const`? | ||
92 | qualifier: Default::default(), | ||
93 | name: node.name().map(|n| n.text().to_string()), | ||
94 | ret_type: node.name().map(|n| n.text().to_string()), | ||
95 | parameters: params, | ||
96 | parameter_names: vec![], | ||
97 | parameter_types, | ||
98 | generic_parameters: generic_parameters(&node), | ||
99 | where_predicates: where_predicates(&node), | ||
100 | doc: st.docs(db), | ||
101 | has_self_param: false, | ||
102 | }) | ||
103 | } | ||
104 | |||
105 | pub(crate) fn from_enum_variant(db: &RootDatabase, variant: hir::EnumVariant) -> Option<Self> { | ||
106 | let node: ast::EnumVariant = variant.source(db).value; | ||
107 | match node.kind() { | ||
108 | ast::StructKind::Record(_) | ast::StructKind::Unit => return None, | ||
109 | _ => (), | ||
110 | }; | ||
111 | |||
112 | let parent_name = variant.parent_enum(db).name(db).to_string(); | ||
113 | |||
114 | let name = format!("{}::{}", parent_name, variant.name(db)); | ||
115 | |||
116 | let mut params = vec![]; | ||
117 | let mut parameter_types = vec![]; | ||
118 | for field in variant.fields(db).into_iter() { | ||
119 | let ty = field.signature_ty(db); | ||
120 | let raw_param = format!("{}", ty.display(db)); | ||
121 | if let Some(param_type) = raw_param.split(':').nth(1).and_then(|it| it.get(1..)) { | ||
122 | parameter_types.push(param_type.to_string()); | ||
123 | } else { | ||
124 | // The unwrap_or_else is useful when you have tuple | ||
125 | parameter_types.push(raw_param); | ||
126 | } | ||
127 | let name = field.name(db); | ||
128 | |||
129 | params.push(format!("{}: {}", name, ty.display(db))); | ||
130 | } | ||
131 | |||
132 | Some(FunctionSignature { | ||
133 | kind: CallableKind::VariantConstructor, | ||
134 | visibility: None, | ||
135 | // Do we need `const`? | ||
136 | qualifier: Default::default(), | ||
137 | name: Some(name), | ||
138 | ret_type: None, | ||
139 | parameters: params, | ||
140 | parameter_names: vec![], | ||
141 | parameter_types, | ||
142 | generic_parameters: vec![], | ||
143 | where_predicates: vec![], | ||
144 | doc: variant.docs(db), | ||
145 | has_self_param: false, | ||
146 | }) | ||
147 | } | ||
148 | } | ||
149 | |||
150 | impl From<&'_ ast::FnDef> for FunctionSignature { | 56 | impl From<&'_ ast::FnDef> for FunctionSignature { |
151 | fn from(node: &ast::FnDef) -> FunctionSignature { | 57 | fn from(node: &ast::FnDef) -> FunctionSignature { |
152 | fn param_list(node: &ast::FnDef) -> (bool, Vec<String>, Vec<String>) { | 58 | fn param_list(node: &ast::FnDef) -> (bool, Vec<String>, Vec<String>) { |