mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
internal: Replace Display impl for Name
This commit is contained in:
parent
2f840c2236
commit
c7ef6c25b7
108 changed files with 1045 additions and 656 deletions
|
@ -29,5 +29,5 @@ fn render(ctx: RenderContext<'_>, const_: hir::Const) -> Option<CompletionItem>
|
|||
}
|
||||
item.insert_text(escaped_name);
|
||||
|
||||
Some(item.build())
|
||||
Some(item.build(ctx.db()))
|
||||
}
|
||||
|
|
|
@ -52,8 +52,13 @@ fn render(
|
|||
|
||||
let (call, escaped_call) = match &func_kind {
|
||||
FuncKind::Method(_, Some(receiver)) => (
|
||||
format!("{}.{}", receiver.unescaped(), name.unescaped()).into(),
|
||||
format!("{receiver}.{name}").into(),
|
||||
format!(
|
||||
"{}.{}",
|
||||
receiver.unescaped().display(ctx.db()),
|
||||
name.unescaped().display(ctx.db())
|
||||
)
|
||||
.into(),
|
||||
format!("{}.{}", receiver.display(ctx.db()), name.display(ctx.db())).into(),
|
||||
),
|
||||
_ => (name.unescaped().to_smol_str(), name.to_smol_str()),
|
||||
};
|
||||
|
|
|
@ -71,8 +71,10 @@ fn render(
|
|||
}
|
||||
None => (name.clone().into(), name.into(), false),
|
||||
};
|
||||
let (qualified_name, escaped_qualified_name) =
|
||||
(qualified_name.unescaped().to_string(), qualified_name.to_string());
|
||||
let (qualified_name, escaped_qualified_name) = (
|
||||
qualified_name.unescaped().display(ctx.db()).to_string(),
|
||||
qualified_name.display(ctx.db()).to_string(),
|
||||
);
|
||||
let snippet_cap = ctx.snippet_cap();
|
||||
|
||||
let mut rendered = match kind {
|
||||
|
@ -98,7 +100,7 @@ fn render(
|
|||
}
|
||||
let label = format_literal_label(&qualified_name, kind, snippet_cap);
|
||||
let lookup = if qualified {
|
||||
format_literal_lookup(&short_qualified_name.to_string(), kind)
|
||||
format_literal_lookup(&short_qualified_name.display(ctx.db()).to_string(), kind)
|
||||
} else {
|
||||
format_literal_lookup(&qualified_name, kind)
|
||||
};
|
||||
|
|
|
@ -57,7 +57,10 @@ pub(crate) fn render_variant_pat(
|
|||
let enum_ty = variant.parent_enum(ctx.db()).ty(ctx.db());
|
||||
|
||||
let (name, escaped_name) = match path {
|
||||
Some(path) => (path.unescaped().to_string().into(), path.to_string().into()),
|
||||
Some(path) => (
|
||||
path.unescaped().display(ctx.db()).to_string().into(),
|
||||
path.display(ctx.db()).to_string().into(),
|
||||
),
|
||||
None => {
|
||||
let name = local_name.unwrap_or_else(|| variant.name(ctx.db()));
|
||||
(name.unescaped().to_smol_str(), name.to_smol_str())
|
||||
|
@ -121,7 +124,7 @@ fn build_completion(
|
|||
Some(snippet_cap) => item.insert_snippet(snippet_cap, pat),
|
||||
None => item.insert_text(pat),
|
||||
};
|
||||
item.build()
|
||||
item.build(ctx.db())
|
||||
}
|
||||
|
||||
fn render_pat(
|
||||
|
@ -172,7 +175,7 @@ fn render_record_as_pat(
|
|||
format!(
|
||||
"{name} {{ {}{} }}",
|
||||
fields.enumerate().format_with(", ", |(idx, field), f| {
|
||||
f(&format_args!("{}${}", field.name(db), idx + 1))
|
||||
f(&format_args!("{}${}", field.name(db).display(db.upcast()), idx + 1))
|
||||
}),
|
||||
if fields_omitted { ", .." } else { "" },
|
||||
name = name
|
||||
|
|
|
@ -53,5 +53,5 @@ fn render(
|
|||
}
|
||||
item.insert_text(escaped_name);
|
||||
|
||||
Some(item.build())
|
||||
Some(item.build(ctx.db()))
|
||||
}
|
||||
|
|
|
@ -21,8 +21,10 @@ pub(crate) fn render_union_literal(
|
|||
let name = local_name.unwrap_or_else(|| un.name(ctx.db()));
|
||||
|
||||
let (qualified_name, escaped_qualified_name) = match path {
|
||||
Some(p) => (p.unescaped().to_string(), p.to_string()),
|
||||
None => (name.unescaped().to_string(), name.to_string()),
|
||||
Some(p) => (p.unescaped().display(ctx.db()).to_string(), p.display(ctx.db()).to_string()),
|
||||
None => {
|
||||
(name.unescaped().display(ctx.db()).to_string(), name.display(ctx.db()).to_string())
|
||||
}
|
||||
};
|
||||
let label = format_literal_label(&name.to_smol_str(), StructKind::Record, ctx.snippet_cap());
|
||||
let lookup = format_literal_lookup(&name.to_smol_str(), StructKind::Record);
|
||||
|
@ -51,9 +53,9 @@ pub(crate) fn render_union_literal(
|
|||
format!(
|
||||
"{} {{ {} }}",
|
||||
escaped_qualified_name,
|
||||
fields
|
||||
.iter()
|
||||
.format_with(", ", |field, f| { f(&format_args!("{}: ()", field.name(ctx.db()))) })
|
||||
fields.iter().format_with(", ", |field, f| {
|
||||
f(&format_args!("{}: ()", field.name(ctx.db()).display(ctx.db())))
|
||||
})
|
||||
)
|
||||
};
|
||||
|
||||
|
@ -61,7 +63,11 @@ pub(crate) fn render_union_literal(
|
|||
"{} {{ {}{} }}",
|
||||
qualified_name,
|
||||
fields.iter().format_with(", ", |field, f| {
|
||||
f(&format_args!("{}: {}", field.name(ctx.db()), field.ty(ctx.db()).display(ctx.db())))
|
||||
f(&format_args!(
|
||||
"{}: {}",
|
||||
field.name(ctx.db()).display(ctx.db()),
|
||||
field.ty(ctx.db()).display(ctx.db())
|
||||
))
|
||||
}),
|
||||
if fields_omitted { ", .." } else { "" }
|
||||
);
|
||||
|
@ -76,5 +82,5 @@ pub(crate) fn render_union_literal(
|
|||
None => item.insert_text(literal),
|
||||
};
|
||||
|
||||
Some(item.build())
|
||||
Some(item.build(ctx.db()))
|
||||
}
|
||||
|
|
|
@ -27,14 +27,14 @@ pub(crate) fn render_record_lit(
|
|||
}
|
||||
let completions = fields.iter().enumerate().format_with(", ", |(idx, field), f| {
|
||||
if snippet_cap.is_some() {
|
||||
f(&format_args!("{}: ${{{}:()}}", field.name(db), idx + 1))
|
||||
f(&format_args!("{}: ${{{}:()}}", field.name(db).display(db.upcast()), idx + 1))
|
||||
} else {
|
||||
f(&format_args!("{}: ()", field.name(db)))
|
||||
f(&format_args!("{}: ()", field.name(db).display(db.upcast())))
|
||||
}
|
||||
});
|
||||
|
||||
let types = fields.iter().format_with(", ", |field, f| {
|
||||
f(&format_args!("{}: {}", field.name(db), field.ty(db).display(db)))
|
||||
f(&format_args!("{}: {}", field.name(db).display(db.upcast()), field.ty(db).display(db)))
|
||||
});
|
||||
|
||||
RenderedLiteral {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue