mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 14:13:58 +00:00
Merge #10071
10071: internal: slightly improve compile times r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
35d98070d2
5 changed files with 22 additions and 19 deletions
|
@ -41,7 +41,7 @@ pub(crate) fn ssr_assists(
|
||||||
for (label, source_change) in assists.into_iter() {
|
for (label, source_change) in assists.into_iter() {
|
||||||
let assist = Assist {
|
let assist = Assist {
|
||||||
id,
|
id,
|
||||||
label: Label::new(label),
|
label: Label::new(label.to_string()),
|
||||||
group: Some(GroupLabel("Apply SSR".into())),
|
group: Some(GroupLabel("Apply SSR".into())),
|
||||||
target: comment_range,
|
target: comment_range,
|
||||||
source_change,
|
source_change,
|
||||||
|
|
|
@ -131,12 +131,8 @@ impl Assists {
|
||||||
target: TextRange,
|
target: TextRange,
|
||||||
f: impl FnOnce(&mut AssistBuilder),
|
f: impl FnOnce(&mut AssistBuilder),
|
||||||
) -> Option<()> {
|
) -> Option<()> {
|
||||||
if !self.is_allowed(&id) {
|
let mut f = Some(f);
|
||||||
return None;
|
self.add_impl(None, id, label.into(), target, &mut |it| f.take().unwrap()(it))
|
||||||
}
|
|
||||||
let label = Label::new(label.into());
|
|
||||||
let assist = Assist { id, label, group: None, target, source_change: None };
|
|
||||||
self.add_impl(assist, f)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn add_group(
|
pub(crate) fn add_group(
|
||||||
|
@ -146,26 +142,34 @@ impl Assists {
|
||||||
label: impl Into<String>,
|
label: impl Into<String>,
|
||||||
target: TextRange,
|
target: TextRange,
|
||||||
f: impl FnOnce(&mut AssistBuilder),
|
f: impl FnOnce(&mut AssistBuilder),
|
||||||
|
) -> Option<()> {
|
||||||
|
let mut f = Some(f);
|
||||||
|
self.add_impl(Some(group), id, label.into(), target, &mut |it| f.take().unwrap()(it))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_impl(
|
||||||
|
&mut self,
|
||||||
|
group: Option<&GroupLabel>,
|
||||||
|
id: AssistId,
|
||||||
|
label: String,
|
||||||
|
target: TextRange,
|
||||||
|
f: &mut dyn FnMut(&mut AssistBuilder),
|
||||||
) -> Option<()> {
|
) -> Option<()> {
|
||||||
if !self.is_allowed(&id) {
|
if !self.is_allowed(&id) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let label = Label::new(label.into());
|
|
||||||
let assist = Assist { id, label, group: Some(group.clone()), target, source_change: None };
|
|
||||||
self.add_impl(assist, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn add_impl(&mut self, mut assist: Assist, f: impl FnOnce(&mut AssistBuilder)) -> Option<()> {
|
let source_change = if self.resolve.should_resolve(&id) {
|
||||||
let source_change = if self.resolve.should_resolve(&assist.id) {
|
|
||||||
let mut builder = AssistBuilder::new(self.file);
|
let mut builder = AssistBuilder::new(self.file);
|
||||||
f(&mut builder);
|
f(&mut builder);
|
||||||
Some(builder.finish())
|
Some(builder.finish())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
assist.source_change = source_change;
|
|
||||||
|
|
||||||
self.buf.push(assist);
|
let label = Label::new(label.into());
|
||||||
|
let group = group.cloned();
|
||||||
|
self.buf.push(Assist { id, label, group, target, source_change });
|
||||||
Some(())
|
Some(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,7 @@ impl From<Label> for String {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Label {
|
impl Label {
|
||||||
pub fn new(label: impl Into<String>) -> Label {
|
pub fn new(label: String) -> Label {
|
||||||
let label = label.into();
|
|
||||||
assert!(label.starts_with(char::is_uppercase) && !label.ends_with('.'));
|
assert!(label.starts_with(char::is_uppercase) && !label.ends_with('.'));
|
||||||
Label(label)
|
Label(label)
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,7 +222,7 @@ fn unresolved_fix(id: &'static str, label: &str, target: TextRange) -> Assist {
|
||||||
assert!(!id.contains(' '));
|
assert!(!id.contains(' '));
|
||||||
Assist {
|
Assist {
|
||||||
id: AssistId(id, AssistKind::QuickFix),
|
id: AssistId(id, AssistKind::QuickFix),
|
||||||
label: Label::new(label),
|
label: Label::new(label.to_string()),
|
||||||
group: None,
|
group: None,
|
||||||
target,
|
target,
|
||||||
source_change: None,
|
source_change: None,
|
||||||
|
|
|
@ -99,7 +99,7 @@ mod tests {
|
||||||
};
|
};
|
||||||
|
|
||||||
let json = serde_json::to_string(&task).unwrap();
|
let json = serde_json::to_string(&task).unwrap();
|
||||||
println!("{}", json);
|
// println!("{}", json);
|
||||||
let back: ExpansionTask = serde_json::from_str(&json).unwrap();
|
let back: ExpansionTask = serde_json::from_str(&json).unwrap();
|
||||||
|
|
||||||
assert_eq!(tt, back.macro_body.to_subtree());
|
assert_eq!(tt, back.macro_body.to_subtree());
|
||||||
|
|
Loading…
Reference in a new issue