improvement: fallback to jedi interpeter in completion #1559
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change improves the responsiveness and coverage of code completion.
Interpreter
class when static analysis-based completion turns up empty. (Jedi's static completer fails on some libraries, like ibis.) TheInterpreter
completer evaluates code, so care is taken to avoid race conditions with the kernel by introducing a lock on the globals dictionary. Acquiring/releasing the lock works in Pyodide, even though Pyodide doesn't support creating threads, so no separate codepath was needed for WASM.As a result:
Note: While the
Interpreter
completer is running, the user won't be able to run code / the kernel won't process control requests. For this reason the Interpreter completer has a timeout of 1 second (we can make this even lower if needed). In practice I believe this won't be a problem since the Interpreter completer is only a fallback.Tested: manually, by playing with a notebook that uses Ibis, Pandas, and NumPy locally.
In the future, we could make docstring fetching lazy, in which case we could remove the docstring limit.