JulianEberius / SublimeRope

ST2 only, use SublimePythonIDE with ST3: Adds Python completions and some IDE-like functions to Sublime Text 2, through the use of the Rope library
GNU General Public License v2.0
250 stars 26 forks source link

Rope does not see changes when a file is saved. #42

Closed ehuss closed 11 years ago

ehuss commented 12 years ago

Whenever a python file is saved, rope doesn't seem to see the changes (like jump-to-global definition). Rebuilding the cache does not help. The only way to get it to update (aside from restarting Sublime) is to do something like ropemate.project_cache.clear().

I'm not sure how exactly Rope is supposed to see changed files. I've been tracing the code for a while, but I don't see how it is supposed to reparse a file. If you could point me to how this is supposed to work, I could try to debug it a little further. The general code path that I see is:

# on save
autoimport.generate_cache(resources=[the saved file])
    update_resource(resource)
        pymodule = project.pycore.resource_to_pyobject(resource)
             cache.get_pymodule(...)  # always in the cache
        _add_names()
            pymodule._get_structural_attributes()
                # Returns the cached attributes from self.structural_attributes
        # Adds the names to the list.

None of those steps seem to clear any caches. resource_to_pyobject just fetches the PyModule from the cache, and fetching the attributes from that module also always gets from its cached value. Any help would be appreciated.

I am on Windows, BTW.

JulianEberius commented 12 years ago

Thanks for your report. I just looked over the codebase briefly, and the whole caching system is quite incoherent, mainly because it grew uncontrolled and wildly over the last months to fight performance problems ;-) Sadly, SublimeRope is just a free-time project ;-)

I do not have time today, but I'll write more when I find some time to think the whole caching thing through (e.g. why are there so many different methods and commands dealing with various caches, etc). It really needs an overall architecture.

JulianEberius commented 11 years ago

Hi,

Not sure if you're still interested in the issue after 3 months, but I have commited a temporary fix for this issue. As you already found out, the issue was not directly with SublimeRope but with Rope and it's AutoImport contrib. It does not invalidate old cache entries on update_resource. The current fix calls some private invalidation method inside Rope. I guess there is a better way (Rope has an observer-pattern built in, which can trigger these invalidations), but they would require some general changes to SublimeRope. Noticed as TODO.