Conversation
|
Thanks @bageljrkhanofemus , thanks for starting the contribution. As far as I can see right now it looks good. Can't wait to see it finished :) Maybe you're interested in #39 too |
|
So a little update, I'm working on trying to find out what modules are installed, and wanted to see how rope handles this part. So it turns out Rope has their own implementation (with caching and a similar featureset) here.
However, it can determine the python path(s) of the current project, which will make that part easier. |
|
Hi @bageljrkhanofemus I've got some doubts, please bear with me as it's been some time since I dove into
What I do see is a great idea is:
I'm very excited of your ideas and implementation, please keep me updated |
|
Thanks for the explanation it was cristal clear. I see your point on the need of being able to run I'm curious too to know how does rope manage the cache and how does it watch the changes in the pythonpath. We currently find the PYTHONPATH with pyprojroot, I don't know if it can fulfill your needs. I wouldn't have any problem ditching it in favour of rope. Thanks again :) |
|
While that is useful (especially since rope needs that anyway), it doesn't give us the full information
Rope manages a cache for the project itself, watches for changes and updates that accordingly (rope's codebase is larger so I haven't read through the whole thing yet) and it stores its cache in a .ropeproject folder. |
|
I've given it a little bit of thought and this is what I came out with: To make the autocompletion quicker, we could split the reading of cache and the update. So when we use the autocomplete it will only fetch items from the cache, and when it saves it updates the cache. Another option would be to only read the cache when saving and autocompleting, and have a daemon in another process that is monitoring the file changes and update the cache then. An alternative to rope's system could be using inotify to monitor the file changes. Right now the vim's integration with Ale runs |
|
inotify would only work when you're editing the file. Say I do this
I don't know a good way to watch for 4 besides hashing the directory or something. |
|
One way of monitoring 4 could be by package manager hooks, I'm currently using PDM, and it looks like it's easy to write a plugin that updates the cache on package changes. I will add it as an optional feature so as not to force the users to use PDM |
|
Simplest way is to It's not fool-proof since mtime can be modified manually, but it'll be much faster than any methods that reads off the file content like hashing the whole directory and it should work for the vast majority of the time. Compared to package manager hooks, it would not require modifying the virtualenv directory nor for the editor's plugin virtualenv to be the same as the project virtualenv. Compared to inotify, saving file metadata would not require a deamon that needs to remain alive while the files/folder was being modified, so when using inotify, you will still need a way to find changes at startup since the daemon shuts down. inotify is faster than metadata scanning though, so for when you already have a persistent daemon (e.g. pylsp), inotify can be a good optimization. |
|
Woah that's smart, I'll add it to my code for updating packages. That's going to be way faster than hashing anything. |
|
Update:
The first two can be solved by scanning the pyproject.toml for dependencies and using those (which I will eventually implement in rope). However, the goal of that project is interactive autoimport in pylsp and I will not finish this PR since it is out of scope. Thank you for your patience and help. |
|
I'm so sad to hear that @bageljrkhanofemus , I completely understand though. Can you please add a link to your project so that if anyone want's to continue this initiative can take it as a reference? |
|



I'm working on creating a plugin for autoimport for pylsp and would find it useful if we could get a list of all possible imports without formatting the file so we can implement autoimport when you autocomplete, not on formatting. I split off the relevant parts off to the SourceCodeBase class and exposed two new functions - find_package and get_all_packages. I don't need find_package, but it was largely implemented and could lead to a better solution if get_all_packages doesn't work.
Checklist