microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.57k stars 28.66k forks source link

File System Observer API #226131

Open tomayac opened 4 weeks ago

tomayac commented 4 weeks ago

Hey Visual Studio Code team,

This is Tom from Chrome's DevRel team. I wanted to point you at an exciting new origin trial that we run in Chrome, namely for the File System Observer API. The core idea is to help IDEs like yours with their file system operations. I think currently this happens in workspaceWatcher.ts and is based on polling. The new API could help you optimize this task:

if ('FileSystemObserver' in self) {
  // The File System Observer API is supported.

  // The callback function that gets called whenever
  // a change is detected.
  const callback = (records) => {
    for (const record of records) {
      console.log('Change detected', record);
    }
  };

  const observer = new FileSystemObserver(callback); 
  // Observe a directory recursively.
  await observer.observe(directoryHandle, {recursive: true});
}

If this is of interest, happy to help you get started. Feel free to reach out.

Cheers, Tom

bpasero commented 3 weeks ago

@tomayac thanks for reaching out, we do indeed have interest in this!

However, maybe not for our desktop experience where we need file watching support also in node.js and leverage https://github.com/parcel-bundler/watcher which is quite efficient, non-polling, leveraging OS watch mechanisms (fsevents, ReadDirectoryChangesW, inotify).

But VS Code for Web leverages the file system access API where we currently miss a way of implementing the watch method for notifying about file changes:

https://github.com/microsoft/vscode/blob/d78aaa9bed432b4407daba634816fdf67b510da5/src/vs/platform/files/browser/htmlFileSystemProvider.ts#L287-L293

Steps to try it out:

Happy to integrate it there. Is there a way to sign up to the origin trial?

tomayac commented 3 weeks ago

@tomayac thanks for reaching out, we do indeed have interest in this!

Amazing :-)

However, maybe not for our desktop experience where we need file watching support also in node.js and leverage https://github.com/parcel-bundler/watcher which is quite efficient, non-polling, leveraging OS watch mechanisms (fsevents, ReadDirectoryChangesW, inotify).

Yes, makes sense. Node.js already can do this for you.

But VS Code for Web leverages the file system access API where we currently miss a way of implementing the watch method for notifying about file changes:

https://github.com/microsoft/vscode/blob/d78aaa9bed432b4407daba634816fdf67b510da5/src/vs/platform/files/browser/htmlFileSystemProvider.ts#L287-L293

Steps to try it out:

  • open https://vscode.dev/
  • click on "Open Folder"
  • pick a local folder
  • notice how changes done outside the browser are not reflected inside the browser directly

This is the exact use case this new API proposal aims to address.

Happy to integrate it there. Is there a way to sign up to the origin trial?

Yes, just go to the sign up page and sign up for your origin https://vscode.dev/. This gives you a token. Next, follow the instructions in this article to integrate it in the app.