Skip to content

Commit 7abf8cc

Browse files
committed
Auto merge of rust-lang#12111 - jonas-schievink:fix-outline-mod-completion, r=jonas-schievink
fix: fix outline mod completion with partial module name Fixes rust-lang/rust-analyzer#12104 ![screenshot-2022-04-28-20:22:42](https://user-images.githubusercontent.com/1786438/165821068-a673a154-ce53-4489-af60-56d09dc9061c.png)
2 parents 339a186 + 52010d7 commit 7abf8cc

File tree

1 file changed

+38
-1
lines changed
  • crates/ide_completion/src/completions

1 file changed

+38
-1
lines changed

crates/ide_completion/src/completions/mod_.rs

+38-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use ide_db::{
88
base_db::{SourceDatabaseExt, VfsPath},
99
RootDatabase, SymbolKind,
1010
};
11+
use syntax::{ast, AstNode, SyntaxKind};
1112

1213
use crate::{context::NameContext, CompletionItem};
1314

@@ -24,7 +25,21 @@ pub(crate) fn complete_mod(acc: &mut Completions, ctx: &CompletionContext) -> Op
2425

2526
let _p = profile::span("completion::complete_mod");
2627

27-
let current_module = ctx.module;
28+
let mut current_module = ctx.module;
29+
// For `mod $0`, `ctx.module` is its parent, but for `mod f$0`, it's `mod f` itself, but we're
30+
// interested in its parent.
31+
if ctx.original_token.kind() == SyntaxKind::IDENT {
32+
if let Some(module) = ctx.original_token.ancestors().nth(1).and_then(ast::Module::cast) {
33+
match current_module.definition_source(ctx.db).value {
34+
ModuleSource::Module(src) if src == module => {
35+
if let Some(parent) = current_module.parent(ctx.db) {
36+
current_module = parent;
37+
}
38+
}
39+
_ => {}
40+
}
41+
}
42+
}
2843

2944
let module_definition_file =
3045
current_module.definition_source(ctx.db).file_id.original_file(ctx.db);
@@ -314,4 +329,26 @@ fn bar_ignored() {}
314329
expect![[r#""#]],
315330
);
316331
}
332+
333+
#[test]
334+
fn name_partially_typed() {
335+
check(
336+
r#"
337+
//- /lib.rs
338+
mod f$0
339+
//- /foo.rs
340+
fn foo() {}
341+
//- /foo/ignored_foo.rs
342+
fn ignored_foo() {}
343+
//- /bar/mod.rs
344+
fn bar() {}
345+
//- /bar/ignored_bar.rs
346+
fn ignored_bar() {}
347+
"#,
348+
expect![[r#"
349+
md foo;
350+
md bar;
351+
"#]],
352+
);
353+
}
317354
}

0 commit comments

Comments
 (0)