mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +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.
|
//! Extensions for `Builder` structure required for item rendering.
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
use syntax::SmolStr;
|
||||||
|
|
||||||
use crate::{context::PathKind, item::Builder, patterns::ImmediateLocation, CompletionContext};
|
use crate::{context::PathKind, item::Builder, patterns::ImmediateLocation, CompletionContext};
|
||||||
|
|
||||||
|
@ -56,7 +57,7 @@ impl Builder {
|
||||||
pub(super) fn add_call_parens(
|
pub(super) fn add_call_parens(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &CompletionContext,
|
ctx: &CompletionContext,
|
||||||
name: String,
|
name: SmolStr,
|
||||||
params: Params,
|
params: Params,
|
||||||
) -> &mut Builder {
|
) -> &mut Builder {
|
||||||
if !self.should_add_parens(ctx) {
|
if !self.should_add_parens(ctx) {
|
||||||
|
|
|
@ -5,6 +5,7 @@ use std::iter;
|
||||||
use hir::{db::HirDatabase, HasAttrs, HirDisplay, StructKind};
|
use hir::{db::HirDatabase, HasAttrs, HirDisplay, StructKind};
|
||||||
use ide_db::SymbolKind;
|
use ide_db::SymbolKind;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
use syntax::SmolStr;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
item::{CompletionItem, ImportEdit},
|
item::{CompletionItem, ImportEdit},
|
||||||
|
@ -48,10 +49,10 @@ fn render(
|
||||||
false,
|
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);
|
||||||
let mut item =
|
|
||||||
CompletionItem::new(SymbolKind::Variant, ctx.source_range(), qualified_name.to_string());
|
|
||||||
item.set_documentation(variant.docs(db))
|
item.set_documentation(variant.docs(db))
|
||||||
.set_deprecated(ctx.is_deprecated(variant))
|
.set_deprecated(ctx.is_deprecated(variant))
|
||||||
.detail(detail(db, variant, variant_kind));
|
.detail(detail(db, variant, variant_kind));
|
||||||
|
@ -60,8 +61,6 @@ fn render(
|
||||||
item.add_import(import_to_add);
|
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 {
|
if variant_kind == hir::StructKind::Tuple {
|
||||||
cov_mark::hit!(inserts_parens_for_tuple_enums);
|
cov_mark::hit!(inserts_parens_for_tuple_enums);
|
||||||
let params = Params::Anonymous(variant.fields(db).len());
|
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 name = local_name.unwrap_or_else(|| func.name(db));
|
||||||
let params = params(completion, func, &func_type);
|
let params = params(completion, func, &func_type);
|
||||||
|
|
||||||
// FIXME: SmolStr?
|
|
||||||
let call = match &func_type {
|
let call = match &func_type {
|
||||||
FuncType::Method(Some(receiver)) => format!("{}.{}", receiver, &name),
|
FuncType::Method(Some(receiver)) => format!("{}.{}", receiver, &name).into(),
|
||||||
_ => name.to_string(),
|
_ => name.to_smol_str(),
|
||||||
};
|
};
|
||||||
let mut item = CompletionItem::new(
|
let mut item = CompletionItem::new(
|
||||||
if func.self_param(db).is_some() {
|
if func.self_param(db).is_some() {
|
||||||
|
@ -66,23 +65,6 @@ fn render(
|
||||||
ctx.source_range(),
|
ctx.source_range(),
|
||||||
call.clone(),
|
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);
|
let ret_type = func.ret_type(db);
|
||||||
item.set_relevance(CompletionRelevance {
|
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()
|
item.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
use hir::{AsAssocItem, HirDisplay};
|
use hir::{AsAssocItem, HirDisplay};
|
||||||
use ide_db::SymbolKind;
|
use ide_db::SymbolKind;
|
||||||
|
use syntax::SmolStr;
|
||||||
|
|
||||||
use crate::{item::CompletionItem, render::RenderContext};
|
use crate::{item::CompletionItem, render::RenderContext};
|
||||||
|
|
||||||
|
@ -28,11 +29,10 @@ fn render(
|
||||||
) -> Option<CompletionItem> {
|
) -> Option<CompletionItem> {
|
||||||
let db = ctx.db();
|
let db = ctx.db();
|
||||||
|
|
||||||
// FIXME: smolstr?
|
|
||||||
let name = if with_eq {
|
let name = if with_eq {
|
||||||
format!("{} = ", type_alias.name(db))
|
SmolStr::from_iter([&*type_alias.name(db).to_smol_str(), " = "])
|
||||||
} else {
|
} else {
|
||||||
type_alias.name(db).to_string()
|
type_alias.name(db).to_smol_str()
|
||||||
};
|
};
|
||||||
let detail = type_alias.display(db).to_string();
|
let detail = type_alias.display(db).to_string();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue