No self-imports in completion

This commit is contained in:
Aleksey Kladov 2018-09-01 12:46:43 +03:00
parent 2161a1689d
commit f5669dfc56
2 changed files with 12 additions and 1 deletions

View file

@ -42,6 +42,7 @@ pub fn scope_completion(file: &File, offset: TextUnit) -> Option<Vec<CompletionI
let scope = ModuleScope::new(root);
res.extend(
scope.entries().iter()
.filter(|entry| entry.syntax() != name_ref.syntax())
.map(|entry| CompletionItem {
name: entry.name().to_string(),
snippet: None,
@ -232,6 +233,13 @@ mod tests {
CompletionItem { name: "quux", snippet: None }]"#);
}
#[test]
fn test_completion_mod_scope_no_self_use() {
check_scope_completion(r"
use foo<|>;
", r#"[]"#);
}
#[test]
fn test_complete_type() {
check_scope_completion(r"

View file

@ -1,5 +1,5 @@
use libsyntax2::{
AstNode, SyntaxNode, SmolStr, ast
AstNode, SyntaxNode, SyntaxNodeRef, SmolStr, ast
};
pub struct ModuleScope {
@ -67,6 +67,9 @@ impl Entry {
.text(),
}
}
pub fn syntax(&self) -> SyntaxNodeRef {
self.node.borrowed()
}
}
fn collect_imports(tree: ast::UseTree, acc: &mut Vec<Entry>) {