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

Opening wsl2 hosted files in idea. #594

Open
cgtarmenta opened this issue Sep 2, 2024 · 1 comment
Open

Opening wsl2 hosted files in idea. #594

cgtarmenta opened this issue Sep 2, 2024 · 1 comment
Labels
upstream Related to an upstream issue

Comments

@cgtarmenta
Copy link

I know this is something extremely low-priority guys, but some of us, clone repos inside of wsl2 env, and use idea from windows.

So if I configure idea as editor doing this:

vueDevTools({
    launchEditor: 'idea',
}),

In first instance, the plugin fails as it can't find idea in the path, so I made a /usr/local/bin bash script to pass the commands to Windows idea

#!/bin/bash
/mnt/c/Windows/explorer.exe 'C:\Users\MyWindowsUser\AppData\Local\JetBrains\Toolbox\scripts\idea.cmd' "$@"

This worked but now the plugin is trying to open files using Ubuntu paths like /home/ubuntu/path/to/my/repo/App.vue

So I've ended up doing some sorcery

#!/bin/bash
#  echo "Original args: $@" 1>&2
# Function to decode URL-encoded strings
urldecode() {
    local url_encoded="${1//+/ }"
    printf '%b' "${url_encoded//%/\\x}"
}

# Function to convert WSL path to Windows path
wsl_to_windows_path() {
    wsl_path="$1"
    windows_path=$(wslpath -w "$wsl_path")
    echo "$windows_path"
}

# Define the IntelliJ IDEA script path directly as a Windows path
idea_cmd="C:\\Users\\$(cmd.exe /C echo %USERNAME% | tr -d '\r')\\AppData\\Local\\JetBrains\\Toolbox\\scripts\\idea.cmd"

# Iterate over all arguments and decode and convert paths if they exist
args=()
for arg in "$@"; do
    # echo "Original arg: $arg" 1>&2
    decoded_arg=$(urldecode "$arg")
    # echo "Decoded arg: $decoded_arg" 1>&2
    if [[ "$decoded_arg" == /* ]]; then
        # Extract the path after 'file=' and convert it
        wsl_path="${decoded_arg#file=}"
        wsl_path="${wsl_path%%:*}"  # Strip line:column info (e.g., :0:0)
        windows_arg=$(wsl_to_windows_path "$wsl_path")
        # echo "Converted path: $windows_arg" 1>&2
        args+=("\"$windows_arg\"")
    else
        args+=("$decoded_arg")
    fi
done
# Combine arguments into a single string for correct grouping
combined_args=$(printf "%s " "${args[@]}")

# Print final arguments for debugging
echo "opening: ${combined_args}" 1>&2

# Call the IntelliJ IDEA script with the translated paths using Windows paths
eval "cmd.exe /C  '$idea_cmd ${combined_args}' 1>&2"

It is ugly and dirty, but it works and now I can open files from your marvelous plugin.

Someone could make this kind of conversion as part of the plugin. If nobody picks this glove, I'll try to make a PR but it can take some time for that.

@alexzhang1030
Copy link
Member

Related yyx990803/launch-editor#72, upstream issue

@alexzhang1030 alexzhang1030 added the upstream Related to an upstream issue label Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upstream Related to an upstream issue
Projects
None yet
Development

No branches or pull requests

2 participants