mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
Complete modules in item lists
This commit is contained in:
parent
7ad378fec0
commit
ea251cbd4a
3 changed files with 45 additions and 4 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
use crate::{CompletionContext, Completions};
|
use crate::{CompletionContext, Completions};
|
||||||
|
|
||||||
|
// Ideally this should be removed and moved into `(un)qualified_path` respectively
|
||||||
pub(crate) fn complete_macro_in_item_position(acc: &mut Completions, ctx: &CompletionContext) {
|
pub(crate) fn complete_macro_in_item_position(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
// Show only macros in top level.
|
// Show only macros in top level.
|
||||||
if !ctx.is_new_item {
|
if !ctx.is_new_item {
|
||||||
|
@ -12,6 +13,10 @@ pub(crate) fn complete_macro_in_item_position(acc: &mut Completions, ctx: &Compl
|
||||||
if let hir::ScopeDef::MacroDef(mac) = res {
|
if let hir::ScopeDef::MacroDef(mac) = res {
|
||||||
acc.add_macro(ctx, Some(name.to_string()), mac);
|
acc.add_macro(ctx, Some(name.to_string()), mac);
|
||||||
}
|
}
|
||||||
|
// FIXME: This should be done in qualified_path/unqualified_path instead?
|
||||||
|
if let hir::ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = res {
|
||||||
|
acc.add_resolution(ctx, name.to_string(), &res);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ use syntax::AstNode;
|
||||||
use crate::{CompletionContext, Completions};
|
use crate::{CompletionContext, Completions};
|
||||||
|
|
||||||
pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionContext) {
|
pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
if ctx.is_path_disallowed() {
|
if ctx.is_path_disallowed() || ctx.expects_item() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let path = match &ctx.path_qual {
|
let path = match &ctx.path_qual {
|
||||||
|
@ -20,7 +20,7 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
|
||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
let context_module = ctx.scope.module();
|
let context_module = ctx.scope.module();
|
||||||
if ctx.expects_item() || ctx.expects_assoc_item() {
|
if ctx.expects_assoc_item() {
|
||||||
if let PathResolution::Def(hir::ModuleDef::Module(module)) = resolution {
|
if let PathResolution::Def(hir::ModuleDef::Module(module)) = resolution {
|
||||||
let module_scope = module.scope(ctx.db, context_module);
|
let module_scope = module.scope(ctx.db, context_module);
|
||||||
for (name, def) in module_scope {
|
for (name, def) in module_scope {
|
||||||
|
@ -636,6 +636,24 @@ impl MyStruct {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore] // FIXME doesn't complete anything atm
|
||||||
|
fn completes_in_item_list() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
struct MyStruct {}
|
||||||
|
macro_rules! foo {}
|
||||||
|
mod bar {}
|
||||||
|
|
||||||
|
crate::$0
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
md bar
|
||||||
|
ma foo! macro_rules! foo
|
||||||
|
"#]],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_super_super_completion() {
|
fn test_super_super_completion() {
|
||||||
check(
|
check(
|
||||||
|
|
|
@ -9,10 +9,10 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC
|
||||||
if !ctx.is_trivial_path {
|
if !ctx.is_trivial_path {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ctx.is_path_disallowed() {
|
if ctx.is_path_disallowed() || ctx.expects_item() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ctx.expects_item() || ctx.expects_assoc_item() {
|
if ctx.expects_assoc_item() {
|
||||||
ctx.scope.process_all_names(&mut |name, def| {
|
ctx.scope.process_all_names(&mut |name, def| {
|
||||||
if let ScopeDef::MacroDef(macro_def) = def {
|
if let ScopeDef::MacroDef(macro_def) = def {
|
||||||
acc.add_macro(ctx, Some(name.to_string()), macro_def);
|
acc.add_macro(ctx, Some(name.to_string()), macro_def);
|
||||||
|
@ -692,4 +692,22 @@ impl MyStruct {
|
||||||
"#]],
|
"#]],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: The completions here currently come from `macro_in_item_position`, but they shouldn't
|
||||||
|
#[test]
|
||||||
|
fn completes_in_item_list() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
struct MyStruct {}
|
||||||
|
macro_rules! foo {}
|
||||||
|
mod bar {}
|
||||||
|
|
||||||
|
$0
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
md bar
|
||||||
|
ma foo!(…) macro_rules! foo
|
||||||
|
"#]],
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue