rust-analyzer/crates/ide-completion/src/render/const_.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

34 lines
1.1 KiB
Rust
Raw Normal View History

2020-11-01 10:48:42 +00:00
//! Renderer for `const` fields.
use hir::{AsAssocItem, HirDisplay};
use ide_db::SymbolKind;
2020-11-01 09:59:43 +00:00
use crate::{item::CompletionItem, render::RenderContext};
2020-11-01 09:59:43 +00:00
pub(crate) fn render_const(ctx: RenderContext<'_>, const_: hir::Const) -> Option<CompletionItem> {
2021-11-08 18:41:16 +00:00
let _p = profile::span("render_const");
render(ctx, const_)
2020-11-03 07:33:13 +00:00
}
fn render(ctx: RenderContext<'_>, const_: hir::Const) -> Option<CompletionItem> {
let db = ctx.db();
let name = const_.name(db)?;
2022-08-01 06:19:49 +00:00
let (name, escaped_name) = (name.unescaped().to_smol_str(), name.to_smol_str());
let detail = const_.display(db).to_string();
let mut item = CompletionItem::new(SymbolKind::Const, ctx.source_range(), name);
item.set_documentation(ctx.docs(const_))
.set_deprecated(ctx.is_deprecated(const_) || ctx.is_deprecated_assoc_item(const_))
.detail(detail)
.set_relevance(ctx.completion_relevance());
if let Some(actm) = const_.as_assoc_item(db) {
if let Some(trt) = actm.containing_trait_or_trait_impl(db) {
item.trait_name(trt.name(db).to_smol_str());
}
2020-11-01 09:59:43 +00:00
}
item.insert_text(escaped_name);
2020-11-01 09:59:43 +00:00
Some(item.build(ctx.db()))
2020-11-01 09:59:43 +00:00
}