Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Intellisense for the underscore table accessor #10369

Open
1 task done
sergei3000 opened this issue Oct 25, 2024 · 3 comments
Open
1 task done

feat: Intellisense for the underscore table accessor #10369

sergei3000 opened this issue Oct 25, 2024 · 3 comments
Labels
feature Features or general enhancements

Comments

@sergei3000
Copy link

Is your feature request related to a problem?

No response

What is the motivation behind your request?

No response

Describe the solution you'd like

I'm using vscode with Python/Pylance extension installed. Here's my example with a table created off of a postgres connection:
my_tab = con.table("my_tab")

  1. This way gives me code suggestions on the column's methods (e.g. isin):
    my_tab.filter(my_tab.my_col.
  2. And this way doesn't:
    my_tab.filter(_.my_col.

It would be awesome if the latter worked for intellisense in the IDE.

What version of ibis are you running?

9.5.0

What backend(s) are you using, if any?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@sergei3000 sergei3000 added the feature Features or general enhancements label Oct 25, 2024
@NickCrews
Copy link
Contributor

I have wanted the same thing :). Unfortunatley, I don't think this will ever be possible, since the meaning of _ depends entirely on the context that it is used, which I don't think can be known statically by an analysis tool like mypy/pyright, etc. At the least, it would require some VERY deep knowledge of python's type system. I wouldn't hold my breath for this

@cpcloud
Copy link
Member

cpcloud commented Nov 2, 2024

I actually made some progress on this, but I'm not yet sure whether it's a viable approach.

The trickiest bit here for a proof of concept is partial parsing of Python syntax.

I remembered (not sure from where) that tree-sitter can handle partial parsing of programming languages, so I spent some time looking into combining tree sitter with the IPython completion mechanism.

First, tree sitter was actually pretty straightforward to use to get the information I want for very simple expressions.

Second, the IPython completion customization hooks leave something to be desired, but I was able to get _ to complete to the syntactically closest ibis.Table expression.

I haven't figured out a few things:

  1. Stem completion. For example when you type _.a<TAB> you should only see attributes that start with a
  2. Column method completion. This is trickier since it requires some additional matching criteria and slightly different way of constructing the final list of completions.

In any event, here's a screenshot and a gist with the code:

image

@cpcloud
Copy link
Member

cpcloud commented Nov 2, 2024

FWIW, I suspect this is doable in a way that is both complete enough to be valuable, and not interfere with existing completions.

The second part, not interfering with existing completions is likely going to require some spelunking in IPython to figure out how to delegate to the default behavior when the Ibis completion doesn't match anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Features or general enhancements
Projects
Status: backlog
Development

No branches or pull requests

3 participants