diff --git a/crates/libeditor/src/completion.rs b/crates/libeditor/src/completion.rs index 242a3a4347..cea2d14d12 100644 --- a/crates/libeditor/src/completion.rs +++ b/crates/libeditor/src/completion.rs @@ -8,7 +8,7 @@ use libsyntax2::{ use { AtomEdit, find_node_at_offset, - scope::{FnScopes, compute_scopes}, + scope::FnScopes, }; #[derive(Debug)] @@ -25,7 +25,7 @@ pub fn scope_completion(file: &File, offset: TextUnit) -> Option(file.syntax(), offset)?; let fn_def = ancestors(name_ref.syntax()).filter_map(ast::FnDef::cast).next()?; - let scopes = compute_scopes(fn_def); + let scopes = FnScopes::new(fn_def); Some(complete(name_ref, &scopes)) } diff --git a/crates/libeditor/src/scope.rs b/crates/libeditor/src/scope.rs index 1fec0b24e4..76104b2cf1 100644 --- a/crates/libeditor/src/scope.rs +++ b/crates/libeditor/src/scope.rs @@ -9,20 +9,6 @@ use libsyntax2::{ algo::{ancestors, generate, walk::preorder} }; -pub fn compute_scopes(fn_def: ast::FnDef) -> FnScopes { - let mut scopes = FnScopes::new(); - let root = scopes.root_scope(); - fn_def.param_list().into_iter() - .flat_map(|it| it.params()) - .filter_map(|it| it.pat()) - .for_each(|it| scopes.add_bindings(root, it)); - - if let Some(body) = fn_def.body() { - compute_block_scopes(body, &mut scopes, root) - } - scopes -} - fn compute_block_scopes(block: ast::Block, scopes: &mut FnScopes, mut scope: ScopeId) { for stmt in block.statements() { match stmt { @@ -106,11 +92,21 @@ pub struct FnScopes { } impl FnScopes { - fn new() -> FnScopes { - FnScopes { - scopes: vec![], - scope_for: HashMap::new(), + pub fn new(fn_def: ast::FnDef) -> FnScopes { + let mut scopes = FnScopes { + scopes: Vec::new(), + scope_for: HashMap::new() + }; + let root = scopes.root_scope(); + fn_def.param_list().into_iter() + .flat_map(|it| it.params()) + .filter_map(|it| it.pat()) + .for_each(|it| scopes.add_bindings(root, it)); + + if let Some(body) = fn_def.body() { + compute_block_scopes(body, &mut scopes, root) } + scopes } pub fn entries(&self, scope: ScopeId) -> &[ScopeEntry] { &self.scopes[scope].entries