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

Doubly-unescaped URI causing workspace to be ignored #655

Closed
CraigStuntzWillowTree opened this issue Sep 15, 2021 · 9 comments
Closed

Doubly-unescaped URI causing workspace to be ignored #655

CraigStuntzWillowTree opened this issue Sep 15, 2021 · 9 comments
Labels
bug Something isn't working text-synchronization https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocum
Milestone

Comments

@CraigStuntzWillowTree
Copy link

Versions

This bug is reproducible in:

  • [ X ] the latest version of the extension (below)
  • [ X ] the latest version of the language server (below)

Extension

v2.14.0

Language Server

2021/09/13 16:25:30 serve_command.go:162: Starting terraform-ls 0.21.0

VS Code

Version: 1.59.1

Operating System

macOS 11.6

Terraform Version

v0.14.7

Steps To Reproduce

Run VS Code.
See dialog box pop up with the error displayed.

image

Ignoring workspace folder file:///Users/craig/Documents/ab/AB%2520Manager%2520Portal: lstat /Users/craig/Documents/ab/AB Manager Portal: no such file or directory. This is most likely bug, please report it.

The folder does exist (see screenshot). However, the displayed path is incorrect %2520 instead of %20

Expected Behavior

No error

Actual Behavior

Error displayed.

@radeksimko
Copy link
Member

radeksimko commented Sep 15, 2021

Thank you for the report, it looks like we encode the URI twice somewhere.

At least that is my guess since %20 becomes %2520 when encoded.

@radeksimko radeksimko changed the title lstat <path>: no such file or directory. This is most likely bug, please report it. Double-encoded workspace folder URIs Sep 15, 2021
@jpogran
Copy link
Contributor

jpogran commented Sep 15, 2021

@CraigStuntzWillowTree can you post a short example folder structure? It looks like the VS Code terminal prompt shows %20 instead of a space. I haven't seen VS Code do that before. I'm interested in trying to reproduce that locally. Also, what OS are you using (I assume some nix distro, since I see fish being used)?

@CraigStuntzWillowTree
Copy link
Author

Regarding %20 in the shell prompt, that's just my shell (fish).

I am using macOS 11.6. I have changed the default shell to fish.

A short example folder structure (edited for length):

~/D/a/AB%20Manager%20Portal (main|✔) $ pwd
/Users/craig/Documents/ab/AB%20Manager%20Portal
~/D/a/AB%20Manager%20Portal (main|✔) $ tree -d -L 2 -I node_modules
.
├── api
│   ├── build
│   ├── dist
│   ├── docs
│   └── src
├── infrastructure
│   ├── sql
│   └── terraform
└── testsuite
    ├── Factories
    ├── locust-load-tests
    ├── mocks
    ├── models
    ├── pages
    └── tests

@CraigStuntzWillowTree
Copy link
Author

Hmm, no, I just looked at the folder name in Finder and it's literally AB%20Manager%20Portal. I guess git assigned that when I cloned the repository. So my apologies for the misleading comment above; it's not fish that renders it that way; it's literally the name of the folder.

@jpogran
Copy link
Contributor

jpogran commented Sep 16, 2021

Thanks for finding that out, that explains where the initial encoding is coming from. I'm not sure there is something for us to do here, we can't know to un-encode the space so we can re-encode it to a URI later. We might have to think on this.

@radeksimko radeksimko changed the title Double-encoded workspace folder URIs Ignoring workspace folder: no such file or directory Sep 28, 2021
@radeksimko
Copy link
Member

FWIW I was able to reproduce this by creating and opening a folder with literal %20 in the name (on macOS 10.15.7).

I believe the likely root cause here is that we unescape paths after parsing the URIs in the language server:

return url.PathUnescape(u.Path)

I'd need to do a bit more testing, but I'm guessing that url.ParseRequestURI already does some unescaping and so we do it twice unnecessarily.

Either way this error is coming from LS which is where we may be able to fix it, so I'm going to transfer the issue there.

@radeksimko radeksimko transferred this issue from hashicorp/vscode-terraform Sep 28, 2021
@radeksimko radeksimko added the bug Something isn't working label Sep 28, 2021
@radeksimko radeksimko changed the title Ignoring workspace folder: no such file or directory Doubly-unescaped URI causing workspace to be ignored Sep 28, 2021
@radeksimko radeksimko added the text-synchronization https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocum label Sep 30, 2021
@radeksimko radeksimko added this to the v0.26.0 milestone Mar 1, 2022
@radeksimko
Copy link
Member

We made some significant changes to how URIs are parsed as part of #771

This means that we should no longer be double-escaping or double-unescaping any URIs.

That said URI escape sequences such as %20 are generally problematic and don't seem to play well with Terraform's other internals, or possibly with Windows FS - or the part of Windows FS API which Go interacts with. As you can see below, terraform init of a module with source = "./With%20Escaped%20Spaces" will return error.

2022-03-14 14 41 51

That said the language server can now provide IntelliSense within the module, assuming that is a stand-alone module which - for any reason - still has %20 in the path.
2022-03-14 14 51 21

@github-actions
Copy link

This functionality has been released in v0.26.0 of the language server.
If you use the official Terraform VS Code extension, it will prompt you to upgrade to this version automatically upon next launch or within the next 24 hours.

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 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 details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working text-synchronization https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocum
Projects
None yet
Development

No branches or pull requests

3 participants