Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit 6daa3ac

Browse files
author
Mikhail Arkhipov
authored
Merge pull request #147 from Microsoft/reloadFix
RELEASE: Fix frequent module reloading
2 parents 4bdbb5e + 04b4b0b commit 6daa3ac

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

src/LanguageServer/Impl/PathsWatcher.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ internal sealed class PathsWatcher : IDisposable {
3333

3434
public PathsWatcher(string[] paths, Action onChanged, ILogger log) {
3535
_log = log;
36-
if (paths?.Length == 0) {
36+
paths = paths.Where(p => Path.IsPathRooted(p)).ToArray() ?? Array.Empty<string>();
37+
if (paths.Length == 0) {
3738
return;
3839
}
3940

4041
_onChanged = onChanged;
4142

42-
var list = new List<FileSystemWatcher>();
4343
var reduced = ReduceToCommonRoots(paths);
4444
foreach (var p in reduced) {
4545
try {
@@ -54,15 +54,14 @@ public PathsWatcher(string[] paths, Action onChanged, ILogger log) {
5454
try {
5555
var fsw = new System.IO.FileSystemWatcher(p) {
5656
IncludeSubdirectories = true,
57-
EnableRaisingEvents = true
57+
EnableRaisingEvents = true,
58+
NotifyFilter = NotifyFilters.FileName | NotifyFilters.DirectoryName
5859
};
5960

60-
fsw.Changed += OnChanged;
6161
fsw.Created += OnChanged;
6262
fsw.Deleted += OnChanged;
6363

6464
_disposableBag
65-
.Add(() => fsw.Changed -= OnChanged)
6665
.Add(() => fsw.Created -= OnChanged)
6766
.Add(() => fsw.Deleted -= OnChanged)
6867
.Add(() => fsw.EnableRaisingEvents = false)
@@ -84,9 +83,9 @@ private void OnChanged(object sender, FileSystemEventArgs e) {
8483

8584
private void TimerProc(object o) {
8685
lock (_lock) {
87-
if (!_changedSinceLastTick && _throttleTimer != null) {
86+
if (_changedSinceLastTick) {
8887
ThreadPool.QueueUserWorkItem(_ => _onChanged());
89-
_throttleTimer.Dispose();
88+
_throttleTimer?.Dispose();
9089
_throttleTimer = null;
9190
}
9291
_changedSinceLastTick = false;

0 commit comments

Comments
 (0)