Skip to content

Commit e6a237e

Browse files
bors[bot]Freax13
andauthored
Merge #9660
9660: hide keyword suggestions in non trivial paths r=Veykril a=Freax13 This pr hides keyword suggestions in non trivial paths: ![now](https://user-images.githubusercontent.com/14952658/126479635-819127d8-322b-4e34-acd2-194d1e9ba504.png) Previously rust analyzer suggested a lot of keywords even when completing non trivial paths: ![prev](https://user-images.githubusercontent.com/14952658/126478222-54c742bb-2bd3-4e5b-b533-f835264604be.png) This had 2 problems: 1. Suggesting a keyword in this position doesn't make sense. 2. There are a lot of keywords, so they make it a lot harder to find the things you're actually looking for (note the scrollbar and that `instructions`, `registers` and `structures` are not visible). Co-authored-by: Tom Dohrmann <[email protected]>
2 parents 478d435 + 7b20904 commit e6a237e

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

crates/ide_completion/src/completions/keyword.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
2020
cov_mark::hit!(no_keyword_completion_in_attr_of_expr);
2121
return;
2222
}
23+
if ctx.is_non_trivial_path() {
24+
cov_mark::hit!(no_keyword_completion_in_non_trivial_path);
25+
return;
26+
}
2327

2428
// Suggest .await syntax for types that implement Future trait
2529
if let Some(receiver) = ctx.dot_receiver() {

crates/ide_completion/src/context.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,10 @@ impl<'a> CompletionContext<'a> {
353353
matches!(self.path_context, Some(PathCompletionContext { is_trivial_path: true, .. }))
354354
}
355355

356+
pub(crate) fn is_non_trivial_path(&self) -> bool {
357+
matches!(self.path_context, Some(PathCompletionContext { is_trivial_path: false, .. }))
358+
}
359+
356360
pub(crate) fn path_qual(&self) -> Option<&ast::Path> {
357361
self.path_context.as_ref().and_then(|it| it.qualifier.as_ref())
358362
}

crates/ide_completion/src/tests/item_list.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -101,25 +101,11 @@ fn in_item_list_after_attr() {
101101

102102
#[test]
103103
fn in_qualified_path() {
104+
cov_mark::check!(no_keyword_completion_in_non_trivial_path);
104105
check(
105106
r#"crate::$0"#,
106107
expect![[r##"
107-
kw pub(crate)
108-
kw pub
109-
kw unsafe
110-
kw fn
111-
kw const
112-
kw type
113-
kw impl
114-
kw extern
115-
kw use
116-
kw trait
117-
kw static
118-
kw mod
119-
kw enum
120-
kw struct
121-
kw union
122-
ma makro!(…) #[macro_export] macro_rules! makro
108+
ma makro!(…) #[macro_export] macro_rules! makro
123109
md module
124110
"##]],
125111
)

0 commit comments

Comments
 (0)