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

terraform: Report uninitialized workspace #84

Merged
merged 1 commit into from
May 6, 2020
Merged

Conversation

radeksimko
Copy link
Member

This improves the UX a little bit when user tries to open a directory which has not been terraform init'd.

Before

2020/05/05 10:05:46 service.go:56: Preparing new service ...
2020/05/05 10:05:46 langserver.go:65: Starting server (pid 69133) ...
...
2020/05/05 10:05:46 exec.go:114: Running /usr/local/bin/terraform ["version"] in "/Users/jamesbayer/Documents/workspace/terraform-getting-started"...
2020/05/05 10:05:46 exec.go:140: terraform run (/usr/local/bin/terraform ["version"], in "/Users/jamesbayer/Documents/workspace/terraform-getting-started", pid 69135) finished with exit code 0
2020/05/05 10:05:46 initialize.go:85: Found compatible Terraform version (0.12.24) at /usr/local/bin/terraform
2020/05/05 10:05:46 schema_storage.go:266: Adding workspace for watching: "/Users/jamesbayer/Documents/workspace/terraform-getting-started"
2020/05/05 10:05:46 watcher.go:88: Adding "/Users/jamesbayer/Documents/workspace/terraform-getting-started/.terraform/plugins/darwin_amd64/lock.json" for watching...
2020/05/05 10:05:46 schema_storage.go:107: Acquiring semaphore before retrieving schema for "/Users/jamesbayer/Documents/workspace/terraform-getting-started" ...
2020/05/05 10:05:46 schema_storage.go:116: Retrieving schemas for "/Users/jamesbayer/Documents/workspace/terraform-getting-started" ...
2020/05/05 10:05:46 exec.go:114: Running /usr/local/bin/terraform ["providers" "schema" "-json"] in "/Users/jamesbayer/Documents/workspace/terraform-getting-started"...
2020/05/05 10:05:46 rpc_logger.go:45: Error for "initialize" (ID 0): [-32098] unable to calculate hash: open /Users/jamesbayer/Documents/workspace/terraform-getting-started/.terraform/plugins/darwin_amd64/lock.json: no such file or directory
2020/05/05 10:05:46 server.go:204: Completed 1 requests [50.043298ms elapsed]
[Error - 10:05:46 AM] Server initialization failed.
  Message: unable to calculate hash: open /Users/jamesbayer/Documents/workspace/terraform-getting-started/.terraform/plugins/darwin_amd64/lock.json: no such file or directory
  Code: -32098 

After

The log messages differ slightly as this build also includes some other patches.

2020/05/06 14:11:54 service.go:59: Preparing new session ...
...
2020/05/06 14:11:54 exec.go:180: Starting /usr/local/bin/terraform ["terraform" "version"] in "/var/folders/fb/k_9ystyd08j934qcxmyv0wjc0000gp/T/"...
2020/05/06 14:11:54 exec.go:146: Waiting for command to finish ...
2020/05/06 14:11:54 exec.go:172: terraform run (/usr/local/bin/terraform ["terraform" "version"], in "/var/folders/fb/k_9ystyd08j934qcxmyv0wjc0000gp/T/", pid 68828) finished with exit code 0
2020/05/06 14:11:54 initialize.go:90: Found compatible Terraform version (0.12.24) at /usr/local/bin/terraform
2020/05/06 14:11:54 schema_storage.go:327: Adding workspace for watching: "/private/var/workspace/tf-test/github"
2020/05/06 14:11:54 watcher.go:88: Adding "/private/var/workspace/tf-test/github/.terraform/plugins/darwin_amd64/lock.json" for watching...
2020/05/06 14:11:54 schema_storage.go:120: Acquiring semaphore before retrieving schema for "/private/var/workspace/tf-test/github" ...
2020/05/06 14:11:54 schema_storage.go:129: Retrieving schemas for "/private/var/workspace/tf-test/github" ...
2020/05/06 14:11:54 rpc_logger.go:45: Error for "initialize" (ID 1): [-32098] Workspace not initialized. Please run `terraform init` in /private/var/workspace/tf-test/github
2020/05/06 14:11:54 server.go:204: Completed 1 requests [117.794116ms elapsed]
2020/05/06 14:11:54 exec.go:180: Starting /usr/local/bin/terraform ["terraform" "providers" "schema" "-json"] in "/private/var/workspace/tf-test/github"...
2020/05/06 14:11:54 server.go:469: Received 1 new requests
2020/05/06 14:11:54 server.go:165: Processing 1 requests
2020/05/06 14:11:54 server.go:223: Checking request for "shutdown":
2020/05/06 14:11:54 rpc_logger.go:29: Incoming request for "shutdown" (ID 2):
2020/05/06 14:11:54 rpc_logger.go:50: Response to "shutdown" (ID 2): null
2020/05/06 14:11:54 server.go:204: Completed 1 requests [144.872µs elapsed]
2020/05/06 14:11:54 server.go:469: Received 1 new requests
2020/05/06 14:11:54 server.go:165: Processing 1 requests
2020/05/06 14:11:54 server.go:223: Checking request for "exit":
2020/05/06 14:11:54 rpc_logger.go:29: Incoming notification for "exit":
2020/05/06 14:11:54 exec.go:146: Waiting for command to finish ...
2020/05/06 14:11:54 schema_storage.go:112: error obtaining schemas: Unable to retrieve schemas: failed to get schemas: Execution of ["terraform" "providers" "schema" "-json"] canceled.

How and whether the error from initialize is surfaced on the client depends on client implementation and we could in theory publish diagnostics to inform the user that way.

Regardless though I think we first need change the reporting of such errors to avoid blocking initialization and still provide reduced functionality - then perhaps we can publish warning informing the user of reduced functionality.
#83

@radeksimko radeksimko added the enhancement New feature or request label May 6, 2020
@radeksimko radeksimko requested a review from a team May 6, 2020 13:39
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.

LGTM

@radeksimko radeksimko merged commit 80c5aaa into master May 6, 2020
@radeksimko radeksimko deleted the f-not-initialized branch May 6, 2020 17:07
@michaelssingh
Copy link

michaelssingh commented Jun 1, 2020

I think this might have broke some things.
Consider, creating a new dir, in that dir create main.tf file:

Jun 01 09:46:44.645 DEBG Routing editor request to Route { session: "36183", language: "terraform", root: "/home/luser/dev/hack/terraform" }, module: kak_lsp::session:95
Jun 01 09:46:44.645 DEBG Spawning a new controller for Route { session: "36183", language: "terraform", root: "/home/luser/dev/hack/terraform" }, module: kak_lsp::session:117
Jun 01 09:46:44.646 INFO Starting Language server `terraform-ls serve`, module: kak_lsp::language_server_transport:21
Jun 01 09:46:44.648 DEBG To editor `36183`: lsp-get-server-initialization-options '/tmp/kak-lsp/luser/db83e86659e4a042', module: kak_lsp::editor_transport:85
Jun 01 09:46:44.655 DEBG lsp_server_initialization_options:
, module: kak_lsp::general:192
Jun 01 09:46:44.655 DEBG To server: {"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"textDocument":{"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"colorProvider":null,"completion":{"completionItem":{"documentationFormat":["plaintext"],"snippetSupport":true}},"semanticHighlightingCapabilities":{"semanticHighlighting":true}},"workspace":{"workspaceEdit":{"documentChanges":true,"resourceOperations":["create","delete","rename"]}}},"processId":36231,"rootUri":"file:///home/luser/dev/hack/terraform","trace":"off"},"id":0}, module: kak_lsp::language_server_transport:175
Jun 01 09:46:44.692 DEBG From server: {"jsonrpc":"2.0","id":0,"error":{"code":-32098,"message":"Workspace not initialized. Please run `terraform init` in /home/luser/dev/hack/terraform"}}, module: kak_lsp::language_server_transport:149
Jun 01 09:46:44.692 ERRO Error response from server: Failure { jsonrpc: Some(V2), error: Error { code: ServerError(-32098), message: "Workspace not initialized. Please run `terraform init` in /home/luser/dev/hack/terraform", data: None }, id: Num(0) }, module: kak_lsp::controller:127
Jun 01 09:46:44.692 DEBG To editor `36183`: lsp-show-error 'terraform language server error: ''Workspace not initialized. Please run `terraform init` in /home/luser/dev/hack/terraform''', module: kak_lsp::editor_transport:85

What is there to initialize? Nothing!

Consider, typing and as such triggering completion in said main.tf:

Jun 01 09:49:21.350 DEBG From editor:
session   = "36183"
client    = "client0"
buffile   = "/home/luser/dev/hack/terraform/main.tf"
filetype  = "terraform"
version   = 5
method    = "textDocument/completion"
[params.position]
line      = 1
column    = 5
[params.completion]
offset    = 1
, module: kak_lsp::editor_transport:125
Jun 01 09:49:21.350 DEBG Searching for vars starting with KAK_LSP_PROJECT_ROOT_TERRAFORM, module: kak_lsp::project_root:41
Jun 01 09:49:21.351 DEBG Routing editor request to Route { session: "36183", language: "terraform", root: "/home/luser/dev/hack/terraform" }, module: kak_lsp::session:95
Jun 01 09:49:21.351 DEBG Language server is not initialized, parking request, module: kak_lsp::controller:73
Jun 01 09:49:21.352 DEBG To editor `36183`: eval -client client0 'lsp-show-error ''Language server is not initialized, parking request''', module: kak_lsp::editor_transport:85

@radeksimko
Copy link
Member Author

@michaelssingh

What is there to initialize? Nothing!

Generally the language server needs to have data to use for completion and any other future functionality (like hover). There is not much the LS can do without it yet.

That said we shouldn't be treating the schema availability as essential and that is tracked under - #83

I'm going to lock this PR because it's unrelated to the issue being discussed. Please file a new one if you believe this isn't covered in #83 Thank you!

@hashicorp hashicorp locked as resolved and limited conversation to collaborators Jun 1, 2020
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.

4 participants