rubyide / vscode-ruby

Provides Ruby language and debugging support for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=rebornix.Ruby
MIT License
1.26k stars 286 forks source link

Windows subsystem for linux support #336

Open fastsyrup opened 6 years ago

fastsyrup commented 6 years ago

Hi,

It would be great if you would support launching and debugging rails using the windows subsystem for linux (https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux) , since rails there is much faster than on native windows...

What do you think?

Best regards and thanks in advance!

lpessoa commented 6 years ago

👍

wingrunr21 commented 6 years ago

Have either of you tried setting up any paths or anything like that to try and support this? I agree this is something we should look at but I haven't developed on a Windows machine in years so I'd need to get an environment spun up.

fastsyrup commented 6 years ago

Nope, what do you mean by setting up paths? Willing to help 😀

wingrunr21 commented 6 years ago

I did a cursory Google search and it said something about prefixing commands with a path of some kind in order to run it within the Linux subsystem.

brettmarl commented 6 years ago

I've just recently been playing with this. I was able to successfully get a rails dev environment setup in WSL. I'm using rdebug-ide in the WSL instance and have vscode-ruby setup in remote-attach mode.

Everything appears to work fine, and when I 'attach' to the remote via Code - it starts the rails server remotely and things appear good. However, it never seems to hit my breakpoints.

I believe I have cwd and remoteWorkspaceRoot setup correctly. I can post all the details if it would be useful. Feels like it's already working, and I'm just missing something in the config.

fastsyrup commented 6 years ago

Hi Brett, yes sounds great, could you please post whatever you did to get it working? Best regards

brettmarl commented 6 years ago

Windows 10 WSL/Ruby Setup

Environment

(I'm using older version of Ruby/Rails due to the project I'm working on)

ruby 2.2.6p396 (2016-11-15 revision 56800) [x86_64-linux] Rails 4.2.4 ruby-debug-ide (0.6.1) debase (0.2.2)

WSL: Distributor ID: Ubuntu Description: Ubuntu 16.04.2 LTS Release: 16.04 Codename: xenial

Installing WSL

To install Ubuntu via WSL - open up a CMD window (with Administrator rights) and run the following command:

lxrun /install /y

This will download Ubuntu from the Windows Store and so take a while. After completing run Bash via the start menu (\windows\system32\bash.exe)

MySQL

For simplicity I installed MySQL on using the windows installer as a regular service running on 3306 on localhost. I didn't install in the WSL environment, as I already had it running on windows.

Installing Ruby

I first created a new linux account to run everything under vs. root. Then used RVM to install Ruby.

WSL Config

Once I confirmed that the rails server ran fine from WSL, my next step was a configure remote debugging with VSCode. To do this I made sure the ruby-debug-ide and debase gems were installed and byebug was removed. To start the remote listener session in WSL I used the following command:

rdebug-ide --host 0.0.0.0 --port 1234 -- /home/dev/.rvm/gems/ruby-2.2.6/bin/rails s -b 0.0.0.0 -p 3000 -e development 

VSCode Config

From VSCode I configure the launch.json settings to be:

{
            "name": "Attach to Remote",
            "type": "Ruby",
            "request": "attach",
            "cwd": "c:\\git\\myproject",
            "remoteHost": "127.0.0.1",
            "remotePort": "1234",
            "remoteWorkspaceRoot": "/mnt/c/git/myproject"
        },

Starting Debugger

Next step, I go into VS Code and attempt to attach to the debugger. This shows the following output in WSL

Fast Debugger (ruby-debug-ide 0.6.1, debase 0.2.2, file filtering is supported) listens on 0.0.0.0:1234
=> Booting Thin
=> Rails 4.2.4 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Thin web server (v1.6.3 codename Protein Powder)
Maximum connections set to 1024
Listening on 0.0.0.0:3000, CTRL+C to stop

And the rails server starts up and is accessible. I can set breakpoints in VSCode, however they never get hit when I execute the code.

fastsyrup commented 6 years ago

Have the same problem, debugger attaches and breaks on breakpoint, but I can't see neither callstack nor variables, nor the line where it breaks...

Anyone know why?

wingrunr21 commented 6 years ago

