Skip to content

Commit

Permalink
Alert on wsl.localhost Path (hashicorp#1522)
Browse files Browse the repository at this point in the history
This adds path detection for network WSL paths to warn the user to open the path in WSL instead.

A user can open a WSL path directly using the network mount path, which results in opening inside the host VS Code instance instead of inside the WSL instance. This is a problem for terraform-ls, which can't resolve the network paths correctly.
  • Loading branch information
jpogran authored Dec 20, 2023
1 parent a2e542e commit a5ff862
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 9 additions & 1 deletion internal/uri/uri.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,5 +206,13 @@ func IsWSLURI(uri string) bool {
return false
}

return u.Scheme == "file" && u.Host == "wsl$"
if u.Scheme == "file" && u.Host == "wsl$" {
return true
}

if u.Scheme == "file" && u.Host == "wsl.localhost" {
return true
}

return false
}
5 changes: 5 additions & 0 deletions internal/uri/uri_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ func TestIsWSLURI(t *testing.T) {
uri: `file://wsl%24/Ubuntu/home/james/some/path`,
want: true,
},
{
name: "Localhost WSL file path should return true",
uri: `file://wsl.localhost/Ubuntu/home/james/foo`,
want: true,
},
{
name: "Regular file path should return false",
uri: `file://C:/foo/james/foo`,
Expand Down

0 comments on commit a5ff862

Please sign in to comment.