mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 15:01:51 +00:00
pass snippet_cap
to format_literal_label
, return early if None
This commit is contained in:
parent
1116cc93ec
commit
694ae77bf6
@ -96,7 +96,7 @@ fn render(
|
||||
if !should_add_parens {
|
||||
kind = StructKind::Unit;
|
||||
}
|
||||
let label = format_literal_label(&qualified_name, kind);
|
||||
let label = format_literal_label(&qualified_name, kind, snippet_cap);
|
||||
let lookup = if qualified {
|
||||
format_literal_lookup(&short_qualified_name.to_string(), kind)
|
||||
} else {
|
||||
|
@ -33,7 +33,7 @@ pub(crate) fn render_struct_pat(
|
||||
let name = local_name.unwrap_or_else(|| strukt.name(ctx.db()));
|
||||
let (name, escaped_name) = (name.unescaped().to_smol_str(), name.to_smol_str());
|
||||
let kind = strukt.kind(ctx.db());
|
||||
let label = format_literal_label(name.as_str(), kind);
|
||||
let label = format_literal_label(name.as_str(), kind, ctx.snippet_cap());
|
||||
let lookup = format_literal_lookup(name.as_str(), kind);
|
||||
let pat = render_pat(&ctx, pattern_ctx, &escaped_name, kind, &visible_fields, fields_omitted)?;
|
||||
|
||||
@ -67,7 +67,7 @@ pub(crate) fn render_variant_pat(
|
||||
}
|
||||
_ => {
|
||||
let kind = variant.kind(ctx.db());
|
||||
let label = format_literal_label(name.as_str(), kind);
|
||||
let label = format_literal_label(name.as_str(), kind, ctx.snippet_cap());
|
||||
let lookup = format_literal_lookup(name.as_str(), kind);
|
||||
let pat = render_pat(
|
||||
&ctx,
|
||||
|
@ -24,7 +24,7 @@ pub(crate) fn render_union_literal(
|
||||
Some(p) => (p.unescaped().to_string(), p.to_string()),
|
||||
None => (name.unescaped().to_string(), name.to_string()),
|
||||
};
|
||||
let label = format_literal_label(&name.to_smol_str(), StructKind::Record);
|
||||
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);
|
||||
let mut item = CompletionItem::new(
|
||||
CompletionItemKind::SymbolKind(SymbolKind::Union),
|
||||
|
@ -90,7 +90,14 @@ pub(crate) fn visible_fields(
|
||||
}
|
||||
|
||||
/// Format a struct, etc. literal option for display in the completions menu.
|
||||
pub(crate) fn format_literal_label(name: &str, kind: StructKind) -> SmolStr {
|
||||
pub(crate) fn format_literal_label(
|
||||
name: &str,
|
||||
kind: StructKind,
|
||||
snippet_cap: Option<SnippetCap>,
|
||||
) -> SmolStr {
|
||||
if snippet_cap.is_none() {
|
||||
return name.into();
|
||||
}
|
||||
match kind {
|
||||
StructKind::Tuple => SmolStr::from_iter([name, "(…)"]),
|
||||
StructKind::Record => SmolStr::from_iter([name, " {…}"]),
|
||||
|
Loading…
Reference in New Issue
Block a user