Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

watcher: Detect 'terraform init' from scratch #385

Merged
merged 1 commit into from
Feb 2, 2021
Merged

Conversation

radeksimko
Copy link
Member

@radeksimko radeksimko commented Jan 25, 2021

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

@radeksimko radeksimko added the enhancement New feature or request label Jan 25, 2021
@radeksimko radeksimko force-pushed the f-detect-new-init branch 3 times, most recently from 8f83b21 to ac40734 Compare January 26, 2021 14:21
@radeksimko radeksimko marked this pull request as ready for review January 26, 2021 14:52
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. 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.
Copy link
Contributor

@aeschright aeschright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@ghost
Copy link

ghost commented Mar 4, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the context necessary to investigate further.

@ghost ghost locked as resolved and limited conversation to collaborators Mar 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Watch prospective root modules (to detect "terraform init" from scratch)
2 participants