mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 15:15:24 +00:00
No self-imports in completion
This commit is contained in:
parent
2161a1689d
commit
f5669dfc56
2 changed files with 12 additions and 1 deletions
|
@ -42,6 +42,7 @@ pub fn scope_completion(file: &File, offset: TextUnit) -> Option<Vec<CompletionI
|
||||||
let scope = ModuleScope::new(root);
|
let scope = ModuleScope::new(root);
|
||||||
res.extend(
|
res.extend(
|
||||||
scope.entries().iter()
|
scope.entries().iter()
|
||||||
|
.filter(|entry| entry.syntax() != name_ref.syntax())
|
||||||
.map(|entry| CompletionItem {
|
.map(|entry| CompletionItem {
|
||||||
name: entry.name().to_string(),
|
name: entry.name().to_string(),
|
||||||
snippet: None,
|
snippet: None,
|
||||||
|
@ -232,6 +233,13 @@ mod tests {
|
||||||
CompletionItem { name: "quux", snippet: None }]"#);
|
CompletionItem { name: "quux", snippet: None }]"#);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_completion_mod_scope_no_self_use() {
|
||||||
|
check_scope_completion(r"
|
||||||
|
use foo<|>;
|
||||||
|
", r#"[]"#);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_complete_type() {
|
fn test_complete_type() {
|
||||||
check_scope_completion(r"
|
check_scope_completion(r"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use libsyntax2::{
|
use libsyntax2::{
|
||||||
AstNode, SyntaxNode, SmolStr, ast
|
AstNode, SyntaxNode, SyntaxNodeRef, SmolStr, ast
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct ModuleScope {
|
pub struct ModuleScope {
|
||||||
|
@ -67,6 +67,9 @@ impl Entry {
|
||||||
.text(),
|
.text(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn syntax(&self) -> SyntaxNodeRef {
|
||||||
|
self.node.borrowed()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect_imports(tree: ast::UseTree, acc: &mut Vec<Entry>) {
|
fn collect_imports(tree: ast::UseTree, acc: &mut Vec<Entry>) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue