diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-06-03 12:27:10 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-06-03 12:27:10 +0100 |
commit | e644f64f2a68a14a841adb3f3e897d1fcb35f23f (patch) | |
tree | 09c4d8eff84a57c684f7a961bf948b38c14d3da3 /crates | |
parent | c6b739bad0c0a458d3ae6bb2bc4514477f325e31 (diff) | |
parent | f06b2bcd91329fb795839a4eabd8f43aa472aeb2 (diff) |
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 <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_ide/src/display/function_signature.rs | 13 | ||||
-rw-r--r-- | crates/stdx/src/lib.rs | 5 | ||||
-rw-r--r-- | crates/test_utils/Cargo.toml | 3 | ||||
-rw-r--r-- | crates/test_utils/src/lib.rs | 6 |
4 files changed, 19 insertions, 8 deletions
diff --git a/crates/ra_ide/src/display/function_signature.rs b/crates/ra_ide/src/display/function_signature.rs index 9572debd8..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::{ | |||
10 | use hir::{Docs, Documentation, HasSource, HirDisplay}; | 10 | use hir::{Docs, Documentation, HasSource, HirDisplay}; |
11 | use ra_ide_db::RootDatabase; | 11 | use ra_ide_db::RootDatabase; |
12 | use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner}; | 12 | use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner}; |
13 | use stdx::SepBy; | 13 | use stdx::{split1, SepBy}; |
14 | 14 | ||
15 | use crate::display::{generic_parameters, where_predicates}; | 15 | use crate::display::{generic_parameters, where_predicates}; |
16 | 16 | ||
@@ -207,7 +207,16 @@ impl From<&'_ ast::FnDef> for FunctionSignature { | |||
207 | res.push(raw_param); | 207 | res.push(raw_param); |
208 | } | 208 | } |
209 | 209 | ||
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)); | ||
211 | res_types.extend(param_list.params().map(|param| { | 220 | res_types.extend(param_list.params().map(|param| { |
212 | let param_text = param.syntax().text().to_string(); | 221 | let param_text = param.syntax().text().to_string(); |
213 | match param_text.split(':').nth(1).and_then(|it| it.get(1..)) { | 222 | match param_text.split(':').nth(1).and_then(|it| it.get(1..)) { |
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 | |||
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 | } | ||
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" | |||
14 | relative-path = "1.0.0" | 14 | relative-path = "1.0.0" |
15 | rustc-hash = "1.1.0" | 15 | rustc-hash = "1.1.0" |
16 | 16 | ||
17 | ra_cfg = { path = "../ra_cfg" } \ No newline at end of file | 17 | ra_cfg = { path = "../ra_cfg" } |
18 | stdx = { 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 | ||
17 | pub use ra_cfg::CfgOptions; | 17 | pub use ra_cfg::CfgOptions; |
18 | use stdx::split1; | ||
18 | 19 | ||
19 | pub use relative_path::{RelativePath, RelativePathBuf}; | 20 | pub use relative_path::{RelativePath, RelativePathBuf}; |
20 | pub use rustc_hash::FxHashMap; | 21 | pub 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 | ||
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 | |||
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: |