mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
Add TypeAliasRender
This commit is contained in:
parent
944ccf6075
commit
15b16917fc
4 changed files with 54 additions and 19 deletions
|
@ -37,8 +37,7 @@ impl<'a> ConstRender<'a> {
|
|||
}
|
||||
|
||||
fn name(&self) -> Option<String> {
|
||||
let ast_node = self.const_.source(self.ctx.db()).value;
|
||||
ast_node.name().map(|name| name.text().to_string())
|
||||
self.ast_node.name().map(|name| name.text().to_string())
|
||||
}
|
||||
|
||||
fn detail(&self) -> String {
|
||||
|
|
46
crates/completion/src/render/type_alias.rs
Normal file
46
crates/completion/src/render/type_alias.rs
Normal file
|
@ -0,0 +1,46 @@
|
|||
use hir::HasSource;
|
||||
use syntax::{
|
||||
ast::{NameOwner, TypeAlias},
|
||||
display::type_label,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
item::{CompletionItem, CompletionItemKind, CompletionKind},
|
||||
render::RenderContext,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct TypeAliasRender<'a> {
|
||||
ctx: RenderContext<'a>,
|
||||
type_alias: hir::TypeAlias,
|
||||
ast_node: TypeAlias,
|
||||
}
|
||||
|
||||
impl<'a> TypeAliasRender<'a> {
|
||||
pub(crate) fn new(ctx: RenderContext<'a>, type_alias: hir::TypeAlias) -> TypeAliasRender<'a> {
|
||||
let ast_node = type_alias.source(ctx.db()).value;
|
||||
TypeAliasRender { ctx, type_alias, ast_node }
|
||||
}
|
||||
|
||||
pub(crate) fn render(self) -> Option<CompletionItem> {
|
||||
let name = self.name()?;
|
||||
let detail = self.detail();
|
||||
|
||||
let item = CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), name)
|
||||
.kind(CompletionItemKind::TypeAlias)
|
||||
.set_documentation(self.ctx.docs(self.type_alias))
|
||||
.set_deprecated(self.ctx.is_deprecated(self.type_alias))
|
||||
.detail(detail)
|
||||
.build();
|
||||
|
||||
Some(item)
|
||||
}
|
||||
|
||||
fn name(&self) -> Option<String> {
|
||||
self.ast_node.name().map(|name| name.text().to_string())
|
||||
}
|
||||
|
||||
fn detail(&self) -> String {
|
||||
type_label(&self.ast_node)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue