Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-completion/src/lib.rs')
-rw-r--r--crates/ide-completion/src/lib.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/crates/ide-completion/src/lib.rs b/crates/ide-completion/src/lib.rs
index 2eaa42040a..2fad293d16 100644
--- a/crates/ide-completion/src/lib.rs
+++ b/crates/ide-completion/src/lib.rs
@@ -169,6 +169,28 @@ pub fn completions(
return Some(completions.into());
}
+ // when the user types a bare `_` (that is it does not belong to an identifier)
+ // the user might just wanted to type a `_` for type inference or pattern discarding
+ // so try to suppress completions in those cases
+ if trigger_character == Some('_') && ctx.original_token.kind() == syntax::SyntaxKind::UNDERSCORE
+ {
+ if let CompletionAnalysis::NameRef(NameRefContext {
+ kind:
+ NameRefKind::Path(
+ path_ctx @ PathCompletionCtx {
+ kind: PathKind::Type { .. } | PathKind::Pat { .. },
+ ..
+ },
+ ),
+ ..
+ }) = analysis
+ {
+ if path_ctx.is_trivial_path() {
+ return None;
+ }
+ }
+ }
+
{
let acc = &mut completions;