aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/db.rs
blob: f6027013f2a8e451ec978a4dc424ebb89c2b6fe5 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//! Defines database & queries for name resolution.
use std::sync::Arc;

use hir_expand::{db::AstDatabase, HirFileId};
use ra_db::{salsa, SourceDatabase};
use ra_syntax::ast;

use crate::{
    adt::{EnumData, StructData},
    nameres::raw::{ImportSourceMap, RawItems},
    EnumId, StructId,
};

#[salsa::query_group(InternDatabaseStorage)]
pub trait InternDatabase: SourceDatabase {
    #[salsa::interned]
    fn intern_function(&self, loc: crate::ItemLoc<ast::FnDef>) -> crate::FunctionId;
    #[salsa::interned]
    fn intern_struct(&self, loc: crate::ItemLoc<ast::StructDef>) -> crate::StructId;
    #[salsa::interned]
    fn intern_union(&self, loc: crate::ItemLoc<ast::StructDef>) -> crate::UnionId;
    #[salsa::interned]
    fn intern_enum(&self, loc: crate::ItemLoc<ast::EnumDef>) -> crate::EnumId;
    #[salsa::interned]
    fn intern_const(&self, loc: crate::ItemLoc<ast::ConstDef>) -> crate::ConstId;
    #[salsa::interned]
    fn intern_static(&self, loc: crate::ItemLoc<ast::StaticDef>) -> crate::StaticId;
    #[salsa::interned]
    fn intern_trait(&self, loc: crate::ItemLoc<ast::TraitDef>) -> crate::TraitId;
    #[salsa::interned]
    fn intern_type_alias(&self, loc: crate::ItemLoc<ast::TypeAliasDef>) -> crate::TypeAliasId;
}

#[salsa::query_group(DefDatabase2Storage)]
pub trait DefDatabase2: InternDatabase + AstDatabase {
    #[salsa::invoke(RawItems::raw_items_with_source_map_query)]
    fn raw_items_with_source_map(
        &self,
        file_id: HirFileId,
    ) -> (Arc<RawItems>, Arc<ImportSourceMap>);

    #[salsa::invoke(RawItems::raw_items_query)]
    fn raw_items(&self, file_id: HirFileId) -> Arc<RawItems>;

    #[salsa::invoke(StructData::struct_data_query)]
    fn struct_data(&self, s: StructId) -> Arc<StructData>;

    #[salsa::invoke(EnumData::enum_data_query)]
    fn enum_data(&self, e: EnumId) -> Arc<EnumData>;
}