mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
introduce completion presentation
This module should remove completion rendering boilerplate from the "brains" of completion engine.
This commit is contained in:
parent
67528c4b39
commit
d0a261468e
5 changed files with 42 additions and 33 deletions
33
crates/ra_ide_api/src/completion/presentation.rs
Normal file
33
crates/ra_ide_api/src/completion/presentation.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
//! This modules takes care of rendering various defenitions as completion items.
|
||||
use hir::Docs;
|
||||
|
||||
use crate::completion::{Completions, CompletionKind, CompletionItemKind, CompletionContext, CompletionItem};
|
||||
|
||||
impl Completions {
|
||||
pub(crate) fn add_field(
|
||||
&mut self,
|
||||
kind: CompletionKind,
|
||||
ctx: &CompletionContext,
|
||||
field: hir::StructField,
|
||||
substs: &hir::Substs,
|
||||
) {
|
||||
CompletionItem::new(kind, ctx.source_range(), field.name(ctx.db).to_string())
|
||||
.kind(CompletionItemKind::Field)
|
||||
.detail(field.ty(ctx.db).subst(substs).to_string())
|
||||
.set_documentation(field.docs(ctx.db))
|
||||
.add_to(self);
|
||||
}
|
||||
|
||||
pub(crate) fn add_pos_field(
|
||||
&mut self,
|
||||
kind: CompletionKind,
|
||||
ctx: &CompletionContext,
|
||||
field: usize,
|
||||
ty: &hir::Ty,
|
||||
) {
|
||||
CompletionItem::new(kind, ctx.source_range(), field.to_string())
|
||||
.kind(CompletionItemKind::Field)
|
||||
.detail(ty.to_string())
|
||||
.add_to(self);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue