aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model_impl/konst.rs
blob: ee03e337490fed7b914406061f6ba8bc457c33c1 (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
use std::sync::Arc;

use ra_syntax::ast::{NameOwner};

use crate::{
    Name, AsName, Const, ConstSignature,
    type_ref::{TypeRef},
    PersistentHirDatabase,
};

impl ConstSignature {
    pub(crate) fn const_signature_query(
        db: &impl PersistentHirDatabase,
        konst: Const,
    ) -> Arc<ConstSignature> {
        let (_, node) = konst.source(db);

        let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing);

        let type_ref = TypeRef::from_ast_opt(node.type_ref());

        let sig = ConstSignature { name, type_ref };

        Arc::new(sig)
    }
}