-
Notifications
You must be signed in to change notification settings - Fork 396
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
base: main
Are you sure you want to change the base?
Conversation
namespace Microsoft.VisualStudio.IO; | ||
|
||
/// <summary> | ||
/// Simple wrapper around the FileSystemWatcher. | ||
/// </summary> | ||
internal sealed class SimpleFileWatcher : IDisposable | ||
[Export(typeof(IFileWatcherService))] | ||
[Order(Order.Lowest)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
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.
public SimpleFileWatcher( | ||
string dirToWatch, | ||
bool includeSubDirs, | ||
NotifyFilters notifyFilters, | ||
string fileFilter) |
There was a problem hiding this comment.
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.
public interface IFileWatcherService : IDisposable | ||
{ | ||
event EventHandler<FileWatcherEventArgs> OnDidCreate; | ||
|
||
event EventHandler<FileWatcherEventArgs> OnDidChange; | ||
|
||
event EventHandler<FileWatcherEventArgs> OnDidDelete; | ||
} |
There was a problem hiding this comment.
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?
What does this PR do
This PR adds a new public interface:
IFileWatcherService
, which will be consumed byLaunchSettingsProvider
.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 ifPrefer 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