Filter private builtins members from completions

This commit is contained in:
Zanie Blue 2025-07-02 15:24:17 -05:00
parent 4cf56d7ad4
commit cb602bf66c
2 changed files with 8 additions and 4 deletions

View file

@ -472,6 +472,7 @@ mod tests {
",
);
test.assert_completions_include("filter");
test.assert_completions_do_not_include("_T");
}
#[test]

View file

@ -69,12 +69,12 @@ impl<'db> SemanticModel<'db> {
return vec![];
};
let ty = Type::module_literal(self.db, self.file, &module);
let builtin = module.is_known(KnownModule::Builtins);
crate::types::all_members(self.db, ty)
.into_iter()
.map(|name| Completion {
name,
builtin: module.is_known(KnownModule::Builtins),
})
// Filter out private members from `builtins`
.filter(|name| !builtin || !name.starts_with('_'))
.map(|name| Completion { name, builtin })
.collect()
}
@ -142,6 +142,9 @@ pub struct Completion {
/// doesn't make it into the LSP response. Instead, we
/// use it mainly in tests so that we can write less
/// noisy tests.
///
/// However, we do pre-filter private names from the
/// builtin module before construction.
pub builtin: bool,
}