aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/from_source.rs5
-rw-r--r--crates/ra_hir/src/source_binder.rs15
-rw-r--r--crates/ra_hir_def/src/lib.rs11
-rw-r--r--crates/ra_hir_expand/src/lib.rs4
-rw-r--r--crates/ra_ide_api/src/references/classify.rs2
-rw-r--r--crates/ra_ide_api/src/runnables.rs6
6 files changed, 22 insertions, 21 deletions
diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs
index ec56dfa6a..79152a57c 100644
--- a/crates/ra_hir/src/from_source.rs
+++ b/crates/ra_hir/src/from_source.rs
@@ -196,9 +196,8 @@ where
196 N: AstNode, 196 N: AstNode,
197 DEF: AstItemDef<N>, 197 DEF: AstItemDef<N>,
198{ 198{
199 let module_src = 199 let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax()));
200 crate::ModuleSource::from_child_node(db, src.file_id.original_file(db), &src.ast.syntax()); 200 let module = Module::from_definition(db, Source::new(src.file_id, module_src))?;
201 let module = Module::from_definition(db, Source { file_id: src.file_id, ast: module_src })?;
202 let ctx = LocationCtx::new(db, module.id, src.file_id); 201 let ctx = LocationCtx::new(db, module.id, src.file_id);
203 Some(DEF::from_ast(ctx, &src.ast)) 202 Some(DEF::from_ast(ctx, &src.ast))
204} 203}
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 662d3f880..f08827ed3 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -56,7 +56,7 @@ fn try_get_resolver_for_node(
56 }, 56 },
57 _ => { 57 _ => {
58 if node.kind() == FN_DEF || node.kind() == CONST_DEF || node.kind() == STATIC_DEF { 58 if node.kind() == FN_DEF || node.kind() == CONST_DEF || node.kind() == STATIC_DEF {
59 Some(def_with_body_from_child_node(db, file_id, node)?.resolver(db)) 59 Some(def_with_body_from_child_node(db, Source::new(file_id.into(), node))?.resolver(db))
60 } else { 60 } else {
61 // FIXME add missing cases 61 // FIXME add missing cases
62 None 62 None
@@ -68,14 +68,13 @@ fn try_get_resolver_for_node(
68 68
69fn def_with_body_from_child_node( 69fn def_with_body_from_child_node(
70 db: &impl HirDatabase, 70 db: &impl HirDatabase,
71 file_id: FileId, 71 child: Source<&SyntaxNode>,
72 node: &SyntaxNode,
73) -> Option<DefWithBody> { 72) -> Option<DefWithBody> {
74 let src = crate::ModuleSource::from_child_node(db, file_id, node); 73 let module_source = crate::ModuleSource::from_child_node(db, child);
75 let module = Module::from_definition(db, crate::Source { file_id: file_id.into(), ast: src })?; 74 let module = Module::from_definition(db, Source::new(child.file_id, module_source))?;
76 let ctx = LocationCtx::new(db, module.id, file_id.into()); 75 let ctx = LocationCtx::new(db, module.id, child.file_id);
77 76
78 node.ancestors().find_map(|node| { 77 child.ast.ancestors().find_map(|node| {
79 match_ast! { 78 match_ast! {
80 match node { 79 match node {
81 ast::FnDef(def) => { Some(Function {id: ctx.to_def(&def) }.into()) }, 80 ast::FnDef(def) => { Some(Function {id: ctx.to_def(&def) }.into()) },
@@ -142,7 +141,7 @@ impl SourceAnalyzer {
142 node: &SyntaxNode, 141 node: &SyntaxNode,
143 offset: Option<TextUnit>, 142 offset: Option<TextUnit>,
144 ) -> SourceAnalyzer { 143 ) -> SourceAnalyzer {
145 let def_with_body = def_with_body_from_child_node(db, file_id, node); 144 let def_with_body = def_with_body_from_child_node(db, Source::new(file_id.into(), node));
146 if let Some(def) = def_with_body { 145 if let Some(def) = def_with_body {
147 let source_map = def.body_source_map(db); 146 let source_map = def.body_source_map(db);
148 let scopes = def.expr_scopes(db); 147 let scopes = def.expr_scopes(db);
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index 0a59c4ad7..a240a10b8 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -78,14 +78,13 @@ impl ModuleSource {
78 } 78 }
79 } 79 }
80 80
81 pub fn from_child_node( 81 pub fn from_child_node(db: &impl db::DefDatabase2, child: Source<&SyntaxNode>) -> ModuleSource {
82 db: &impl db::DefDatabase2, 82 if let Some(m) =
83 file_id: FileId, 83 child.ast.ancestors().filter_map(ast::Module::cast).find(|it| !it.has_semi())
84 child: &SyntaxNode, 84 {
85 ) -> ModuleSource {
86 if let Some(m) = child.ancestors().filter_map(ast::Module::cast).find(|it| !it.has_semi()) {
87 ModuleSource::Module(m) 85 ModuleSource::Module(m)
88 } else { 86 } else {
87 let file_id = child.file_id.original_file(db);
89 let source_file = db.parse(file_id).tree(); 88 let source_file = db.parse(file_id).tree();
90 ModuleSource::SourceFile(source_file) 89 ModuleSource::SourceFile(source_file)
91 } 90 }
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs
index 930789b0f..437d73e94 100644
--- a/crates/ra_hir_expand/src/lib.rs
+++ b/crates/ra_hir_expand/src/lib.rs
@@ -230,6 +230,10 @@ pub struct Source<T> {
230} 230}
231 231
232impl<T> Source<T> { 232impl<T> Source<T> {
233 pub fn new(file_id: HirFileId, ast: T) -> Source<T> {
234 Source { file_id, ast }
235 }
236
233 pub fn map<F: FnOnce(T) -> U, U>(self, f: F) -> Source<U> { 237 pub fn map<F: FnOnce(T) -> U, U>(self, f: F) -> Source<U> {
234 Source { file_id: self.file_id, ast: f(self.ast) } 238 Source { file_id: self.file_id, ast: f(self.ast) }
235 } 239 }
diff --git a/crates/ra_ide_api/src/references/classify.rs b/crates/ra_ide_api/src/references/classify.rs
index 00690e449..b5e35e29f 100644
--- a/crates/ra_ide_api/src/references/classify.rs
+++ b/crates/ra_ide_api/src/references/classify.rs
@@ -144,8 +144,8 @@ pub(crate) fn classify_name_ref(
144 } 144 }
145 } 145 }
146 146
147 let ast = ModuleSource::from_child_node(db, file_id, &parent);
148 let file_id = file_id.into(); 147 let file_id = file_id.into();
148 let ast = ModuleSource::from_child_node(db, Source::new(file_id, &parent));
149 // FIXME: find correct container and visibility for each case 149 // FIXME: find correct container and visibility for each case
150 let container = Module::from_definition(db, Source { file_id, ast })?; 150 let container = Module::from_definition(db, Source { file_id, ast })?;
151 let visibility = None; 151 let visibility = None;
diff --git a/crates/ra_ide_api/src/runnables.rs b/crates/ra_ide_api/src/runnables.rs
index 366ac8048..8039a5164 100644
--- a/crates/ra_ide_api/src/runnables.rs
+++ b/crates/ra_ide_api/src/runnables.rs
@@ -1,5 +1,6 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use hir::Source;
3use itertools::Itertools; 4use itertools::Itertools;
4use ra_db::SourceDatabase; 5use ra_db::SourceDatabase;
5use ra_syntax::{ 6use ra_syntax::{
@@ -65,9 +66,8 @@ fn runnable_mod(db: &RootDatabase, file_id: FileId, module: ast::Module) -> Opti
65 return None; 66 return None;
66 } 67 }
67 let range = module.syntax().text_range(); 68 let range = module.syntax().text_range();
68 let src = hir::ModuleSource::from_child_node(db, file_id, &module.syntax()); 69 let src = hir::ModuleSource::from_child_node(db, Source::new(file_id.into(), &module.syntax()));
69 let module = 70 let module = hir::Module::from_definition(db, Source::new(file_id.into(), src))?;
70 hir::Module::from_definition(db, hir::Source { file_id: file_id.into(), ast: src })?;
71 71
72 let path = module.path_to_root(db).into_iter().rev().filter_map(|it| it.name(db)).join("::"); 72 let path = module.path_to_root(db).into_iter().rev().filter_map(|it| it.name(db)).join("::");
73 Some(Runnable { range, kind: RunnableKind::TestMod { path } }) 73 Some(Runnable { range, kind: RunnableKind::TestMod { path } })