Skip to content

Commit

Permalink
Merge pull request #18835 from Veykril/push-wnmwwoktmpyt
Browse files Browse the repository at this point in the history
Hide synthetic locals from completions
  • Loading branch information
Veykril authored Jan 4, 2025
2 parents d1d4319 + bf7597c commit 061d257
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crates/ide-completion/src/completions/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,17 @@ pub(crate) fn complete_expr_path(
[..] => acc.add_path_resolution(ctx, path_ctx, name, def, doc_aliases),
}
}
// synthetic names currently leak out as we lack synthetic hygiene, so filter them
// out here
ScopeDef::Local(_) => {
if !name.as_str().starts_with('<') {
acc.add_path_resolution(ctx, path_ctx, name, def, doc_aliases)
}
}
_ if scope_def_applicable(def) => {
acc.add_path_resolution(ctx, path_ctx, name, def, doc_aliases)
}

_ => (),
});

Expand Down
5 changes: 5 additions & 0 deletions crates/ide-completion/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,11 @@ impl<'a> CompletionContext<'a> {
let mut locals = FxHashMap::default();
scope.process_all_names(&mut |name, scope| {
if let ScopeDef::Local(local) = scope {
// synthetic names currently leak out as we lack synthetic hygiene, so filter them
// out here
if name.as_str().starts_with('<') {
return;
}
locals.insert(name, local);
}
});
Expand Down
72 changes: 72 additions & 0 deletions crates/ide-completion/src/tests/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1785,3 +1785,75 @@ fn foo<T: ExcludedTrait>() {
"#]],
);
}

#[test]
fn hide_ragennew_synthetic_identifiers() {
check_empty(
r#"
//- minicore: iterator
fn bar() {
for i in [0; 10] {
r$0
}
}
"#,
expect![[r#"
en Option Option<{unknown}>
en Result Result<{unknown}, {unknown}>
fn bar() fn()
lc i i32
ma const_format_args!(…) macro_rules! const_format_args
ma format_args!(…) macro_rules! format_args
ma format_args_nl!(…) macro_rules! format_args_nl
ma panic!(…) macro_rules! panic
ma print!(…) macro_rules! print
md core
md result (use core::result)
md rust_2015 (use core::prelude::rust_2015)
md rust_2018 (use core::prelude::rust_2018)
md rust_2021 (use core::prelude::rust_2021)
tt Clone
tt Copy
tt IntoIterator
tt Iterator
ta Result (use core::fmt::Result)
ev Err(…) Err(E)
ev None None
ev Ok(…) Ok(T)
ev Some(…) Some(T)
bt u32 u32
kw async
kw break
kw const
kw continue
kw crate::
kw enum
kw extern
kw false
kw fn
kw for
kw if
kw if let
kw impl
kw let
kw loop
kw match
kw mod
kw return
kw self::
kw static
kw struct
kw trait
kw true
kw type
kw union
kw unsafe
kw use
kw while
kw while let
sn macro_rules
sn pd
sn ppd
"#]],
);
}

0 comments on commit 061d257

Please sign in to comment.