From 69d07df201307fb7c539cdb20b8f1c1c12840386 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 24 Oct 2018 18:37:25 +0300 Subject: Complete crate:: paths --- crates/ra_editor/src/completion.rs | 30 +++++++++++++++++------------- crates/ra_editor/src/lib.rs | 2 +- 2 files changed, 18 insertions(+), 14 deletions(-) (limited to 'crates/ra_editor/src') diff --git a/crates/ra_editor/src/completion.rs b/crates/ra_editor/src/completion.rs index 8502b337d..0a3675255 100644 --- a/crates/ra_editor/src/completion.rs +++ b/crates/ra_editor/src/completion.rs @@ -2,7 +2,7 @@ use rustc_hash::{FxHashMap, FxHashSet}; use ra_syntax::{ algo::visit::{visitor, visitor_ctx, Visitor, VisitorCtx}, - ast::{self, LoopBodyOwner, ModuleItemOwner}, + ast::{self, AstChildren, LoopBodyOwner, ModuleItemOwner}, text_utils::is_subrange, AstNode, File, SyntaxKind::*, @@ -65,6 +65,21 @@ pub fn scope_completion(file: &File, offset: TextUnit) -> Option, this_item: Option, acc: &mut Vec) { + let scope = ModuleScope::new(items); + acc.extend( + scope + .entries() + .iter() + .filter(|entry| Some(entry.syntax()) != this_item.map(|it| it.syntax())) + .map(|entry| CompletionItem { + label: entry.name().to_string(), + lookup: None, + snippet: None, + }), + ); +} + fn complete_name_ref(file: &File, name_ref: ast::NameRef, acc: &mut Vec) { if !is_node::(name_ref.syntax()) { return; @@ -77,18 +92,7 @@ fn complete_name_ref(file: &File, name_ref: ast::NameRef, acc: &mut Vec