From 22949dab267bf7b8b3da73fe7745a12daca21a52 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 7 Nov 2018 18:42:30 +0300 Subject: rename module source --- crates/ra_analysis/src/completion.rs | 9 ++++--- crates/ra_analysis/src/descriptors/module/imp.rs | 16 ++++++------ crates/ra_analysis/src/descriptors/module/mod.rs | 31 ++++++++++++------------ crates/ra_analysis/src/imp.rs | 8 +++--- 4 files changed, 32 insertions(+), 32 deletions(-) (limited to 'crates/ra_analysis') diff --git a/crates/ra_analysis/src/completion.rs b/crates/ra_analysis/src/completion.rs index ea15f239c..6fd30aaee 100644 --- a/crates/ra_analysis/src/completion.rs +++ b/crates/ra_analysis/src/completion.rs @@ -34,10 +34,11 @@ pub(crate) fn resolve_based_completion( let source_root_id = db.file_source_root(position.file_id); let file = db.file_syntax(position.file_id); let module_tree = db.module_tree(source_root_id)?; - let module_id = match module_tree.any_module_for_source(ModuleSource::File(position.file_id)) { - None => return Ok(None), - Some(it) => it, - }; + let module_id = + match module_tree.any_module_for_source(ModuleSource::SourceFile(position.file_id)) { + None => return Ok(None), + Some(it) => it, + }; let file = { let edit = AtomEdit::insert(position.offset, "intellijRulezz".to_string()); file.reparse(&edit) diff --git a/crates/ra_analysis/src/descriptors/module/imp.rs b/crates/ra_analysis/src/descriptors/module/imp.rs index b5c232ea4..ade96ddc0 100644 --- a/crates/ra_analysis/src/descriptors/module/imp.rs +++ b/crates/ra_analysis/src/descriptors/module/imp.rs @@ -41,8 +41,8 @@ pub(crate) fn submodules( db::check_canceled(db)?; let file_id = source.file_id(); let submodules = match source.resolve(db) { - ModuleSourceNode::Root(it) => collect_submodules(file_id, it.borrowed()), - ModuleSourceNode::Inline(it) => it + ModuleSourceNode::SourceFile(it) => collect_submodules(file_id, it.borrowed()), + ModuleSourceNode::Module(it) => it .borrowed() .item_list() .map(|it| collect_submodules(file_id, it)) @@ -89,8 +89,8 @@ pub(crate) fn module_scope( let tree = db.module_tree(source_root_id)?; let source = module_id.source(&tree).resolve(db); let res = match source { - ModuleSourceNode::Root(root) => ModuleScope::new(root.borrowed().items()), - ModuleSourceNode::Inline(inline) => match inline.borrowed().item_list() { + ModuleSourceNode::SourceFile(it) => ModuleScope::new(it.borrowed().items()), + ModuleSourceNode::Module(it) => match it.borrowed().item_list() { Some(items) => ModuleScope::new(items.items()), None => ModuleScope::new(std::iter::empty()), }, @@ -121,7 +121,7 @@ fn create_module_tree<'a>( let source_root = db.source_root(source_root); for &file_id in source_root.files.iter() { - let source = ModuleSource::File(file_id); + let source = ModuleSource::SourceFile(file_id); if visited.contains(&source) { continue; // TODO: use explicit crate_roots here } @@ -181,7 +181,7 @@ fn build_subtree( visited, roots, Some(link), - ModuleSource::File(file_id), + ModuleSource::SourceFile(file_id), ), }) .collect::>>()?; @@ -213,8 +213,8 @@ fn resolve_submodule( file_resolver: &FileResolverImp, ) -> (Vec, Option) { let file_id = match source { - ModuleSource::File(it) => it, - ModuleSource::Inline(..) => { + ModuleSource::SourceFile(it) => it, + ModuleSource::Module(..) => { // TODO return (Vec::new(), None); } diff --git a/crates/ra_analysis/src/descriptors/module/mod.rs b/crates/ra_analysis/src/descriptors/module/mod.rs index 5301f44ab..58d6abed3 100644 --- a/crates/ra_analysis/src/descriptors/module/mod.rs +++ b/crates/ra_analysis/src/descriptors/module/mod.rs @@ -41,19 +41,18 @@ impl ModuleTree { /// `ModuleSource` is the syntax tree element that produced this module: /// either a file, or an inlinde module. -/// TODO: we don't produce Inline modules yet #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub(crate) enum ModuleSource { - File(FileId), + SourceFile(FileId), #[allow(dead_code)] - Inline(SyntaxPtr), + Module(SyntaxPtr), } /// An owned syntax node for a module. Unlike `ModuleSource`, /// this holds onto the AST for the whole file. enum ModuleSourceNode { - Root(ast::SourceFileNode), - Inline(ast::ModuleNode), + SourceFile(ast::SourceFileNode), + Module(ast::ModuleNode), } #[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] @@ -135,14 +134,14 @@ impl LinkId { ) -> ast::ModuleNode { let owner = self.owner(tree); match owner.source(tree).resolve(db) { - ModuleSourceNode::Root(root) => { + ModuleSourceNode::SourceFile(root) => { let ast = imp::modules(root.borrowed()) .find(|(name, _)| name == &tree.link(self).name) .unwrap() .1; ast.owned() } - ModuleSourceNode::Inline(it) => it, + ModuleSourceNode::Module(it) => it, } } } @@ -158,34 +157,34 @@ impl ModuleSource { pub(crate) fn new_inline(file_id: FileId, module: ast::Module) -> ModuleSource { assert!(!module.has_semi()); let ptr = SyntaxPtr::new(file_id, module.syntax()); - ModuleSource::Inline(ptr) + ModuleSource::Module(ptr) } pub(crate) fn as_file(self) -> Option { match self { - ModuleSource::File(f) => Some(f), - ModuleSource::Inline(..) => None, + ModuleSource::SourceFile(f) => Some(f), + ModuleSource::Module(..) => None, } } pub(crate) fn file_id(self) -> FileId { match self { - ModuleSource::File(f) => f, - ModuleSource::Inline(ptr) => ptr.file_id(), + ModuleSource::SourceFile(f) => f, + ModuleSource::Module(ptr) => ptr.file_id(), } } fn resolve(self, db: &impl SyntaxDatabase) -> ModuleSourceNode { match self { - ModuleSource::File(file_id) => { + ModuleSource::SourceFile(file_id) => { let syntax = db.file_syntax(file_id); - ModuleSourceNode::Root(syntax.ast().owned()) + ModuleSourceNode::SourceFile(syntax.ast().owned()) } - ModuleSource::Inline(ptr) => { + ModuleSource::Module(ptr) => { let syntax = db.resolve_syntax_ptr(ptr); let syntax = syntax.borrowed(); let module = ast::Module::cast(syntax).unwrap(); - ModuleSourceNode::Inline(module.owned()) + ModuleSourceNode::Module(module.owned()) } } } diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 00c4a08bd..614a6e9be 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -226,7 +226,7 @@ impl AnalysisImpl { let module_source = match find_node_at_offset::(file.syntax(), position.offset) { Some(m) if !m.has_semi() => ModuleSource::new_inline(position.file_id, m), - _ => ModuleSource::File(position.file_id), + _ => ModuleSource::SourceFile(position.file_id), }; let res = module_tree @@ -254,7 +254,7 @@ impl AnalysisImpl { let module_tree = self.module_tree(file_id)?; let crate_graph = self.db.crate_graph(); let res = module_tree - .modules_for_source(ModuleSource::File(file_id)) + .modules_for_source(ModuleSource::SourceFile(file_id)) .into_iter() .map(|it| it.root(&module_tree)) .filter_map(|it| it.source(&module_tree).as_file()) @@ -386,7 +386,7 @@ impl AnalysisImpl { fix: None, }) .collect::>(); - if let Some(m) = module_tree.any_module_for_source(ModuleSource::File(file_id)) { + if let Some(m) = module_tree.any_module_for_source(ModuleSource::SourceFile(file_id)) { for (name_node, problem) in m.problems(&module_tree, &*self.db) { let diag = match problem { Problem::UnresolvedModule { candidate } => { @@ -548,7 +548,7 @@ impl AnalysisImpl { Some(name) => name.text(), None => return Vec::new(), }; - let module_id = match module_tree.any_module_for_source(ModuleSource::File(file_id)) { + let module_id = match module_tree.any_module_for_source(ModuleSource::SourceFile(file_id)) { Some(id) => id, None => return Vec::new(), }; -- cgit v1.2.3