aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Loucks <[email protected]>2020-06-03 12:26:15 +0100
committerAaron Loucks <[email protected]>2020-06-03 12:26:15 +0100
commitf06b2bcd91329fb795839a4eabd8f43aa472aeb2 (patch)
tree9642c029da5dc0bd44b36087464e2407062bf040
parent1211a46826ee8a08683e4cfe151649efd6fd90fa (diff)
Use split1 when formatting function signature params
-rw-r--r--Cargo.lock1
-rw-r--r--crates/ra_ide/src/display/function_signature.rs8
-rw-r--r--crates/stdx/src/lib.rs5
-rw-r--r--crates/test_utils/Cargo.toml3
-rw-r--r--crates/test_utils/src/lib.rs6
5 files changed, 12 insertions, 11 deletions
diff --git a/Cargo.lock b/Cargo.lock
index def4ed45e..aca283cda 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1639,6 +1639,7 @@ dependencies = [
1639 "relative-path", 1639 "relative-path",
1640 "rustc-hash", 1640 "rustc-hash",
1641 "serde_json", 1641 "serde_json",
1642 "stdx",
1642 "text-size", 1643 "text-size",
1643] 1644]
1644 1645
diff --git a/crates/ra_ide/src/display/function_signature.rs b/crates/ra_ide/src/display/function_signature.rs
index b081ecaad..ca8a6a650 100644
--- a/crates/ra_ide/src/display/function_signature.rs
+++ b/crates/ra_ide/src/display/function_signature.rs
@@ -10,7 +10,7 @@ use std::{
10use hir::{Docs, Documentation, HasSource, HirDisplay}; 10use hir::{Docs, Documentation, HasSource, HirDisplay};
11use ra_ide_db::RootDatabase; 11use ra_ide_db::RootDatabase;
12use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner}; 12use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner};
13use stdx::SepBy; 13use stdx::{split1, SepBy};
14 14
15use crate::display::{generic_parameters, where_predicates}; 15use crate::display::{generic_parameters, where_predicates};
16 16
@@ -210,10 +210,8 @@ impl From<&'_ ast::FnDef> for FunctionSignature {
210 // macro-generated functions are missing whitespace 210 // macro-generated functions are missing whitespace
211 fn fmt_param(param: ast::Param) -> String { 211 fn fmt_param(param: ast::Param) -> String {
212 let text = param.syntax().text().to_string(); 212 let text = param.syntax().text().to_string();
213 match text.find(':') { 213 match split1(&text, ':') {
214 Some(pos) if 1 + pos < text.len() => { 214 Some((left, right)) => format!("{}: {}", left.trim(), right.trim()),
215 format!("{} {}", &text[0..1 + pos].trim(), &text[1 + pos..].trim())
216 }
217 _ => text, 215 _ => text,
218 } 216 }
219 } 217 }
diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs
index 71a57fba2..c0356344c 100644
--- a/crates/stdx/src/lib.rs
+++ b/crates/stdx/src/lib.rs
@@ -124,3 +124,8 @@ pub fn replace(buf: &mut String, from: char, to: &str) {
124 // FIXME: do this in place. 124 // FIXME: do this in place.
125 *buf = buf.replace(from, to) 125 *buf = buf.replace(from, to)
126} 126}
127
128pub fn split1(haystack: &str, delim: char) -> Option<(&str, &str)> {
129 let idx = haystack.find(delim)?;
130 Some((&haystack[..idx], &haystack[idx + delim.len_utf8()..]))
131}
diff --git a/crates/test_utils/Cargo.toml b/crates/test_utils/Cargo.toml
index 4d185b01c..8840bf36a 100644
--- a/crates/test_utils/Cargo.toml
+++ b/crates/test_utils/Cargo.toml
@@ -14,4 +14,5 @@ serde_json = "1.0.48"
14relative-path = "1.0.0" 14relative-path = "1.0.0"
15rustc-hash = "1.1.0" 15rustc-hash = "1.1.0"
16 16
17ra_cfg = { path = "../ra_cfg" } \ No newline at end of file 17ra_cfg = { path = "../ra_cfg" }
18stdx = { path = "../stdx" } \ No newline at end of file
diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs
index 1bd97215c..2141bfc20 100644
--- a/crates/test_utils/src/lib.rs
+++ b/crates/test_utils/src/lib.rs
@@ -15,6 +15,7 @@ use std::{
15}; 15};
16 16
17pub use ra_cfg::CfgOptions; 17pub use ra_cfg::CfgOptions;
18use stdx::split1;
18 19
19pub use relative_path::{RelativePath, RelativePathBuf}; 20pub use relative_path::{RelativePath, RelativePathBuf};
20pub use rustc_hash::FxHashMap; 21pub use rustc_hash::FxHashMap;
@@ -332,11 +333,6 @@ fn parse_meta(meta: &str) -> FixtureMeta {
332 FixtureMeta::File(FileMeta { path, crate_name: krate, deps, edition, cfg, env }) 333 FixtureMeta::File(FileMeta { path, crate_name: krate, deps, edition, cfg, env })
333} 334}
334 335
335fn split1(haystack: &str, delim: char) -> Option<(&str, &str)> {
336 let idx = haystack.find(delim)?;
337 Some((&haystack[..idx], &haystack[idx + delim.len_utf8()..]))
338}
339
340/// Adjusts the indentation of the first line to the minimum indentation of the rest of the lines. 336/// Adjusts the indentation of the first line to the minimum indentation of the rest of the lines.
341/// This allows fixtures to start off in a different indentation, e.g. to align the first line with 337/// This allows fixtures to start off in a different indentation, e.g. to align the first line with
342/// the other lines visually: 338/// the other lines visually: