Skip to content

Commit e644f64

Browse files
bors[bot]aloucks
andauthored
Merge #4678
4678: Unsquish parameter types in tooltips for macro-generated functions r=aloucks a=aloucks Note the missing whitespace between `:` and the parameter type. Before: ![image](https://user-images.githubusercontent.com/221559/83364680-faf13d80-a370-11ea-96b7-a041969a4954.png) After: ![image](https://user-images.githubusercontent.com/221559/83364685-03e20f00-a371-11ea-9668-4e6ebcb81947.png) Co-authored-by: Aaron Loucks <aloucks@cofront.net>
2 parents c6b739b + f06b2bc commit e644f64

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ra_ide/src/display/function_signature.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::{
1010
use hir::{Docs, Documentation, HasSource, HirDisplay};
1111
use ra_ide_db::RootDatabase;
1212
use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner};
13-
use stdx::SepBy;
13+
use stdx::{split1, SepBy};
1414

1515
use crate::display::{generic_parameters, where_predicates};
1616

@@ -207,7 +207,16 @@ impl From<&'_ ast::FnDef> for FunctionSignature {
207207
res.push(raw_param);
208208
}
209209

210-
res.extend(param_list.params().map(|param| param.syntax().text().to_string()));
210+
// macro-generated functions are missing whitespace
211+
fn fmt_param(param: ast::Param) -> String {
212+
let text = param.syntax().text().to_string();
213+
match split1(&text, ':') {
214+
Some((left, right)) => format!("{}: {}", left.trim(), right.trim()),
215+
_ => text,
216+
}
217+
}
218+
219+
res.extend(param_list.params().map(fmt_param));
211220
res_types.extend(param_list.params().map(|param| {
212221
let param_text = param.syntax().text().to_string();
213222
match param_text.split(':').nth(1).and_then(|it| it.get(1..)) {

crates/stdx/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,8 @@ pub fn replace(buf: &mut String, from: char, to: &str) {
124124
// FIXME: do this in place.
125125
*buf = buf.replace(from, to)
126126
}
127+
128+
pub 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+
}

crates/test_utils/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ serde_json = "1.0.48"
1414
relative-path = "1.0.0"
1515
rustc-hash = "1.1.0"
1616

17-
ra_cfg = { path = "../ra_cfg" }
17+
ra_cfg = { path = "../ra_cfg" }
18+
stdx = { path = "../stdx" }

crates/test_utils/src/lib.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use std::{
1515
};
1616

1717
pub use ra_cfg::CfgOptions;
18+
use stdx::split1;
1819

1920
pub use relative_path::{RelativePath, RelativePathBuf};
2021
pub use rustc_hash::FxHashMap;
@@ -332,11 +333,6 @@ fn parse_meta(meta: &str) -> FixtureMeta {
332333
FixtureMeta::File(FileMeta { path, crate_name: krate, deps, edition, cfg, env })
333334
}
334335

335-
fn 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-
340336
/// Adjusts the indentation of the first line to the minimum indentation of the rest of the lines.
341337
/// This allows fixtures to start off in a different indentation, e.g. to align the first line with
342338
/// the other lines visually:

0 commit comments

Comments
 (0)