aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/completion/presentation.rs
blob: 6b2de56bc0ba876a6dee7b3b3a8cfe31f4cb65de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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);
    }
}