This commit is contained in:
Aleksey Kladov 2020-02-07 15:04:50 +01:00
parent 2d95047f7c
commit 6ac9c4ad6a
2 changed files with 11 additions and 4 deletions

View File

@ -57,7 +57,7 @@ pub(crate) struct AssistCtx<'a> {
should_compute_edit: bool,
}
impl<'a> Clone for AssistCtx<'a> {
impl Clone for AssistCtx<'_> {
fn clone(&self) -> Self {
AssistCtx {
db: self.db,
@ -80,8 +80,7 @@ impl<'a> AssistCtx<'a> {
label: impl Into<String>,
f: impl FnOnce(&mut ActionBuilder),
) -> Option<Assist> {
let label = AssistLabel { label: label.into(), id };
assert!(label.label.chars().nth(0).unwrap().is_uppercase());
let label = AssistLabel::new(label.into(), id);
let assist = if self.should_compute_edit {
let action = {
@ -103,7 +102,7 @@ impl<'a> AssistCtx<'a> {
label: impl Into<String>,
f: impl FnOnce() -> Vec<ActionBuilder>,
) -> Option<Assist> {
let label = AssistLabel { label: label.into(), id };
let label = AssistLabel::new(label.into(), id);
let assist = if self.should_compute_edit {
let actions = f();
assert!(!actions.is_empty(), "Assist cannot have no");

View File

@ -34,6 +34,14 @@ pub struct AssistLabel {
pub id: AssistId,
}
impl AssistLabel {
pub(crate) fn new(label: String, id: AssistId) -> AssistLabel {
// FIXME: make fields private, so that this invariant can't be broken
assert!(label.chars().nth(0).unwrap().is_uppercase());
AssistLabel { label: label.into(), id }
}
}
#[derive(Debug, Clone)]
pub struct AssistAction {
pub label: Option<String>,