aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src
diff options
context:
space:
mode:
authorice1000 <[email protected]>2019-12-03 20:28:40 +0000
committerice1000 <[email protected]>2019-12-04 23:30:42 +0000
commit5c5f90ba57c83499a44af33bf8b91b24254fb685 (patch)
tree839b5d523978918cde9f6aeceba6f8819214e856 /crates/ra_hir_def/src
parent38853459e3d964cc7f635829cdc66f5faee33d85 (diff)
Confluent `ModuleSource` usage
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r--crates/ra_hir_def/src/nameres.rs18
1 files changed, 5 insertions, 13 deletions
diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs
index feb2a4d32..e356515cb 100644
--- a/crates/ra_hir_def/src/nameres.rs
+++ b/crates/ra_hir_def/src/nameres.rs
@@ -57,7 +57,6 @@ mod tests;
57 57
58use std::sync::Arc; 58use std::sync::Arc;
59 59
60use either::Either;
61use hir_expand::{ 60use hir_expand::{
62 ast_id_map::FileAstId, diagnostics::DiagnosticSink, name::Name, InFile, MacroDefId, 61 ast_id_map::FileAstId, diagnostics::DiagnosticSink, name::Name, InFile, MacroDefId,
63}; 62};
@@ -154,20 +153,16 @@ impl ModuleOrigin {
154 153
155 /// Returns a node which defines this module. 154 /// Returns a node which defines this module.
156 /// That is, a file or a `mod foo {}` with items. 155 /// That is, a file or a `mod foo {}` with items.
157 pub fn definition_source( 156 pub fn definition_source(&self, db: &impl DefDatabase) -> InFile<ModuleSource> {
158 &self,
159 db: &impl DefDatabase,
160 ) -> InFile<Either<ast::SourceFile, ast::Module>> {
161 match self { 157 match self {
162 ModuleOrigin::File(_, file_id) | ModuleOrigin::Root(Some(file_id)) => { 158 ModuleOrigin::File(_, file_id) | ModuleOrigin::Root(Some(file_id)) => {
163 let file_id = *file_id; 159 let file_id = *file_id;
164 let sf = db.parse(file_id).tree(); 160 let sf = db.parse(file_id).tree();
165 return InFile::new(file_id.into(), Either::Left(sf)); 161 return InFile::new(file_id.into(), ModuleSource::SourceFile(sf));
166 } 162 }
167 ModuleOrigin::Root(None) => unreachable!(), 163 ModuleOrigin::Root(None) => unreachable!(),
168 ModuleOrigin::Inline(m) => InFile::new(m.file_id, Either::Right(m.to_node(db))), 164 ModuleOrigin::Inline(m) => InFile::new(m.file_id, ModuleSource::Module(m.to_node(db))),
169 // FIXME: right now it's never constructed, so it's fine to omit 165 ModuleOrigin::Block(b) => InFile::new(b.file_id, ModuleSource::Block(b.to_node(db))),
170 ModuleOrigin::Block(_b) => unimplemented!(),
171 } 166 }
172 } 167 }
173} 168}
@@ -348,10 +343,7 @@ impl CrateDefMap {
348 343
349impl ModuleData { 344impl ModuleData {
350 /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items. 345 /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items.
351 pub fn definition_source( 346 pub fn definition_source(&self, db: &impl DefDatabase) -> InFile<ModuleSource> {
352 &self,
353 db: &impl DefDatabase,
354 ) -> InFile<Either<ast::SourceFile, ast::Module>> {
355 self.origin.definition_source(db) 347 self.origin.definition_source(db)
356 } 348 }
357 349