Vscode-remote-release: [Feature Request] Set Remote WSL as default run option without depending on the workspace

Created on 15 Feb 2020  路  8Comments  路  Source: microsoft/vscode-remote-release

Hello!

  • I know that the workspace can do it, but even if I set "window.restoreWindows": "one" and "window.restoreWindows": "all", it opens automatically the Remote WSL, but if you open any file or any folder, it will open the Remote WSL, but not with any clicked file or folder.
  • I know that it is possible to open VSCode with Remote WSL automatically from the WSL terminal, but I want to open VSCode with Remote WSL automatically and normally _without from_ terminal, with any file or any folder.

I would like to suggest that make it possible to set Remote WSL as default run option when I open VSCode. Referring to the subreddit topic Can I make Remote WSL as default run option?.

References

feature-request wsl

Most helpful comment

So, I've made a go script that will automatically detect the path and launch VSCode smartly using "Open with Code".

package main

import (
    "fmt"
    "os"
    "os/exec"
    "strings"
)

func convertPath(path string) string {
    formatted := strings.Trim(path, "\\\\wsl$\\Ubuntu")
    formatted = strings.ReplaceAll(formatted, "\\", "/")
    return formatted
}

func main() {
    path := os.Args[1]
    localPath := os.Getenv("LOCALAPPDATA")
    var finalArguments []string
    if strings.HasPrefix(path, "\\\\wsl$") {
        finalArguments = append(finalArguments, "--remote", "wsl+ubuntu", convertPath(path))
    } else {
        finalArguments = append(finalArguments, path)
    }
    cmd := exec.Command(fmt.Sprintf("%v\\Programs\\Microsoft VS Code\\code.exe", localPath), finalArguments...)
    cmd.Run()
}

I built it using go build -ldflags -H=windowsgui to hide the terminal window. You can get the exe file here.
Just edit the following registries

  • Computer\HKEY_CLASSES_ROOT\Directory\Background\shell\VSCode\command -> "C:\users\path\to\opencode.exe" "%V"
  • Computer\HKEY_CLASSES_ROOT\Directory\shell\VSCode\command -> "C:\users\path\to\opencode.exe" "%V"

All 8 comments

This is a very useful feature because I only install python in wsl2 . I have to change to windows terminal , enter the directory and code xxx.py when I want to open and run a python file in windows .

Yes. This will be a very useful feature to have. Just having the file and folder context option "Open with Code" recognize the user is opening at a path like \\wsl$\Ubuntu\home\ and opening VSCode with Remote WSL would be an awesome feature to have.

So, I've made a go script that will automatically detect the path and launch VSCode smartly using "Open with Code".

package main

import (
    "fmt"
    "os"
    "os/exec"
    "strings"
)

func convertPath(path string) string {
    formatted := strings.Trim(path, "\\\\wsl$\\Ubuntu")
    formatted = strings.ReplaceAll(formatted, "\\", "/")
    return formatted
}

func main() {
    path := os.Args[1]
    localPath := os.Getenv("LOCALAPPDATA")
    var finalArguments []string
    if strings.HasPrefix(path, "\\\\wsl$") {
        finalArguments = append(finalArguments, "--remote", "wsl+ubuntu", convertPath(path))
    } else {
        finalArguments = append(finalArguments, path)
    }
    cmd := exec.Command(fmt.Sprintf("%v\\Programs\\Microsoft VS Code\\code.exe", localPath), finalArguments...)
    cmd.Run()
}

I built it using go build -ldflags -H=windowsgui to hide the terminal window. You can get the exe file here.
Just edit the following registries

  • Computer\HKEY_CLASSES_ROOT\Directory\Background\shell\VSCode\command -> "C:\users\path\to\opencode.exe" "%V"
  • Computer\HKEY_CLASSES_ROOT\Directory\shell\VSCode\command -> "C:\users\path\to\opencode.exe" "%V"


This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 10 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!


This feature request has not yet received the 10 community upvotes it takes to make to our backlog. 10 days to go. To learn more about how we handle feature requests, please see our documentation.

Happy Coding


:slightly_frowning_face: In the last 60 days, this feature request has received less than 10 community upvotes and we closed it. Still a big Thank You to you for taking the time to create this issue! To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

@sbatten, please, can you re-open it?

We currently have no plans to work on the suggested feature. Please have a look at the solution proposed in https://github.com/microsoft/vscode-remote-release/issues/2365#issuecomment-695937925

Was this page helpful?
0 / 5 - 0 ratings