diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-11-01 10:53:17 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-11-01 10:53:17 +0000 |
commit | f6f9a0bf35f073e554a340f04e213867732d81a1 (patch) | |
tree | 9c9cfc3f6868864d7dd1164aaff6b248f81a402b /crates/ra_analysis/src/descriptors/module/scope.rs | |
parent | d685a9b564fe524865cda5713c527aaeb1ca6b1d (diff) | |
parent | f2b654fd443ce1a0a31a9eaf1a1c25e911d0001a (diff) |
Merge #182
182: Module source r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_analysis/src/descriptors/module/scope.rs')
-rw-r--r-- | crates/ra_analysis/src/descriptors/module/scope.rs | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/crates/ra_analysis/src/descriptors/module/scope.rs b/crates/ra_analysis/src/descriptors/module/scope.rs index 681e272c2..215b31f8e 100644 --- a/crates/ra_analysis/src/descriptors/module/scope.rs +++ b/crates/ra_analysis/src/descriptors/module/scope.rs | |||
@@ -1,9 +1,6 @@ | |||
1 | //! Backend for module-level scope resolution & completion | 1 | //! Backend for module-level scope resolution & completion |
2 | 2 | ||
3 | use ra_syntax::{ | 3 | use ra_syntax::{ast, AstNode, SmolStr}; |
4 | ast::{self, ModuleItemOwner}, | ||
5 | AstNode, File, SmolStr, | ||
6 | }; | ||
7 | 4 | ||
8 | use crate::syntax_ptr::LocalSyntaxPtr; | 5 | use crate::syntax_ptr::LocalSyntaxPtr; |
9 | 6 | ||
@@ -28,11 +25,7 @@ enum EntryKind { | |||
28 | } | 25 | } |
29 | 26 | ||
30 | impl ModuleScope { | 27 | impl ModuleScope { |
31 | pub fn new(file: &File) -> ModuleScope { | 28 | pub(crate) fn new<'a>(items: impl Iterator<Item = ast::ModuleItem<'a>>) -> ModuleScope { |
32 | ModuleScope::from_items(file.ast().items()) | ||
33 | } | ||
34 | |||
35 | pub fn from_items<'a>(items: impl Iterator<Item = ast::ModuleItem<'a>>) -> ModuleScope { | ||
36 | let mut entries = Vec::new(); | 29 | let mut entries = Vec::new(); |
37 | for item in items { | 30 | for item in items { |
38 | let entry = match item { | 31 | let entry = match item { |
@@ -102,11 +95,11 @@ fn collect_imports(tree: ast::UseTree, acc: &mut Vec<Entry>) { | |||
102 | #[cfg(test)] | 95 | #[cfg(test)] |
103 | mod tests { | 96 | mod tests { |
104 | use super::*; | 97 | use super::*; |
105 | use ra_syntax::File; | 98 | use ra_syntax::{ast::ModuleItemOwner, File}; |
106 | 99 | ||
107 | fn do_check(code: &str, expected: &[&str]) { | 100 | fn do_check(code: &str, expected: &[&str]) { |
108 | let file = File::parse(&code); | 101 | let file = File::parse(&code); |
109 | let scope = ModuleScope::new(&file); | 102 | let scope = ModuleScope::new(file.ast().items()); |
110 | let actual = scope.entries.iter().map(|it| it.name()).collect::<Vec<_>>(); | 103 | let actual = scope.entries.iter().map(|it| it.name()).collect::<Vec<_>>(); |
111 | assert_eq!(expected, actual.as_slice()); | 104 | assert_eq!(expected, actual.as_slice()); |
112 | } | 105 | } |