Turn of file watcher programmatically on a few folders in the projects via a plugin.

Hi All,

Is there a way to progrmatically turn of file watcher for certain roots in Intelllij (via a plugin)/ some setting already present ?. There are a few folders in my project (which contain various file types, hence filtering out by file types is not a option here), which has frequently changing files and causes the IDE to hang. I tried placing one of the folders outside the project sturcture and the IDE hangs have stopped. I was wondering if I could still keep the folders in the project, but turn of file watcher for it.

In particular I was looking for the following:
1. I realised that there is a method I could use in  LocalFileSystemImpl - removeWatchedRoots. But this is expecting a list of WatchRequests, how do I get the WatchRequest easily given the folder path for passing to this method.
2. On project initialization, when is the best time to invoke removeWatchedRoots for this folder. I want the project to initialize normally and indexing complete on initialization and then eventually turn off the watcher on this folder.

Would appreciate any other tips or suggestions.

Thanks
-Harani

5 comments
Comment actions Permalink

No, there is no way to do this at the moment.

Have you tried to mark these roots as excluded (in Project Structure | module | Sources)?

0
Comment actions Permalink

Yes, I tried marking them as excluded via the intellij iml file, - <excludeFolder> option. But would this exclude them only from indexing or even from file watcher scanning? [Update: I noticed that the folders and files under them are still watched even after marking them as excluded]

Alternatively is there an easy way to turn off NativeFileWatcherImpl programatically/via config? I can then implement a custom file watcher using plugabble file watcher extension point which would filter out unwanted folders. Or Alternatively I can modify the NativeFileWatcherImpl to accept blacklisting folders via settings and upstream these changes. What do you suggest is the best solution?

0
Comment actions Permalink

Right, excluded directories are watched but not indexed - I guess it's indexing which consumes all the CPU time and makes the IDE unresponsive?

NativeFileWatcherImpl can be turned off by setting the "idea.filewatcher.disabled=true". This can be done programmatically, but only before the LocalFileSystem app component is initialized (which is AFAIK impossible to achieve from a plugin).

0
Comment actions Permalink

I have added two new methods to LocalFileSystem -> shutDownFileWatcher() , startupFileWatcher() which would invoke the startup and shutdown methods in the FileWatcher. I am interested in upstreaming the changes and wanted to know the best way to do so. This is mainly because LocalFileSystemImpl, LocalFileSystemBase and FileWatcher are not directly accessible in a plugin.

0
Comment actions Permalink

The best way is submitting a pull request to https://github.com/JetBrains/intellij-community/.

In this case, though, the patch would be declined. The IDE hanging on a directory update is a bug which should be investigated and fixed. So, it would be better if you reproduce the hanging, take 2-3 thread dumps, and file an issue to the tracker.

0

Please sign in to leave a comment.