diff options
Diffstat (limited to 'crates/ra_ide/src/display')
-rw-r--r-- | crates/ra_ide/src/display/function_signature.rs | 56 |
1 files changed, 2 insertions, 54 deletions
diff --git a/crates/ra_ide/src/display/function_signature.rs b/crates/ra_ide/src/display/function_signature.rs index 9b7220d1f..77551117b 100644 --- a/crates/ra_ide/src/display/function_signature.rs +++ b/crates/ra_ide/src/display/function_signature.rs | |||
@@ -2,15 +2,12 @@ | |||
2 | 2 | ||
3 | // FIXME: this modules relies on strings and AST way too much, and it should be | 3 | // FIXME: this modules relies on strings and AST way too much, and it should be |
4 | // rewritten (matklad 2020-05-07) | 4 | // rewritten (matklad 2020-05-07) |
5 | use std::{ | 5 | use std::convert::From; |
6 | convert::From, | ||
7 | fmt::{self, Display}, | ||
8 | }; | ||
9 | 6 | ||
10 | use hir::{Docs, Documentation, HasSource, HirDisplay}; | 7 | use hir::{Docs, Documentation, HasSource, HirDisplay}; |
11 | use ra_ide_db::RootDatabase; | 8 | use ra_ide_db::RootDatabase; |
12 | use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner}; | 9 | use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner}; |
13 | use stdx::{split_delim, SepBy}; | 10 | use stdx::split_delim; |
14 | 11 | ||
15 | use crate::display::{generic_parameters, where_predicates}; | 12 | use crate::display::{generic_parameters, where_predicates}; |
16 | 13 | ||
@@ -247,52 +244,3 @@ impl From<&'_ ast::FnDef> for FunctionSignature { | |||
247 | } | 244 | } |
248 | } | 245 | } |
249 | } | 246 | } |
250 | |||
251 | impl Display for FunctionSignature { | ||
252 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
253 | if let Some(t) = &self.visibility { | ||
254 | write!(f, "{} ", t)?; | ||
255 | } | ||
256 | |||
257 | if self.qualifier.is_async { | ||
258 | write!(f, "async ")?; | ||
259 | } | ||
260 | |||
261 | if self.qualifier.is_const { | ||
262 | write!(f, "const ")?; | ||
263 | } | ||
264 | |||
265 | if self.qualifier.is_unsafe { | ||
266 | write!(f, "unsafe ")?; | ||
267 | } | ||
268 | |||
269 | if let Some(extern_abi) = &self.qualifier.extern_abi { | ||
270 | // Keyword `extern` is included in the string. | ||
271 | write!(f, "{} ", extern_abi)?; | ||
272 | } | ||
273 | |||
274 | if let Some(name) = &self.name { | ||
275 | match self.kind { | ||
276 | CallableKind::Function => write!(f, "fn {}", name)?, | ||
277 | CallableKind::StructConstructor => write!(f, "struct {}", name)?, | ||
278 | CallableKind::VariantConstructor => write!(f, "{}", name)?, | ||
279 | } | ||
280 | } | ||
281 | |||
282 | if !self.generic_parameters.is_empty() { | ||
283 | write!(f, "{}", self.generic_parameters.iter().sep_by(", ").surround_with("<", ">"))?; | ||
284 | } | ||
285 | |||
286 | write!(f, "{}", self.parameters.iter().sep_by(", ").surround_with("(", ")"))?; | ||
287 | |||
288 | if let Some(t) = &self.ret_type { | ||
289 | write!(f, " -> {}", t)?; | ||
290 | } | ||
291 | |||
292 | if !self.where_predicates.is_empty() { | ||
293 | write!(f, "\nwhere {}", self.where_predicates.iter().sep_by(",\n "))?; | ||
294 | } | ||
295 | |||
296 | Ok(()) | ||
297 | } | ||
298 | } | ||