mrward / monodevelop-dnx-addin

.NET Core support for MonoDevelop and Xamarin Studio
MIT License
47 stars 11 forks source link

Smart file watching #24

Open fogzot opened 8 years ago

fogzot commented 8 years ago

As discussed in #19 and other issues watching the full solution tree sometimes results in too many open files errors, especially when one uses client-side package managers like npm or bower. A solution could be to watch single directories, excluding problematic ones. My idea is to:

  1. Extract project structure information from both the solution file and the top-level global.json "projects" key and use a bit of euristic (see later) to determine which subdirectories should be watched for changes.
  2. Look for exclude patterns in each subdirectory: this could be made configurable but ignoring node_modules, bower_packages and other well-known names is probably a good start.
  3. For each subdirectory that doesn't contain anything to ignore just create a single watcher.
  4. For each subdirectory that contains something to ignore creare a top-level watcher with IncludeSubdirectories set to false and then one watcher for every directory.

We will end up with more watchers than strictly necessary but, given that one usually doesn't have tens of directories inside each project, not that much more.

Does this seems sensible or am I missing something?

mrward commented 8 years ago

It would need to handle new directories that get created or new projects being added. I wonder if there is any problem creating lots of individual file watchers.

I am still tempted to just rely on the IDE detecting file changes since this feature already exists and may be simpler to implement. It also completely fixes the too many files problem.

fogzot commented 8 years ago

I fear that the IDE will not detect files added from the outside but I don't know about this part of MonoDevelop: which files exactly does it watch?

mrward commented 8 years ago

Yeah I agree it may not detect files added outside the IDE.

How often does adding files outside the IDE happen in practice? I was assuming that if you are in the IDE then you are adding new files using the IDE.

The IDE will detect files that have changed that it knows about. For example if you edit a .csproj file outside the IDE when you switch back to the IDE it knows the file has changed and will reload the project file. New files are different problem. This could be handled by rescanning the directories when the IDE receives focus again. Or maybe this is not automatic and instead the user can refresh a directory themselves in the solution window.

Right now if you add a new directory or files the solution window will not be updated even though the file watcher will detect this and be sending the files to the DNX host. However this is just something that was not yet implemented.