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

use ra_syntax::{
    SyntaxNode, TreeArc,
};

use crate::{
    SourceFileItems, SourceItemId, HirFileId,
    PersistentHirDatabase,
};

pub(super) fn file_items(
    db: &impl PersistentHirDatabase,
    file_id: HirFileId,
) -> Arc<SourceFileItems> {
    let source_file = db.hir_parse(file_id);
    let res = SourceFileItems::new(file_id, &source_file);
    Arc::new(res)
}

pub(super) fn file_item(
    db: &impl PersistentHirDatabase,
    source_item_id: SourceItemId,
) -> TreeArc<SyntaxNode> {
    let source_file = db.hir_parse(source_item_id.file_id);
    db.file_items(source_item_id.file_id)[source_item_id.item_id].to_node(&source_file).to_owned()
}