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

Enable opening a single Terraform file #843

Merged
merged 7 commits into from
Apr 7, 2022
Merged

Enable opening a single Terraform file #843

merged 7 commits into from
Apr 7, 2022

Conversation

jpogran
Copy link
Contributor

@jpogran jpogran commented Mar 31, 2022

This PR enables single file support by skipping configuring the file watcher with information about what folders to watch. This leaves the watcher with little environment information, but still provides enough functionality to edit a single file. This suits the common transitory workflows for single files. For example, opening a file just to review contents or to make a few line changes without needing the context from an entire Terraform project.

A warning is shown to the user when a single file is opened, explaining that some capabilities may be reduced when editing a single file, and to open a directory to regain full editor functionality. This is to warn the user that while we enable this workflow, we don't encourage it because of the tradeoffs we currently have to do. This warning can be disabled by setting ignoreSingleFileWarning to true.

@jpogran jpogran self-assigned this Mar 31, 2022
@jpogran jpogran added the enhancement New feature or request label Mar 31, 2022
@jpogran jpogran added this to the v0.27.0 milestone Mar 31, 2022
@jpogran jpogran linked an issue Mar 31, 2022 that may be closed by this pull request
Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

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

I gave it a try and it works pretty well! 👍🏻

I left some naming suggestions in-line and there are now some conflicts to resolve after merging #839

Enqueueing a new directory was

walker.EnqueuePath(modPath)

and is now

stateStore.WalkerPaths.EnqueueDir(dirUri)

i.e. the enqueueing happens on the state store (memdb) as opposed to the walker itself.

Secondly there are now two walkers (svc.closedDirWalker & svc.openDirWalker) so some setup methods previously called on svc.walker now need to be called on both instead.

I am happy to assist with the rebasing and resolution of conflicts, if you like - feel free to ping me and I can jump on Zoom with you!

internal/langserver/handlers/initialize.go Outdated Show resolved Hide resolved
internal/langserver/handlers/initialize.go Outdated Show resolved Hide resolved
internal/langserver/handlers/initialize.go Outdated Show resolved Hide resolved
internal/langserver/handlers/initialize.go Outdated Show resolved Hide resolved
internal/langserver/handlers/initialize.go Outdated Show resolved Hide resolved
Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

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

One remaining error handling + commented out code, otherwise LGTM

jpogran and others added 3 commits April 7, 2022 11:51
Co-authored-by: Radek Simko <radek.simko@gmail.com>
@jpogran jpogran marked this pull request as ready for review April 7, 2022 15:53
@jpogran jpogran requested review from a team and radeksimko and removed request for a team April 7, 2022 16:08
Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

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

Just proposed a small change to the warning message, but LGTM otherwise 🚀

Tested in combination with hashicorp/vscode-terraform#1031 and it works great!
magic

internal/langserver/handlers/initialize.go Outdated Show resolved Hide resolved
Co-authored-by: Radek Simko <radek.simko@gmail.com>
@jpogran jpogran changed the title Single File Support Enable opening a single Terraform file Apr 7, 2022
@jpogran jpogran merged commit bd7aa97 into main Apr 7, 2022
@jpogran jpogran deleted the single_file_support branch April 7, 2022 16:52
jpogran added a commit to hashicorp/vscode-terraform that referenced this pull request Apr 7, 2022
Adds the terraform-ls setting that controls whether warnings are shown when editing single Terraform files.

Works with hashicorp/terraform-ls#843
@github-actions
Copy link

This functionality has been released in v0.27.0 of the language server.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

I'm going to lock this pull request 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 related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 15, 2022
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.

Support single files and parent (non-Terraform) folders
2 participants