typing underscore should not trigger completions in types or patterns

This commit is contained in:
Lukas Wirth 2023-09-29 21:06:47 +02:00
parent f19479a2ad
commit ae5d74dffb
2 changed files with 131 additions and 0 deletions

View file

@ -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;