Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion crates/ide-completion/src/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ use crate::{
CompletionContext, CompletionItem, CompletionItemKind,
context::{
DotAccess, ItemListKind, NameContext, NameKind, NameRefContext, NameRefKind,
PathCompletionCtx, PathKind, PatternContext, TypeAscriptionTarget, TypeLocation, Visible,
PathCompletionCtx, PathKind, PatternContext, Qualified, TypeAscriptionTarget, TypeLocation,
Visible,
},
item::Builder,
render::{
Expand Down Expand Up @@ -752,6 +753,7 @@ pub(super) fn complete_name_ref(
if let TypeAscriptionTarget::RetType { item: Some(item), .. } =
ascription
&& path_ctx.required_thin_arrow().is_some()
&& matches!(path_ctx.qualified, Qualified::No)
{
keyword::complete_for_and_where(acc, ctx, &item.clone().into());
}
Expand Down
64 changes: 63 additions & 1 deletion crates/ide-completion/src/tests/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! Except for use items which are tested in [super::use_tree] and mod declarations with are tested
//! in [crate::completions::mod_].
use expect_test::expect;
use expect_test::{Expect, expect};

use crate::tests::{check, check_edit, check_with_base_items};

Expand Down Expand Up @@ -134,6 +134,12 @@ fn completes_where() {
kw where
"#]],
);
check_with_base_items(
r"fn func() -> foo::Bar $0",
expect![[r#"
kw where
"#]],
);
check_with_base_items(
r"enum Enum $0",
expect![[r#"
Expand All @@ -154,6 +160,62 @@ fn completes_where() {
);
}

#[test]
fn completes_where_in_stmt_list() {
fn check_in_stmt_list(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
check(&format!("const _: () = {{{ra_fixture}}};"), expect);
}
check_in_stmt_list(
r"struct Struct $0",
expect![[r#"
kw where
"#]],
);
check_in_stmt_list(
r"struct Struct $0 {}",
expect![[r#"
kw where
"#]],
);
check_in_stmt_list(
r"fn func() $0",
expect![[r#"
bt u32 (adds ->) u32
kw crate:: (adds ->)
kw dyn (adds ->)
kw fn (adds ->)
kw for (adds ->)
kw impl (adds ->)
kw self:: (adds ->)
kw where
"#]],
);
check_in_stmt_list(
r"fn func() -> foo::Bar $0",
expect![[r#"
kw where
"#]],
);
check_in_stmt_list(
r"enum Enum $0",
expect![[r#"
kw where
"#]],
);
check_in_stmt_list(
r"enum Enum $0 {}",
expect![[r#"
kw where
"#]],
);
check_in_stmt_list(
r"trait Trait $0 {}",
expect![[r#"
kw where
"#]],
);
}

#[test]
fn before_record_field() {
check_with_base_items(
Expand Down
20 changes: 20 additions & 0 deletions crates/ide-completion/src/tests/type_pos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,26 @@ fn x() $0
kw where
"#]],
);

check_with_base_items(
r#"
mod foo { pub struct Bar; }
fn x() foo::$0
"#,
expect![[r#"
st Bar (adds ->) Bar
"#]],
);

check_with_base_items(
r#"
mod foo { pub struct Bar; }
fn x() foo::b$0
"#,
expect![[r#"
st Bar (adds ->) Bar
"#]],
);
}

#[test]
Expand Down