Skip to content

Commit 89ef71a

Browse files
committed
Fix tab completion for classes
1 parent 044f9c1 commit 89ef71a

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/shell/helper.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,16 @@ impl<'vm> ShellHelper<'vm> {
5858
fn get_available_completions<'w>(
5959
&self,
6060
words: &'w [String],
61-
) -> Option<(&'w str, Box<dyn Iterator<Item = PyResult<PyStrRef>> + 'vm>)> {
61+
) -> Option<(&'w str, impl Iterator<Item = PyResult<PyStrRef>> + 'vm)> {
6262
// the very first word and then all the ones after the dot
6363
let (first, rest) = words.split_first().unwrap();
6464

6565
let str_iter_method = |obj, name| {
66-
let iter = self.vm.call_method(obj, name, ())?;
66+
let iter = self.vm.call_special_method(obj, name, ())?;
6767
PyIterable::<PyStrRef>::try_from_object(self.vm, iter)?.iter(self.vm)
6868
};
6969

70-
if let Some((last, parents)) = rest.split_last() {
70+
let (word_start, iter1, iter2) = if let Some((last, parents)) = rest.split_last() {
7171
// we need to get an attribute based off of the dir() of an object
7272

7373
// last: the last word, could be empty if it ends with a dot
@@ -82,16 +82,17 @@ impl<'vm> ShellHelper<'vm> {
8282
current = self.vm.get_attribute(current.clone(), attr.as_str()).ok()?;
8383
}
8484

85-
let current_iter = str_iter_method(&current, "__dir__").ok()?;
85+
let current_iter = str_iter_method(current, "__dir__").ok()?;
8686

87-
Some((&last, Box::new(current_iter) as _))
87+
(last, current_iter, None)
8888
} else {
8989
// we need to get a variable based off of globals/builtins
9090

91-
let globals = str_iter_method(self.globals.as_object(), "keys").ok()?;
92-
let builtins = str_iter_method(&self.vm.builtins, "__dir__").ok()?;
93-
Some((&first, Box::new(Iterator::chain(globals, builtins)) as _))
94-
}
91+
let globals = str_iter_method(self.globals.as_object().clone(), "keys").ok()?;
92+
let builtins = str_iter_method(self.vm.builtins.clone(), "__dir__").ok()?;
93+
(first, globals, Some(builtins))
94+
};
95+
Some((word_start, iter1.chain(iter2.into_iter().flatten())))
9596
}
9697

9798
fn complete_opt(&self, line: &str) -> Option<(usize, Vec<String>)> {

vm/src/vm.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,9 @@ impl VirtualMachine {
991991
PyMethod::get_special(obj, method, self)
992992
}
993993

994-
pub(crate) fn call_special_method(
994+
/// NOT PUBLIC API
995+
#[doc(hidden)]
996+
pub fn call_special_method(
995997
&self,
996998
obj: PyObjectRef,
997999
method: &str,

0 commit comments

Comments
 (0)