Below are instructions for getting Visual Studio Code (VSC) debugging breakpoints to work with Windows SU 2024.
First of all, for debugging in VSC, please install the ‘VSCode rdbg Ruby Debugger` extension, by Koichi Sasada.
I’ve placed the files needed to use Windows SketchUp 2024 with VSC debugging in a zip file.
These files are part of a normal ‘stand-alone’ Ruby, but are not included with SU. Also, the zip file contains the most recent versions, which are newer than the ones included with Ruby 3.2.
It should be installed/extracted to:
C:/Users/<user>/.gem/ruby
You may need to create the path. It’s the location where RubyGems installs gems when the --user-install
option is used. On Windows, these can be accessed by both a stand-alone Ruby 3.2 and SU 2024’s Ruby.
Assuming you’ve got a folder with Ruby code that runs in SU, place a file there at .vscode/launch
, with the below contents:
{
"version": "0.2.0",
"configurations": [
{
"type": "rdbg",
"name": "SU 2024 Attach with rdbg",
"request": "attach",
"debugPort": "40001"
},
]
}
This file is read by VSC.
Then in one of your Ruby files that SU loads, place the following code:
if ENV['RUBY_DEBUG_PORT']
gem 'debug', '>1.9.0'
require 'debug/open_nonstop'
puts "Started debugging"
end
Now, pick a Ruby file, and add a line binding.break
, which will cause the debugger to kick in when it’s run. I placed it in a file that’s executed when a menu item is selected/clicked. Note that setting a breakpoint in the VSC GUI doesn’t seem to work.
The above takes care of the setup. Now:
- Open VSC, and open your folder with Ruby code. Then, click the debugger (Ctrl+Shift+D). In the upper right, you should see ‘SU 2024 Attach with rdbg’ in the list/combobox. If not, select it.
- From a PowerShell terminal in VSC or otherwise, run the command, which should start SU:
$env:RUBY_DEBUG_PORT = '40001'; &'C:/Program Files/SketchUp/SketchUp 2024/SketchUp.exe'
- In VSC, click the run triangle that’s on the left of the Debug list/combobox, or hit F5. This starts the debugger.
- Now, if you need to perform an action to reach the place where you placed the
binding.break
line. Do so. You should see the debugger stop your code at that line.
With my code, the debugger also steps thru Ruby files called by the extension, so one sees the RubyGems files used for a require
statement.
A few notes:
I haven’t taken that much time working on this, and this is only debugging. Editor related features are part of Ruby LSP.
I’ve been working with Ruby for a long time, and I still use NotePad++ for editing, mostly because I like the ‘Function List’. GitHub’s Web UX has something similar, but VSC does not. Also, I often use what’s called ‘puts’ debugging. I also rely on tests.
ENV['RUBY_DEBUG_PORT']
needs to be set for remote debugging to work. I also used it as a means of determining if the code was running with a desire to use VSC debugging. That’s why the command line above that sets it and starts SU.