Repository navigation
Route filesystem queries through the fscommands owner - #911
marlon-costa-dc wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #911 +/- ##
==========================================
+ Coverage 95.44% 95.49% +0.04%
==========================================
Files 134 134
Lines 26910 26985 +75
==========================================
+ Hits 25685 25768 +83
+ Misses 1225 1217 -8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
What's the use case for this? Can you provide some justifications on why this is necessary so I understand better what the purpose of routing these checks through fscommands? |
|
Thanks for asking. The use case is running Rope over a filesystem view that is not the live disk. A custom Concretely, we analyse and refactor a large Python workspace with Rope while other tools may be rewriting files on disk at the same time. To keep one refactoring consistent, we give the
So a resource that only exists in the snapshot is reported missing, a file deleted on disk mid-run still appears, and change detection fires against files the snapshot never read. The same applies to anything that keeps unsaved buffers or a virtual tree (an editor or language server integration, tests with an in-memory filesystem): writes can be redirected today, but reads cannot. The change keeps the default behaviour identical: |
|
IIUC, the current PR works fine with any For a more concrete example, pylsp-rope's WorkspaceFileCommands would break with this change because they do not implement these new methods and also do not inherit from FileSystemCommands. And it also doesn't feel right that fscommands had to inherit from If this is going to ever have a chance to go through, the new methods should be optional. Maybe rope can wrap the passed in And we should also formalise its contract for the new optional APIs. If future version of rope needs to add a new filesystem commands, there needs to be a way for implementors that works with virtual filesystems to know if they need to implement a missing command instead of simply staying silent until the missing command needs to be called. Like maybe setting up a formal ABC or Protocol. |
|
Here is another use case, narrower than the snapshot one. Editors and |
FileSystemCommands gained the query ports exists, isfile, isdir, listdir, stat, and realpath, and SubversionCommands, MercurialCommands, GITCommands, and DarcsCommands now subclass it so every implementation offers the full interface. Project.get_resource(), Project.__init__ root election, Resource.exists(), Folder.get_children(), and the resource observer ChangeIndicator no longer call os.path/os.listdir/os.stat directly: a custom fscommands object previously leaked those reads to the real filesystem. Directory enumeration and metadata errors now propagate to the caller instead of being reported as an empty result.
d68d275 to
3144b07
Compare
|
I've rebased this branch onto current master (2a29095) to resolve the conflict with the type annotations from #933. The only conflict was in |
# Conflicts: # CHANGELOG.md
Custom
fscommandsimplementations only intercept create/delete/move: every existence check, directory enumeration, stat, and realpath in project/resources/resourceobserver still goes straight toos.path/os.listdir/os.stat, so a project over a captured or virtual filesystem leaks reads to the real OS.This adds
exists/isfile/isdir/listdir/stat/realpathtoFileSystemCommands, makes the VCS commands subclass it, and routes project resource discovery, root election,Resource.exists,Folder.get_children, and the observer'sChangeIndicatorthrough the owner. Errors propagate unchanged — nothing is suppressed.projecttest: 124 passed (3 new routing tests with a recording fscommands) locally on 3.13.