aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/query_definitions.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/query_definitions.rs')
-rw-r--r--crates/ra_hir/src/query_definitions.rs32
1 files changed, 18 insertions, 14 deletions
diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs
index 8f2c40669..380ea5410 100644
--- a/crates/ra_hir/src/query_definitions.rs
+++ b/crates/ra_hir/src/query_definitions.rs
@@ -5,7 +5,7 @@ use std::{
5 5
6use rustc_hash::FxHashMap; 6use rustc_hash::FxHashMap;
7use ra_syntax::{ 7use ra_syntax::{
8 AstNode, SyntaxNode, 8 AstNode, SyntaxNode, TreePtr,
9 ast::{self, ModuleItemOwner} 9 ast::{self, ModuleItemOwner}
10}; 10};
11use ra_db::{SourceRootId, Cancelable,}; 11use ra_db::{SourceRootId, Cancelable,};
@@ -31,30 +31,34 @@ pub(super) fn struct_data(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Ar
31 assert!(def_loc.kind == DefKind::Struct); 31 assert!(def_loc.kind == DefKind::Struct);
32 let syntax = db.file_item(def_loc.source_item_id); 32 let syntax = db.file_item(def_loc.source_item_id);
33 let struct_def = 33 let struct_def =
34 ast::StructDef::cast(syntax.borrowed()).expect("struct def should point to StructDef node"); 34 ast::StructDef::cast(&syntax).expect("struct def should point to StructDef node");
35 Ok(Arc::new(StructData::new(struct_def.borrowed()))) 35 Ok(Arc::new(StructData::new(struct_def)))
36} 36}
37 37
38pub(super) fn enum_data(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<EnumData>> { 38pub(super) fn enum_data(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<EnumData>> {
39 let def_loc = def_id.loc(db); 39 let def_loc = def_id.loc(db);
40 assert!(def_loc.kind == DefKind::Enum); 40 assert!(def_loc.kind == DefKind::Enum);
41 let syntax = db.file_item(def_loc.source_item_id); 41 let syntax = db.file_item(def_loc.source_item_id);
42 let enum_def = 42 let enum_def = ast::EnumDef::cast(&syntax).expect("enum def should point to EnumDef node");
43 ast::EnumDef::cast(syntax.borrowed()).expect("enum def should point to EnumDef node"); 43 Ok(Arc::new(EnumData::new(enum_def)))
44 Ok(Arc::new(EnumData::new(enum_def.borrowed())))
45} 44}
46 45
47pub(super) fn file_items(db: &impl HirDatabase, file_id: HirFileId) -> Arc<SourceFileItems> { 46pub(super) fn file_items(db: &impl HirDatabase, file_id: HirFileId) -> Arc<SourceFileItems> {
48 let source_file = db.hir_source_file(file_id); 47 let source_file = db.hir_source_file(file_id);
49 let source_file = source_file.borrowed(); 48 let res = SourceFileItems::new(file_id, &source_file);
50 let res = SourceFileItems::new(file_id, source_file);
51 Arc::new(res) 49 Arc::new(res)
52} 50}
53 51
54pub(super) fn file_item(db: &impl HirDatabase, source_item_id: SourceItemId) -> SyntaxNode { 52pub(super) fn file_item(
53 db: &impl HirDatabase,
54 source_item_id: SourceItemId,
55) -> TreePtr<SyntaxNode> {
55 match source_item_id.item_id { 56 match source_item_id.item_id {
56 Some(id) => db.file_items(source_item_id.file_id)[id].clone(), 57 Some(id) => db.file_items(source_item_id.file_id)[id].to_owned(),
57 None => db.hir_source_file(source_item_id.file_id).syntax().owned(), 58 None => db
59 .hir_source_file(source_item_id.file_id)
60 .syntax()
61 .to_owned(),
58 } 62 }
59} 63}
60 64
@@ -88,7 +92,7 @@ pub(super) fn input_module_items(
88 let file_id = HirFileId::from(id); 92 let file_id = HirFileId::from(id);
89 let file_items = db.file_items(file_id); 93 let file_items = db.file_items(file_id);
90 //FIXME: expand recursively 94 //FIXME: expand recursively
91 for item in db.hir_source_file(file_id).borrowed().items() { 95 for item in db.hir_source_file(file_id).items() {
92 acc.add_item(file_id, &file_items, item); 96 acc.add_item(file_id, &file_items, item);
93 } 97 }
94 } 98 }
@@ -98,9 +102,9 @@ pub(super) fn input_module_items(
98 102
99 let mut res = InputModuleItems::default(); 103 let mut res = InputModuleItems::default();
100 match source { 104 match source {
101 ModuleSource::SourceFile(it) => fill(&mut res, &mut it.borrowed().items_with_macros()), 105 ModuleSource::SourceFile(it) => fill(&mut res, &mut it.items_with_macros()),
102 ModuleSource::Module(it) => { 106 ModuleSource::Module(it) => {
103 if let Some(item_list) = it.borrowed().item_list() { 107 if let Some(item_list) = it.item_list() {
104 fill(&mut res, &mut item_list.items_with_macros()) 108 fill(&mut res, &mut item_list.items_with_macros())
105 } 109 }
106 } 110 }