aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/display/function_signature.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-07-16 20:32:20 +0100
committerAleksey Kladov <[email protected]>2020-07-16 20:32:20 +0100
commit0265778e86f7e130a921ab6307cfdcc0ad953fe0 (patch)
tree9aab4e60f3f55b783e6b2b105b239115e8fb958d /crates/ra_ide/src/display/function_signature.rs
parent4759a39f06be1ec1469101a8aac39039b8743806 (diff)
Don't use function signature for Display
Diffstat (limited to 'crates/ra_ide/src/display/function_signature.rs')
-rw-r--r--crates/ra_ide/src/display/function_signature.rs56
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)
5use std::{ 5use std::convert::From;
6 convert::From,
7 fmt::{self, Display},
8};
9 6
10use hir::{Docs, Documentation, HasSource, HirDisplay}; 7use hir::{Docs, Documentation, HasSource, HirDisplay};
11use ra_ide_db::RootDatabase; 8use ra_ide_db::RootDatabase;
12use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner}; 9use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner};
13use stdx::{split_delim, SepBy}; 10use stdx::split_delim;
14 11
15use crate::display::{generic_parameters, where_predicates}; 12use 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
251impl 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}