I am running vscode in windows on remote WSL2. I have installed HashiCorp Terraform extension, however I started getting the errors in the screenshot attached and the extension doesn’t seem to be working when I open terraform files. I have v1.0.1 installed. Does anyone know what’s going on here? Thanks!
Do you mind sharing how exactly did you open the path in VS Code?
AFAICT the message you shared above would occur if you were to access the UNC path from a Windows shell, e.g. by running
code "\\wsl$\Ubuntu-20.04\home\example" from Windows.
The recommended way is to open the shell of the Linux distro you’re using (e.g. Ubuntu) then open VS Code with the Linux path from there, such as
code /home/example . This starts the VSCode editor in Windows as a ‘client’ with the WSL VSCode Server ‘inside’ the WSL distro. As explained in the WSL tutorial:
VS Code is installing a small server on the Linux side that the desktop VS Code will then talk to. That server will then install and host extensions in WSL, so that they run in the context of the tools and frameworks installed in WSL. In other words, your language extensions will run against the tools and frameworks installed in WSL, not against what is installed on the Windows side, as it should for the proper development experience.
We plan to improve the error message as part of Better guide WSL users opening UNC `\\wsl$\` paths · Issue #656 · hashicorp/terraform-ls · GitHub
Thanks @radeksimko , I opened vscode from inside wsl and I made sure the the lower left coroner shows I am connected to WSL:
however now I am getting the following error message:
Just to mention that I am opening an entire directory that contains multiple sub-dirs and different file types, not just terraform.
ah nvm, I went to the extension section on vscode and a new button
install for WSL showed up next to the terraform extension, clicking and reloading vscode solved the problem.
With regards to the other error you shared (“Editing a single file is not yet supported”) - We’re actively working on introducing a limited support for editing single files, but still recommend (and will continue recommending) opening whole folders instead.
For example, if you use a terminal to open VS Code, you’d run
code /path/to/folder instead of
code /path/to/folder/main.tf, or similarly you would drag a whole folder into VS Code GUI instead of a single file.