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_include("filter");
test.assert_completions_do_not_include("_T");
} }
#[test] #[test]

View File

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