Commit message:
gopls/internal/filewatcher: introduce filewatcher using fsnotify
The file watcher is a wrapper over the fsnotify.Watcher, expose two
channels (same as fsnotify.Watcher), an events channel and an error
channel.
The file watcher automatically converted the fsnotify.Event to
protocol.FileEvent and handles some simple filtering.
- file watcher only captures events happens to *{.go, .sum, .work, .mod}.
- file watcher ignores hidden dirs and testdata.
- file watcher only pays attention to operation Rename, Remove, Create
and Write.
- file watcher have a debouncer in place that group events together and
send them in batch.
Upon "Close()", the file watcher will close the fsnotify.Watcher, close
all channels and wait for all go routine to finish.
Race analysis, file watcher only read/write mutex guarded fields in methods:
watchDir, stopWatchDir, isDir, addEvent, sendEvents, Close().
For golang/go#74292