Vscode-terraform: VS Code Folders should have isolated language server context

Created on 11 Jul 2020  ยท  11Comments  ยท  Source: hashicorp/vscode-terraform

I am unsure if this is at all duplicate of #417 since we don't have enough details there, but I managed to reproduce a bug with a great help of a community member on Discourse.

This could also be solved by https://github.com/hashicorp/terraform-ls/issues/179 but I think if we _know_ that two folders just aren't related to each other I think we just shouldn't even attempt to be cross-linking them in any way, i.e. these shouldn't share the same language server session.


Hierarchy

.
|-- first
    `-- .terraform
`-- second
    `-- .terraform

Steps to reproduce

  1. Create a hierarchy of two (initialized) root modules as above
  2. Open first in VS Code, e.g. via code first in the terminal
  3. Right click in the Explorer -> Add Folder to Workspace
  4. Pick second folder

Actual behaviour

textDocument/didOpen was sent to the server, which looked up first root module as a candidate for second, because they share the same LS session.

Expected behaviour

New language server session or process is launched for second folder and initialize request is sent, which triggers an isolated discovery of root module(s) within second.

We could also leverage workspace/workspaceFolders, but I am afraid that might require some more significant changes on the server side. Also workspace/workspaceFolders is opt-in per LSP and when it isn't supported by the server then most clients (those I had chance to try) just launch isolated session and send new initialize request, so I think the extension should just mimic this behaviour for now.

bug

All 11 comments

This also happens (for me) when I have a project with multiple tf directories:

Even if I open vscode inside the tf-000-management directory, I still get the 'no root module found' error.

โฏ tree -a -d
.
|-- modules
|   `-- azopsreference
|-- tf-000-management
|   `-- .terraform
|       |-- modules
|       `-- plugins
|           `-- linux_amd64
`-- tf-001-connectivity
    `-- .terraform
        `-- plugins
            `-- linux_amd64

@matt-FFFFFF I believe that "no root module found" is generally unrelated to this bug. The way this bug would be experienced by the end user is in fact by finding either incorrect or more than 1 root module.

I would be curious to see the log though, if you don't mind sharing it - that might help me understand why it isn't being discovered - see https://github.com/hashicorp/terraform-ls/blob/master/docs/TROUBLESHOOTING.md for how to set up logging.

Apologies. Having searched again I can see that my issue is already reported.

@matt-FFFFFF No worries, there's a number of reports with "no root module found" message, but they may each have different root cause - which is why I'd really appreciate looking at the log.

Sure. Getting them now

Once you have the logs then this may be the best place for continuing the discussion: https://github.com/hashicorp/terraform-ls/issues/221

Typically. It's not doing it now... Will report in that issue when I get something

For reference, here's the VSCode example on handling multiple workspace folders: https://github.com/microsoft/vscode-extension-samples/tree/master/lsp-multi-server-sample

I think this is related and/or a duplicate of #330

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fcatacut picture fcatacut  ยท  5Comments

sugarraysam picture sugarraysam  ยท  4Comments

QuinnStevens picture QuinnStevens  ยท  6Comments

mdschweda picture mdschweda  ยท  3Comments

okgolove picture okgolove  ยท  4Comments