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>
This commit is contained in:
bors[bot] 2020-06-03 11:27:10 +00:00 committed by GitHub
commit e644f64f2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 8 deletions

1
Cargo.lock generated
View File

@ -1640,6 +1640,7 @@ dependencies = [
"relative-path",
"rustc-hash",
"serde_json",
"stdx",
"text-size",
]

View File

@ -10,7 +10,7 @@ use std::{
use hir::{Docs, Documentation, HasSource, HirDisplay};
use ra_ide_db::RootDatabase;
use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner};
use stdx::SepBy;
use stdx::{split1, SepBy};
use crate::display::{generic_parameters, where_predicates};
@ -207,7 +207,16 @@ impl From<&'_ ast::FnDef> for FunctionSignature {
res.push(raw_param);
}
res.extend(param_list.params().map(|param| param.syntax().text().to_string()));
// macro-generated functions are missing whitespace
fn fmt_param(param: ast::Param) -> String {
let text = param.syntax().text().to_string();
match split1(&text, ':') {
Some((left, right)) => format!("{}: {}", left.trim(), right.trim()),
_ => text,
}
}
res.extend(param_list.params().map(fmt_param));
res_types.extend(param_list.params().map(|param| {
let param_text = param.syntax().text().to_string();
match param_text.split(':').nth(1).and_then(|it| it.get(1..)) {

View File

@ -124,3 +124,8 @@ pub fn replace(buf: &mut String, from: char, to: &str) {
// FIXME: do this in place.
*buf = buf.replace(from, to)
}
pub fn split1(haystack: &str, delim: char) -> Option<(&str, &str)> {
let idx = haystack.find(delim)?;
Some((&haystack[..idx], &haystack[idx + delim.len_utf8()..]))
}

View File

@ -14,4 +14,5 @@ serde_json = "1.0.48"
relative-path = "1.0.0"
rustc-hash = "1.1.0"
ra_cfg = { path = "../ra_cfg" }
ra_cfg = { path = "../ra_cfg" }
stdx = { path = "../stdx" }

View File

@ -15,6 +15,7 @@ use std::{
};
pub use ra_cfg::CfgOptions;
use stdx::split1;
pub use relative_path::{RelativePath, RelativePathBuf};
pub use rustc_hash::FxHashMap;
@ -332,11 +333,6 @@ fn parse_meta(meta: &str) -> FixtureMeta {
FixtureMeta::File(FileMeta { path, crate_name: krate, deps, edition, cfg, env })
}
fn split1(haystack: &str, delim: char) -> Option<(&str, &str)> {
let idx = haystack.find(delim)?;
Some((&haystack[..idx], &haystack[idx + delim.len_utf8()..]))
}
/// Adjusts the indentation of the first line to the minimum indentation of the rest of the lines.
/// This allows fixtures to start off in a different indentation, e.g. to align the first line with
/// the other lines visually: