mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
Simplify const rendering, remove constructor structs
This commit is contained in:
parent
e99ed3e407
commit
2b60d80eaf
1 changed files with 16 additions and 37 deletions
|
@ -2,53 +2,32 @@
|
||||||
|
|
||||||
use hir::{AsAssocItem, HasSource};
|
use hir::{AsAssocItem, HasSource};
|
||||||
use ide_db::SymbolKind;
|
use ide_db::SymbolKind;
|
||||||
use syntax::{ast::Const, display::const_label};
|
use syntax::display::const_label;
|
||||||
|
|
||||||
use crate::{item::CompletionItem, render::RenderContext};
|
use crate::{item::CompletionItem, render::RenderContext};
|
||||||
|
|
||||||
pub(crate) fn render_const(ctx: RenderContext<'_>, const_: hir::Const) -> Option<CompletionItem> {
|
pub(crate) fn render_const(ctx: RenderContext<'_>, const_: hir::Const) -> Option<CompletionItem> {
|
||||||
let _p = profile::span("render_const");
|
let _p = profile::span("render_const");
|
||||||
ConstRender::new(ctx, const_)?.render()
|
render(ctx, const_)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
fn render(ctx: RenderContext<'_>, const_: hir::Const) -> Option<CompletionItem> {
|
||||||
struct ConstRender<'a> {
|
let db = ctx.db();
|
||||||
ctx: RenderContext<'a>,
|
let name = const_.name(db)?.to_smol_str();
|
||||||
const_: hir::Const,
|
// FIXME: This is parsing files!
|
||||||
ast_node: Const,
|
let detail = const_label(&const_.source(db)?.value);
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> ConstRender<'a> {
|
let mut item = CompletionItem::new(SymbolKind::Const, ctx.source_range(), name.clone());
|
||||||
fn new(ctx: RenderContext<'a>, const_: hir::Const) -> Option<ConstRender<'a>> {
|
item.set_documentation(ctx.docs(const_))
|
||||||
let ast_node = const_.source(ctx.db())?.value;
|
.set_deprecated(ctx.is_deprecated(const_) || ctx.is_deprecated_assoc_item(const_))
|
||||||
Some(ConstRender { ctx, const_, ast_node })
|
.detail(detail);
|
||||||
}
|
|
||||||
|
|
||||||
fn render(self) -> Option<CompletionItem> {
|
if let Some(actm) = const_.as_assoc_item(db) {
|
||||||
let name = self.const_.name(self.ctx.db())?.to_smol_str();
|
if let Some(trt) = actm.containing_trait_or_trait_impl(db) {
|
||||||
let detail = self.detail();
|
item.trait_name(trt.name(db).to_smol_str());
|
||||||
|
item.insert_text(name);
|
||||||
let mut item =
|
|
||||||
CompletionItem::new(SymbolKind::Const, self.ctx.source_range(), name.clone());
|
|
||||||
item.set_documentation(self.ctx.docs(self.const_))
|
|
||||||
.set_deprecated(
|
|
||||||
self.ctx.is_deprecated(self.const_)
|
|
||||||
|| self.ctx.is_deprecated_assoc_item(self.const_),
|
|
||||||
)
|
|
||||||
.detail(detail);
|
|
||||||
|
|
||||||
let db = self.ctx.db();
|
|
||||||
if let Some(actm) = self.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());
|
|
||||||
item.insert_text(name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(item.build())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn detail(&self) -> String {
|
Some(item.build())
|
||||||
const_label(&self.ast_node)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue