aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r--crates/ra_ide_api/src/display.rs58
-rw-r--r--crates/ra_ide_api/src/lib.rs27
2 files changed, 36 insertions, 49 deletions
diff --git a/crates/ra_ide_api/src/display.rs b/crates/ra_ide_api/src/display.rs
index 60fa72f1b..9d9d2097f 100644
--- a/crates/ra_ide_api/src/display.rs
+++ b/crates/ra_ide_api/src/display.rs
@@ -1,5 +1,34 @@
1//! This module contains utilities for rendering turning things into something
2//! that may be used to render in UI.
1use super::*; 3use super::*;
2use std::fmt::{self, Display}; 4use std::fmt::{self, Display};
5use join_to_string::join;
6
7/// Contains information about a function signature
8#[derive(Debug)]
9pub struct FunctionSignature {
10 /// Optional visibility
11 pub visibility: Option<String>,
12 /// Name of the function
13 pub name: Option<String>,
14 /// Documentation for the function
15 pub doc: Option<Documentation>,
16 /// Generic parameters
17 pub generic_parameters: Vec<String>,
18 /// Parameters of the function
19 pub parameters: Vec<String>,
20 /// Optional return type
21 pub ret_type: Option<String>,
22 /// Where predicates
23 pub where_predicates: Vec<String>,
24}
25
26impl FunctionSignature {
27 pub(crate) fn with_doc_opt(mut self, doc: Option<Documentation>) -> Self {
28 self.doc = doc;
29 self
30 }
31}
3 32
4impl Display for FunctionSignature { 33impl Display for FunctionSignature {
5 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 34 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@@ -12,14 +41,13 @@ impl Display for FunctionSignature {
12 } 41 }
13 42
14 if !self.generic_parameters.is_empty() { 43 if !self.generic_parameters.is_empty() {
15 write!(f, "<")?; 44 join(self.generic_parameters.iter())
16 write_joined(f, &self.generic_parameters, ", ")?; 45 .separator(", ")
17 write!(f, ">")?; 46 .surround_with("<", ">")
47 .to_fmt(f)?;
18 } 48 }
19 49
20 write!(f, "(")?; 50 join(self.parameters.iter()).separator(", ").surround_with("(", ")").to_fmt(f)?;
21 write_joined(f, &self.parameters, ", ")?;
22 write!(f, ")")?;
23 51
24 if let Some(t) = &self.ret_type { 52 if let Some(t) = &self.ret_type {
25 write!(f, " -> {}", t)?; 53 write!(f, " -> {}", t)?;
@@ -27,25 +55,9 @@ impl Display for FunctionSignature {
27 55
28 if !self.where_predicates.is_empty() { 56 if !self.where_predicates.is_empty() {
29 write!(f, "\nwhere ")?; 57 write!(f, "\nwhere ")?;
30 write_joined(f, &self.where_predicates, ",\n ")?; 58 join(self.where_predicates.iter()).separator(",\n ").to_fmt(f)?;
31 } 59 }
32 60
33 Ok(()) 61 Ok(())
34 } 62 }
35} 63}
36
37fn write_joined<T: Display>(
38 f: &mut fmt::Formatter,
39 items: impl IntoIterator<Item = T>,
40 sep: &str,
41) -> fmt::Result {
42 let mut first = true;
43 for e in items {
44 if !first {
45 write!(f, "{}", sep)?;
46 }
47 first = false;
48 write!(f, "{}", e)?;
49 }
50 Ok(())
51}
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs
index 7f8f454bc..816bab94f 100644
--- a/crates/ra_ide_api/src/lib.rs
+++ b/crates/ra_ide_api/src/lib.rs
@@ -73,6 +73,7 @@ pub use crate::{
73 syntax_highlighting::HighlightedRange, 73 syntax_highlighting::HighlightedRange,
74 structure::{StructureNode, file_structure}, 74 structure::{StructureNode, file_structure},
75 diagnostics::Severity, 75 diagnostics::Severity,
76 display::FunctionSignature,
76}; 77};
77 78
78pub use ra_db::{ 79pub use ra_db::{
@@ -248,32 +249,6 @@ pub struct CallInfo {
248 pub active_parameter: Option<usize>, 249 pub active_parameter: Option<usize>,
249} 250}
250 251
251/// Contains information about a function signature
252#[derive(Debug)]
253pub struct FunctionSignature {
254 /// Optional visibility
255 pub visibility: Option<String>,
256 /// Name of the function
257 pub name: Option<String>,
258 /// Documentation for the function
259 pub doc: Option<Documentation>,
260 /// Generic parameters
261 pub generic_parameters: Vec<String>,
262 /// Parameters of the function
263 pub parameters: Vec<String>,
264 /// Optional return type
265 pub ret_type: Option<String>,
266 /// Where predicates
267 pub where_predicates: Vec<String>,
268}
269
270impl FunctionSignature {
271 pub(crate) fn with_doc_opt(mut self, doc: Option<Documentation>) -> Self {
272 self.doc = doc;
273 self
274 }
275}
276
277/// `AnalysisHost` stores the current state of the world. 252/// `AnalysisHost` stores the current state of the world.
278#[derive(Debug, Default)] 253#[derive(Debug, Default)]
279pub struct AnalysisHost { 254pub struct AnalysisHost {