-
Notifications
You must be signed in to change notification settings - Fork 163
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
Support aliases in rope_autoimport #712
Comments
Hi @tkrabel-db, thanks for your interest in contributing to rope. I think the idea sounds reasonable to me. You're welcome to try and implement it, if the code looks reasonable enough, I am happy to review and accept the pull request. I don't think this should be implemented as a hardcoded list of aliases though, it would be much more sensible to make this a configurable option. Rope reads project tooling configuration from Let me know if you would need any help. |
That makes sense! I'll work on it! |
@tkrabel-db @lieryan I made an initial pass at fixing this issue in #730, if the approach is reasonable I can keep working on the PR to complete the feature. |
Is your feature request related to a problem? Please describe.
Context: Using rope_autoimport as a language server feature (like in python-lsp-server).
I commonly type aliases like
pd
ornp
, but rope autoimport doesn't suggest the right aliased imports for that.Describe the solution you'd like
Support autoimports for common aliases. This doesn't have to be comprehensive, but we could start with the obvious ones:
Describe alternatives you've considered
I considered solving this in
python-lsp-server
, which uses rope for its autoimport feature. My conceptual implementation feels hacky and inefficient. Here's why, given an example.Let's say I want to support one alias import,
import pandas as pd
. In order to do that on the LS level, I need to search the index to check ifpandas
is installed, which adds a scan to the scan necessary to find potential import candidates. The index search increases with the number of aliases! So with, say 5 supported aliases, we search the index 5 times for every "aliased" module + 1 more time for the regular import suggestions.Moving this to rope would reduce the complexity. We could add a
get_alias_modules()
(name TBD) method that searches a specific alias index in rope (which could be an in-memory object since that index is super small), and add that search to thefull_search
.I am happy to implement that if you like the idea and we get consensus on the implementation
The text was updated successfully, but these errors were encountered: