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

Use File System Events To Monitor Workspace #1365

Merged
merged 3 commits into from
Jul 1, 2023

Conversation

thecoolwinter
Copy link
Collaborator

@thecoolwinter thecoolwinter commented Jul 1, 2023

Description

Removes the existing file system watching code and replaces it with MacOS's File System Events API. This API isn't bound by process file descriptor limits and is built for recursive directory monitoring. In place of file descriptors it uses kernel updates to notify our process that events have occurred.

Changes in detail:

  • Removes all references to watcherCode from CEWorkspaceFile
  • Removes all unnecessary subjects, publishers, and watcher code from CEWorkspaceFileManager.
  • Adds an observer API to the CEWorkspaceFileManager that allows more than one subscriber to listen for updates to the file tree.
    • This has been designed for multiple observers. So if we need to monitor file changes in the future with another API like extensions at the same time as the project navigator, that's supported. It also further decouples this file management from UI code through delegation.
  • Modifies tests to use the new observation method
  • Adds a DirectoryEventStream class.
    • This class uses the afore mentioned file system events API and converts the raw response to some more swift-like data.
    • On initialization it starts the stream. By default it will use a 0.05s event debounce and queue events to be received on the default qos dispatch queue.
    • 0.05s was chosen after testing with larger and smaller sizes to find a time that feels snappy while reducing extra events.
    • The stream can be listened to by setting a completion handler on the stream object which will be called whenever a valid event is found. See the FSEvents enum for more info on valid events. The stream will send events on a background thread, so any UI related code will have to be dispatched by the receiver.

This has implications for @Wouter01's branch getting rid of CEWorkspaceFile. Thankfully, most of the changes here won't effect that PR besides removing some of the work halfway done there. As discussed on Discord, we'll merge this monitoring system in favor of the NSDocument subclassing Wouter was doing and perform any updates needed to use the new Resource protocol on that branch.

Related Issues

Checklist

  • I read and understood the contributing guide as well as the code of conduct
  • The issues this PR addresses are related to each other
  • My changes generate no new warnings
  • My code builds and runs on my machine
  • My changes are all related to the related issue above
  • I documented my code

Screenshots

Moving files is snappy and updates consistently (even moving a large project's node_modules folder had little to no noticeable effect on this):

Screen.Recording.2023-06-29.at.11.30.19.PM.mov

Files created/modified/deleted in the built-in terminal or by other applications update quickly and consistently:

Screen.Recording.2023-06-30.at.9.27.50.PM.mov

Copy link
Collaborator

@austincondiff austincondiff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! 👏

@austincondiff austincondiff merged commit 44063ca into CodeEditApp:main Jul 1, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐞 Missing reload folder contents in navigation pane 🐞 Can't create a New File
3 participants