mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Add _suggestions module (#5675)
This commit is contained in:
1 parent
be56911598
commit
3c6bc2cf9f
3 files changed
+23
-1
No files matched your search
@@ -33,6 +33,7 @@ mod pyexpat;
|
||||
mod pystruct;
|
||||
mod random;
|
||||
mod statistics;
|
||||
mod suggestions;
|
||||
// TODO: maybe make this an extension module, if we ever get those
|
||||
// mod re;
|
||||
#[cfg(feature = "bz2")]
|
||||
@@ -133,6 +134,7 @@ pub fn get_module_inits() -> impl Iterator<Item = (Cow<'static, str>, StdlibInit
|
||||
"unicodedata" => unicodedata::make_module,
|
||||
"zlib" => zlib::make_module,
|
||||
"_statistics" => statistics::make_module,
|
||||
"suggestions" => suggestions::make_module,
|
||||
// crate::vm::sysmodule::sysconfigdata_name() => sysconfigdata::make_module,
|
||||
}
|
||||
#[cfg(any(unix, target_os = "wasi"))]
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
pub(crate) use _suggestions::make_module;
|
||||
|
||||
#[pymodule]
|
||||
mod _suggestions {
|
||||
use rustpython_vm::VirtualMachine;
|
||||
|
||||
use crate::vm::PyObjectRef;
|
||||
|
||||
#[pyfunction]
|
||||
fn _generate_suggestions(
|
||||
candidates: Vec<PyObjectRef>,
|
||||
name: PyObjectRef,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyObjectRef {
|
||||
match crate::vm::suggestion::calculate_suggestions(candidates.iter(), &name) {
|
||||
Some(suggestion) => suggestion.into(),
|
||||
None => vm.ctx.none(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ use std::iter::ExactSizeIterator;
|
||||
|
||||
const MAX_CANDIDATE_ITEMS: usize = 750;
|
||||
|
||||
fn calculate_suggestions<'a>(
|
||||
pub fn calculate_suggestions<'a>(
|
||||
dir_iter: impl ExactSizeIterator<Item = &'a PyObjectRef>,
|
||||
name: &PyObjectRef,
|
||||
) -> Option<PyStrRef> {
|
||||
|
||||
Reference in new issue
Block a user