mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 21:35:20 +00:00
Replace a few String instances with SmolStr in completions
This commit is contained in:
parent
7f7a3644b3
commit
60dfe8ceed
4 changed files with 29 additions and 29 deletions
|
@ -1,6 +1,7 @@
|
|||
//! Extensions for `Builder` structure required for item rendering.
|
||||
|
||||
use itertools::Itertools;
|
||||
use syntax::SmolStr;
|
||||
|
||||
use crate::{context::PathKind, item::Builder, patterns::ImmediateLocation, CompletionContext};
|
||||
|
||||
|
@ -56,7 +57,7 @@ impl Builder {
|
|||
pub(super) fn add_call_parens(
|
||||
&mut self,
|
||||
ctx: &CompletionContext,
|
||||
name: String,
|
||||
name: SmolStr,
|
||||
params: Params,
|
||||
) -> &mut Builder {
|
||||
if !self.should_add_parens(ctx) {
|
||||
|
|
|
@ -5,6 +5,7 @@ use std::iter;
|
|||
use hir::{db::HirDatabase, HasAttrs, HirDisplay, StructKind};
|
||||
use ide_db::SymbolKind;
|
||||
use itertools::Itertools;
|
||||
use syntax::SmolStr;
|
||||
|
||||
use crate::{
|
||||
item::{CompletionItem, ImportEdit},
|
||||
|
@ -48,10 +49,10 @@ fn render(
|
|||
false,
|
||||
),
|
||||
};
|
||||
let qualified_name = qualified_name.to_string();
|
||||
let short_qualified_name: SmolStr = short_qualified_name.to_string().into();
|
||||
|
||||
// FIXME: ModPath::to_smol_str()?
|
||||
let mut item =
|
||||
CompletionItem::new(SymbolKind::Variant, ctx.source_range(), qualified_name.to_string());
|
||||
let mut item = CompletionItem::new(SymbolKind::Variant, ctx.source_range(), qualified_name);
|
||||
item.set_documentation(variant.docs(db))
|
||||
.set_deprecated(ctx.is_deprecated(variant))
|
||||
.detail(detail(db, variant, variant_kind));
|
||||
|
@ -60,8 +61,6 @@ fn render(
|
|||
item.add_import(import_to_add);
|
||||
}
|
||||
|
||||
// FIXME: ModPath::to_smol_str()?
|
||||
let short_qualified_name = short_qualified_name.to_string();
|
||||
if variant_kind == hir::StructKind::Tuple {
|
||||
cov_mark::hit!(inserts_parens_for_tuple_enums);
|
||||
let params = Params::Anonymous(variant.fields(db).len());
|
||||
|
|
|
@ -52,10 +52,9 @@ fn render(
|
|||
let name = local_name.unwrap_or_else(|| func.name(db));
|
||||
let params = params(completion, func, &func_type);
|
||||
|
||||
// FIXME: SmolStr?
|
||||
let call = match &func_type {
|
||||
FuncType::Method(Some(receiver)) => format!("{}.{}", receiver, &name),
|
||||
_ => name.to_string(),
|
||||
FuncType::Method(Some(receiver)) => format!("{}.{}", receiver, &name).into(),
|
||||
_ => name.to_smol_str(),
|
||||
};
|
||||
let mut item = CompletionItem::new(
|
||||
if func.self_param(db).is_some() {
|
||||
|
@ -66,23 +65,6 @@ fn render(
|
|||
ctx.source_range(),
|
||||
call.clone(),
|
||||
);
|
||||
item.set_documentation(ctx.docs(func))
|
||||
.set_deprecated(ctx.is_deprecated(func) || ctx.is_deprecated_assoc_item(func))
|
||||
.detail(detail(db, func))
|
||||
.add_call_parens(completion, call.clone(), params);
|
||||
|
||||
if import_to_add.is_none() {
|
||||
if let Some(actm) = func.as_assoc_item(db) {
|
||||
if let Some(trt) = actm.containing_trait_or_trait_impl(db) {
|
||||
item.trait_name(trt.name(db).to_smol_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(import_to_add) = import_to_add {
|
||||
item.add_import(import_to_add);
|
||||
}
|
||||
item.lookup_by(name.to_smol_str());
|
||||
|
||||
let ret_type = func.ret_type(db);
|
||||
item.set_relevance(CompletionRelevance {
|
||||
|
@ -100,6 +82,24 @@ fn render(
|
|||
}
|
||||
}
|
||||
|
||||
item.set_documentation(ctx.docs(func))
|
||||
.set_deprecated(ctx.is_deprecated(func) || ctx.is_deprecated_assoc_item(func))
|
||||
.detail(detail(db, func))
|
||||
.add_call_parens(completion, call, params);
|
||||
|
||||
if import_to_add.is_none() {
|
||||
if let Some(actm) = func.as_assoc_item(db) {
|
||||
if let Some(trt) = actm.containing_trait_or_trait_impl(db) {
|
||||
item.trait_name(trt.name(db).to_smol_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(import_to_add) = import_to_add {
|
||||
item.add_import(import_to_add);
|
||||
}
|
||||
item.lookup_by(name.to_smol_str());
|
||||
|
||||
item.build()
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use hir::{AsAssocItem, HirDisplay};
|
||||
use ide_db::SymbolKind;
|
||||
use syntax::SmolStr;
|
||||
|
||||
use crate::{item::CompletionItem, render::RenderContext};
|
||||
|
||||
|
@ -28,11 +29,10 @@ fn render(
|
|||
) -> Option<CompletionItem> {
|
||||
let db = ctx.db();
|
||||
|
||||
// FIXME: smolstr?
|
||||
let name = if with_eq {
|
||||
format!("{} = ", type_alias.name(db))
|
||||
SmolStr::from_iter([&*type_alias.name(db).to_smol_str(), " = "])
|
||||
} else {
|
||||
type_alias.name(db).to_string()
|
||||
type_alias.name(db).to_smol_str()
|
||||
};
|
||||
let detail = type_alias.display(db).to_string();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue