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

Remove command prefix #1075

Merged
merged 4 commits into from
Apr 27, 2022
Merged

Remove command prefix #1075

merged 4 commits into from
Apr 27, 2022

Conversation

jpogran
Copy link
Contributor

@jpogran jpogran commented Apr 25, 2022

This removes generating a command prefix when registering commands for the language client connecting to terraform-ls.

Previously the extension would create a LanguageClient/terraform-ls pair per 'folder' in a workspace. This means there was a terraform-ls process per folder to keep track of. The hashicorp/terraform-ls#502 PR enabled a single terraform-ls process to handle multi-folder workspaces, which meant we could refactor the extension In #845 to use a single LanguageClient instance. A leftover from the original design was a prefix for commands registered between terraform-ls and the client. This ensured unique command IDs when multiple clients were present, but is no longer necessary with a single language client.

Acceptance tests:

  • Open a single folder and use any LS based commands
  • Open a single folder, then use Add Folder to workspace to open a multi-folder workspace
  • Open a multi-folder workspace directly using a workspace file like something.code-workspace
  • In any example, open one of the Module Views, wait for items to show up, then close editor (do not close views). Then re-open editor. The Module views should show a progress bar until the LS is ready and responds with data, without error.

In each case, the extension should start with no errors. When adding additional folders to the workspace or when opening a mult-folder workspace directly, there should be no errors regarding duplicate commands.

@jpogran jpogran added this to the 2.23.0 milestone Apr 25, 2022
@jpogran jpogran self-assigned this Apr 25, 2022
jpogran added 4 commits April 26, 2022 10:28
This removes generating a command prefix for the language client connecting to terraform-ls. This also removes registering prefixed commands to terraform-ls.
@jpogran jpogran force-pushed the remove-command-prefix branch from 7ab7287 to f60fba0 Compare April 26, 2022 17:23
@jpogran jpogran marked this pull request as ready for review April 27, 2022 13:05
@jpogran jpogran requested a review from a team as a code owner April 27, 2022 13:05
Copy link
Member

@dbanck dbanck left a comment

Choose a reason for hiding this comment

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

LGTM 👍

I wasn't able to reproduce any error cases we encountered in the past :)

@jpogran jpogran merged commit ba4fa5f into main Apr 27, 2022
@jpogran jpogran deleted the remove-command-prefix branch April 27, 2022 14:36
jpogran added a commit that referenced this pull request Apr 28, 2022
This extracts the LanguageClient creation from ClientHandler and puts it directly inside the activation point.

In order to implement hashicorp/terraform-ls#722 we need to add a new StaticFeature to register a client-side command for terraform-ls to call when it knows the `terraform.providers` view needs to be refreshed.

StaticFeatures are registered using the LanguageClient.registerFeature method, which means the ClientHandler class needs to create the StaticFeature. The StaticFeature needs both the LanguageClient and `terraform.providers` view created before it can be initialized. The LanguageClient is created by the ClientHandler class. This all results in a cyclic dependency.

We could resolve this cyclic dependency by adding more responsibility to ClientHandler, but this introduces more complexity to the class. This will become increasingly hard to deal with as more aspects like StaticFeature are added.

We resolve this by extracting the creation of LanguageClient and moving dependent features like the StaticFeatures to the main activation method. This puts all the parts that rely on each other in the same place where the data needed is located to make decisions about whether they are activated or not.

This builds on work done in:

- #1073
- #1074
- #1075
- #1079
@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 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants