Skip to content

Opening wsl2 hosted files in idea. #594

Open
@cgtarmenta

Description

@cgtarmenta

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    upstreamRelated to an upstream issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions