watcher: Detect 'terraform init' from scratch #385
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a bigger change than perhaps expected but I was not able to come up with any decent way of splitting it up.
As mentioned in one in-line comment, there is currently no reliable and efficient way of watching a directory recursively in Go. See fsnotify/fsnotify#18 There are some alternative solutions, but they either involve cgo or don't actually use any "event API" of the underlying OS but repeatedly do filewalk.
Previously we watched individual manifest and lock file of a module and we can't watch for creation of these files in a directory which doesn't exist yet. Therefore it was decided to instead watch the relevant parent directories and add relevant nested directories on creation and/or walk the hierarchy of the newly created dir. This creates even more places from where parts of module can be (re)loaded (walker, watcher, handlers), which would be hard to accommodate in the old design.
Therefore a mechanism for queueing all module operations was created.
This allows for a naive deduplication of operations (we don't run the same operation on the same module if it's already queued) and also allows us to report progress more easily in the future.
Finally this design also allows any caller to decide whether run an operation synchronously or asynchronously. e.g. We can wait for a module to be parsed in textDocument/didChange handler.
Closes #222