mirror of https://github.com/astral-sh/ruff
Filter private `builtins` members from completions
This commit is contained in:
parent
4cf56d7ad4
commit
cb602bf66c
|
|
@ -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]
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue