How to debug ruby plugins in SketchUp? - ruby

The only tip I got to debug ruby plugins in SketchUp is the use of puts.
I tried to launch SketchUp this way: sketchup.exe > log.txt 2> errors.txt, but it only shows logs / errors from SketchUp app, not from its plugins.
Does anyone knows how to:
Execute step by step inside SketchUp
Get an execution stack when a plugin crashes SketchUp
Any other idea that woul be helpfull to debug ruby plugins in this context

SketchUp released an open source debugger for the SketchUp Ruby API on April 15th, 2014:
https://github.com/SketchUp/sketchup-ruby-debugger

Update: As of SketchUp 2014 you can use Ruby IDE's to step through Ruby code. Follow the instructions at this GitHub repository: https://github.com/SketchUp/sketchup-ruby-debugger
No more puts debugging!
TBD has written and released a bridge to debug SketchUp Ruby plugins: http://labs.plugins.ro/
That's probably what you're looking for. I haven't used it myself yet - so can't elaborate too much on it.
I often use a call to the WIN32 api to OutputDebugString which allows me to see the output (in DebugView) I send to it regardless if SU craches - and it doesn't slow down the execution as much as outputting lots of stuff to the SketchUp Ruby Console:
http://www.thomthom.net/software/sketchup/tt_lib2/doc/TT.html#debug-class_method
(I meant to give a direct link to the BitBucket source code, but the site is down a the moment. Repo: https://bitbucket.org/thomthom/tt-library-2/ )
EDIT: Site back online - direct link: https://bitbucket.org/thomthom/tt-library-2/src/tip/TT_Lib2/debug.rb?at=Version%202.8
One could also reroute puts to OutputDebugString if you wanted a quick catch all solution.
On a slight sidenote, there is also the Developers Tools utility released by the SketchUp team with an enhanced Ruby Console and unit test framework: https://github.com/SketchUp/sketchup-developer-tools

It looks like the SketchUp folks released a new unit testing framework in October 2014. I've not tried using it yet, but will give it a shot and report back with what I find:
https://github.com/SketchUp/testup-2

Related

How to setup ruby profiler in IntelliJ

There seems to have been a recent update for to ruby mine that allows you to attach a rbspy profiler to a rails app. I have found a ton of guides on the internet (for instance this one) that explain what changes need to be updated in ruby mine to allow you to attach the profiler to the ruby process, but i have not been able to find the same steps for intellij with the ruby plugin.
Is there a way to perform the steps linked in the guide above in the Intellij IDE?
At the moment Ruby profiler isn't available via Ruby plugin in IDEA but it's planned to be in 2019.2:
https://youtrack.jetbrains.com/issue/RUBY-23977
UPD: it seems to be available in the last IDEA 2019.2 EAPs (starting from 192.5118.30)

How to traverse through Source code only using debugger - Rails 3.2.13

In my Rails app, using Ruby 2.0.0-p0 and Rails 3.2.13, I also use the gem debugger for debugging purpose. If I have to debug an area in my source code, for e.g. a controller method, I will put debugger inbetween and when I execute the action, it will go to the source code and then travserse through the framework code a lot and that really mess-up the normal debugging. I can see many commands through help, but don't know how to handle with that.
I just want to traverse through the source code only..
Please help me to have a solution. Thanks :)-
Use byebug instead. It was created to overcome debugger's problems with ruby-2.0.0, like the one that makes it "step" when you use command "next", unexpectedly leading you to framework sources.
Disclaimer: I'm byebug's author

How to install UIBuilder on Pharo

I'm learning Smalltalk for my graduation (Computer Science), and got started using Pharo.
I've read and watched that there is a nice framework for UI building, called UIBuilder tool. But I'm confused on how to install it on Pharo.
Note that this unfortunately only works on old versions of Pharo.
The install instructions are what the registration section gives e/g/
In a transcript paste
MCHttpRepository
location: 'http://www.squeaksource.com/UIBuilder'
user: ''
password: ''
Select that and choose DoIt from the menu.
This will then download the classes and install in the image. The tool that does this is Monticello for more on this see the Pharo By Example Monticello chapter
The old "UIBuilder" project seems to be dead/discontinued. The Squeaksource page
http://www.squeaksource.com/UIBuilder.html says:
"Failed attempt of develop a UI builder for Pharo-Smalltalk."
There is now a new "UI Painter" project developed as part of GSOC 2013
for Pharo based on Spec. More information can be found here : http://uipainter-gsoc.over-blog.com/
If you can get away with it, build your UI with Glamour. That is included in Moose. Otherwise the supported (but very much in development) way to create UI's for Pharo is using Spec.

Code completion for Sketchup Ruby API

Does anyone know of a program that has support for code completion for Sketchup Ruby API?
Here are some Ruby IDEs that have code completion:
JetBrains RubyMine: http://www.jetbrains.com/ruby/
NetBeans Ruby plugin: http://wiki.netbeans.org/Ruby
Unfortunately, it looks like you might need to do some work to get the Sketchup API symbols loaded into your IDE of choice. If I come across anything, I'll edit this answer.
You might also try posting to their mailing list to see if they have any ideas: http://groups.google.com/group/google-sketchup-developers
I found a code-completion addon for Notepad++. I added the SketchUp Ruby API methods to the Ruby code completion. Though I think it needs updating to support SU8's methods. I don't remember where I found it, but pretty sure it was somewhere on the SketchUcation forum: http://forums.sketchucation.com/
I'll post back if I find it.

How to incorporate Interactive Ruby into my development process?

I am trying to find a better way to integrate IRB with my normal ruby devleopment. Currently I rarely use IRB with my code. I only use it to verify syntax or to try something small.
I know I can load my own code into ruby as a
require 'mycode'
but this usually doesn't mesh with my programming style. Sometimes the variables I want to examine are out of scope or inside of a loop. Is there an easy way to fire up my script and freeze at a certain point inside of IRB? I guess I'm looking for an easier way to debug my ruby code without breaking my F5(compile) key.
Maybe a more experienced ruby developer can share with me a more streamlined method of development.
Install the ruby-debug gem. Of course, require it inside your app (only in development/test mode). Now you can write 'debugger' where you want to stop execution.
Once your app stop at your breakpoint, you can type 'help' to know about all commands. One of them is 'irb'. It starts an IRB session in which you have access to all methods in your current context.
I personally mostly use p (print), eval, v i (instance vars) and v l (local vars). Of course, n for next and c for continue.
The command to step out of a given block/method never worked for me though. I never investigated why :-)
I don't tend to use irb directly that frequently, as I tend to be inside rails and so use script/console a bunch, but I do like using the ruby debugger (Ruby Debug gem). It lets you set a breakpoint basically and then step through your code line by line.
Here's a screencast about it that I haven't actually watched, but a quick search pulled it up, and it could be useful:
http://brian.maybeyoureinsane.net/blog/2007/05/07/ruby-debug-basics-screencast/
For Ruby development in Eclipse: there's a much improved version of RDT (ruby development tools) available now. To install it directly in Eclipse, click Help > Software Updates > Find and Install > Search for new features radio button > next > new remote Site > Name = Ruby and URL = http://update.aptana.com/update/rdt/3.2/
Another Ruby plugin is the shiny new Eclipse DLTK (dynamic languages toolkit).
DLTK stable release 1.0.M5 just came out a few days ago.
Here are some useful installation tips.
I just use rdebug to debug any of my ruby or RoR code.
If you're willing to use an IDE for debugging, I know Eclipse (via the Ruby Development Tools) has a relatively straightforward interface. If you're doing rails then there's a specific build of eclipse called RadRails which may also help (though I haven't used it for debugging)

Resources