posit-dev / posit-dev/positron
Support `_ipython_key_completions_` completions hook
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 4.3k
- Forks
- 184
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 206
Description
Discussed in https://github.com/posit-dev/positron/discussions/8425
Originally posted by @astrowonk July 7, 2025
iPython (and thus Jupyter) support the ability to expose custom autocomplete information in class definitions. Here is a silly one:class DemoAutocomplete: """demo class""" def __getitem__(self, item): return item + item @staticmethod def _ipython_key_completions_(): """required for custom autocompletion of subscriptables""" return list(range(10))In iPython or Jupyter, autocomplete now works for the subscriptable instance of this class.
![]()
However in Positron console, the autocomplete suggestions are both irrelevant (appears to be every defined object) and don't include the key completions data:
![]()
It would be wonderful if we could have autocomplete parity with juptyer/ipython. I use custom classes for autocomplete extensively as we have many tables and other data structures whose names I can't remember, so I create helper subscriptable objects with defined
_ipython_key_completions_that allow me to access this data easily.
Possible Implementation
Originally posted by @seeM July 8, 2025
It doesn't work currently because we don't use IPython's completions system, we go directly to a language server which can inspect the kernel's variables.We'd probably implement this by patching Jedi as we've done before, or we could try to get it added in the Jedi repo. Here's the upstream Jedi issue that was tracking this but was closed at some point: https://github.com/davidhalter/jedi/issues/771
Originally posted by @astrowonk July 8, 2025
The iPython docs claim that it will also look at dir for autocompletion suggestions, but the code for _get_keys does not appear to do anything with dir.dir does not seem to help the Positron console either (so I guess Jedi also doesn't look at dir).
I was hoping I could just also define dir and Jedi/Positron would autocomplete my example but no such luck!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing Positron's direct language-server completion path and compare it with IPython's _get_keys implementation in IPython/core/completer.py. Review the closed Jedi issue 771 and the existing Jedi patching approach mentioned in the discussion. Done means subscriptable objects exposing ipython_key_completions produce the expected key suggestions in the Positron console.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- jupyter, python
- Domain
- developer-experience, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100