Skip to content

WIP - Add IFileWatcherService so we can enable VS Code File Watcher for dotnet-project-system-vscode services #9662

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

LittleLittleCloud
Copy link
Contributor

@LittleLittleCloud LittleLittleCloud commented May 14, 2025

What does this PR do

This PR adds a new public interface: IFileWatcherService, which will be consumed by LaunchSettingsProvider.

This PR also implement that interface for SimpleFileWatcher class and export it as MEF component.

Why

This provides an opportunity to consume VsCodeFileWatchService in LaunchProfileHandlerAggregator for vs-green if Prefer Visual Studio Code File System Watchers option is enabled, which could be helpful to reduce the number of inotify watches on linux when user opens a large project.

relevant issues

Microsoft Reviewers: Open in CodeFlow

@LittleLittleCloud LittleLittleCloud requested a review from a team as a code owner May 14, 2025 23:27
@LittleLittleCloud LittleLittleCloud changed the title Add IFileWatcherService in order to enable VS Code File Watcher for dotnet-project-system-vscode services Add IFileWatcherService so we can enable VS Code File Watcher for dotnet-project-system-vscode services May 14, 2025
namespace Microsoft.VisualStudio.IO;

/// <summary>
/// Simple wrapper around the FileSystemWatcher.
/// </summary>
internal sealed class SimpleFileWatcher : IDisposable
[Export(typeof(IFileWatcherService))]
[Order(Order.Lowest)]
Copy link
Contributor Author

@LittleLittleCloud LittleLittleCloud May 14, 2025

Choose a reason for hiding this comment

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

@drewnoakes

How is Order works here,, If I implement another IFileWatcherService with a higher order inside dotnet-project-system-vscode, will that be used to create LaunchSettingProvider instead?

Copy link
Member

Choose a reason for hiding this comment

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

[Order] is metadata that a MEF consumer can use to differentiate between imports when there are multiple available. In this PR I don't see any ImportsMany (or similar constructs like OrderPrecedenceImportCollection), so I don't think Order is needed.

@LittleLittleCloud LittleLittleCloud changed the title Add IFileWatcherService so we can enable VS Code File Watcher for dotnet-project-system-vscode services WIP-Add IFileWatcherService so we can enable VS Code File Watcher for dotnet-project-system-vscode services May 15, 2025
@LittleLittleCloud LittleLittleCloud changed the title WIP-Add IFileWatcherService so we can enable VS Code File Watcher for dotnet-project-system-vscode services WIP - Add IFileWatcherService so we can enable VS Code File Watcher for dotnet-project-system-vscode services May 15, 2025
Comment on lines +24 to +28
public SimpleFileWatcher(
string dirToWatch,
bool includeSubDirs,
NotifyFilters notifyFilters,
string fileFilter)
Copy link
Member

Choose a reason for hiding this comment

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

This approach isn't likely to work. MEF won't be able to call this constructor. Instead it'll use the default (parameterless) constructor, which don't instantiate the _fileWatcher, meaning that no watching will take place.

This watcher doesn't feel like something that should be a MEF service. Its construction requires a file path, which isn't something that MEF would know about.

Comment on lines +7 to +14
public interface IFileWatcherService : IDisposable
{
event EventHandler<FileWatcherEventArgs> OnDidCreate;

event EventHandler<FileWatcherEventArgs> OnDidChange;

event EventHandler<FileWatcherEventArgs> OnDidDelete;
}
Copy link
Member

Choose a reason for hiding this comment

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

My understanding of the high-level goal of this PR is that it becomes possible to abstract away exactly which file system watcher implementation is used.

However the construction of that watcher requires data that's not available via MEF, such as the path of the file/directory.

Instead, I think this needs to be exposed as a factory that can construct a watcher.

Something like:

[ProjectSystemContract(...)]
public interface IFileWatcherProvider
{
    IDisposable Watch(
        string dirToWatch,
        bool includeSubDirs,
        NotifyFilters notifyFilters,
        string fileFilter,
        FileSystemEventHandler? handler,
        RenamedEventHandler? renameHandler);
}

Though your use of a DataContract below suggests to me that you're potentially wanting to marshal this between processes via RPC, which would require a slightly different API.

Can you explain more about the high-level interaction between repositories and processes?

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.

2 participants