There are existing issues with the debugger and breakpoints (see #316). It's probably the same issue.

donpapa26 commented 5 years ago

I found a solution!

You need to add your project Gemfile this group:

group :development do gem 'ruby-debug-ide', '0.6.1' gem 'debase', '0.2.2' end

( I use ruby 2.1.8, in this case, I needed to freeze the ruby-debug-ide version number. )

I used this command in my project folder:

rdebug-ide --host 0.0.0.0 --port 1234 -d -x -- ./bin/rails s -b 0.0.0.0 -p 3000 -e development

My config in the launch.json: { "name": "Listen for rdebug-ide API", "type": "Ruby", "request": "attach", "cwd": "C:\Users\MYUSER\code\MYPROJECT", "remoteHost": "127.0.0.1", "remotePort": "1234", "remoteWorkspaceRoot": "/mnt/c/Users/MYUSER/code/MYPROJECT", "showDebuggerOutput": true }

tinhdang1115 commented 5 years ago

I found a solution!

You need to add your project Gemfile this group:

group :development do gem 'ruby-debug-ide', '0.6.1' gem 'debase', '0.2.2' end

( I use ruby 2.1.8, in this case, I needed to freeze the ruby-debug-ide version number. )

I used this command in my project folder:

rdebug-ide --host 0.0.0.0 --port 1234 -d -x -- ./bin/rails s -b 0.0.0.0 -p 3000 -e development

My config in the launch.json: { "name": "Listen for rdebug-ide API", "type": "Ruby", "request": "attach", "cwd": "C:\Users\MYUSER\code\MYPROJECT", "remoteHost": "127.0.0.1", "remotePort": "1234", "remoteWorkspaceRoot": "/mnt/c/Users/MYUSER/code/MYPROJECT", "showDebuggerOutput": true }

I tried, but the breakpoints are still being ignored, I can see that the request contains debug info:

image

Not sure why it doesn't work, I'm new to Ruby, but my guess: It could be the mapping path issue?

raman-nbg commented 5 years ago

Is there any progress?

It also would be nice to start the ruby application in WSL directly from VSCode using an option like "uswWSL": true. Something similar is already possible with NodeJS: https://blogs.msdn.microsoft.com/commandline/2017/10/27/running-node-js-on-wsl-from-visual-studio-code/

yisonPylkita commented 5 years ago

In vscode extension for Rust we just got this functionality working. https://github.com/rust-lang/rls-vscode/pull/488

You had hit the same problem I had some time ago. To map paths between WSL and Windows in vscode you have to add this

// Changes paths between Windows and Windows Subsystem for Linux
if (this.config.useWSL) {
    clientOptions.uriConverters = {
        code2Protocol: (uri: Uri) => {
            const res = Uri.file(uriWindowsToWsl(uri.fsPath)).toString();
            console.log(`code2Protocol for path ${uri.fsPath} -> ${res}`);
            return res;
        },
        protocol2Code: (wslPath: string) => {
            if (wslPath.startsWith('file://')) {
                wslPath = wslPath.substr('file://'.length);
            }

            const res = Uri.file(uriWslToWindows(wslPath));
            console.log(`protocol2Code for path ${wslPath} -> ${res.fsPath}`);
            return res;
        },
    };
}

I also wrote a simple TypeScript library for mapping paths between WSL and Windows - https://github.com/yisonPylkita/wslpath.ts

wingrunr21 commented 5 years ago

@yisonPylkita this is great! I'll take a look at adding support!

mallikarjunece commented 4 years ago

Windows 10 WSL/Ruby Setup

Environment

(I'm using older version of Ruby/Rails due to the project I'm working on)

ruby 2.2.6p396 (2016-11-15 revision 56800) [x86_64-linux] Rails 4.2.4 ruby-debug-ide (0.6.1) debase (0.2.2)

WSL: Distributor ID: Ubuntu Description: Ubuntu 16.04.2 LTS Release: 16.04 Codename: xenial

Installing WSL

To install Ubuntu via WSL - open up a CMD window (with Administrator rights) and run the following command:

lxrun /install /y

This will download Ubuntu from the Windows Store and so take a while. After completing run Bash via the start menu (\windows\system32\bash.exe)

MySQL

For simplicity I installed MySQL on using the windows installer as a regular service running on 3306 on localhost. I didn't install in the WSL environment, as I already had it running on windows.

Installing Ruby

I first created a new linux account to run everything under vs. root. Then used RVM to install Ruby.

WSL Config

Once I confirmed that the rails server ran fine from WSL, my next step was a configure remote debugging with VSCode. To do this I made sure the ruby-debug-ide and debase gems were installed and byebug was removed. To start the remote listener session in WSL I used the following command:

rdebug-ide --host 0.0.0.0 --port 1234 -- /home/dev/.rvm/gems/ruby-2.2.6/bin/rails s -b 0.0.0.0 -p 3000 -e development 

VSCode Config

From VSCode I configure the launch.json settings to be:

{
            "name": "Attach to Remote",
            "type": "Ruby",
            "request": "attach",
            "cwd": "c:\\git\\myproject",
            "remoteHost": "127.0.0.1",
            "remotePort": "1234",
            "remoteWorkspaceRoot": "/mnt/c/git/myproject"
        },

Starting Debugger

Next step, I go into VS Code and attempt to attach to the debugger. This shows the following output in WSL

Fast Debugger (ruby-debug-ide 0.6.1, debase 0.2.2, file filtering is supported) listens on 0.0.0.0:1234
=> Booting Thin
=> Rails 4.2.4 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Thin web server (v1.6.3 codename Protein Powder)
Maximum connections set to 1024
Listening on 0.0.0.0:3000, CTRL+C to stop

And the rails server starts up and is accessible. I can set breakpoints in VSCode, however they never get hit when I execute the code.

I have done this and my launch config is

{ "name": "Listen for rdebug-ide", "type": "Ruby", "request": "attach", "remoteHost": "127.0.0.1", "remotePort": "1234", "cwd": "${workspaceRoot}", "remoteWorkspaceRoot": "/", "showDebuggerOutput": true, }

But, I am getting the following error while starting debugging...

Debugger error: Client: Error: connect ECONNREFUSED 127.0.0.1:1234

Something I missed ?

How to overcome this, kindly help me...

Thanks, Mallikarjuna.

alanlivio commented 3 years ago

I have the same problem in WSL. Is there a solution?

alanlivio commented 3 years ago

As an alternative, I was able to debug with using the vscode-ruby-debug extension .

alanlivio commented 3 years ago

As a alternative, I was able to debug with the extension