Ruby Screenshot of the Week #11: Rails Debugging


First the screenshot - click for full resolution:








The NetBeans Ruby support now lets you debug Rails applications. As the screenshot shows, you can even step right through RHTML files! All the usual debugging features are there - breakpoints, stack view, local variables view - and balloon evaluation, where you hover the mouse over a variable and it displays the current value as a tooltip.



I can't take any credit for this; the debugger has been written by Martin Krauskopf, and uses the debug-commons library. Martin was my co-speaker for the Ruby talk (TS-9972) at JavaOne. If you missed it, Brian Leonard will be doing the same talk at RailsConf this weekend. One thing I want to clarify is that not everything I talked about in the type inference section is actually implemented yet in NetBeans. The talk represents everything I plan to do, not everything I've already done.



Note that the RHTML debugging feature is not present in the recent Milestone 9 bits. We've made a lot of improvements since then. Just this morning I integrated various fixes to make code completion work much better in Rails. You now properly get code completion in your model and migration files etc - as the following screenshot shows:






Another feature we added after Milestone 9 was some preliminary support for Auto Test - see the testing page for some screenshots and more info.



For now, I recommend that you use NetBeans Milestone 9 as your base IDE, and then use the trunk/daily Ruby bits with them. The easiest way to do that is to install Milestone 9, then follow the instructions in the RubyInstallation wiki page to blow away the ruby1 cluster in your M9 installation and replace it with a .zip download from deadlock.nbextras.org. Also be sure to nuke your userdir for any custom installed modules there (usually ~/.netbeans/dev). In the future, staying up to date with the Tools | Plugins manager will be easy, but with Milestone 9, it only displays branched Milestone 9 modules, and we aren't merging and rebuilding the Ruby stuff into the M9 branch at this point.



If all that sounded complicated, just go and download the Ruby-only IDE zip here. Get the zip containing rubyide in the name, unzip somewhere, and run nbrubyide/bin/nbrubyide. This will be daily-everything as opposed to a stable IDE + trunk Ruby, but - it will probably be okay.



Finally, if you're going to be debugging, make sure you first visit the RubyDebugging wiki page which will tell you some really important configuration information - like how to enable fast debugging.

Comments:

Hey Tor.. playing with the debugging, I can't seem to figure out how to debug a unit test or one off script. Rails debugging works (!) so I have things hooked up correctly, I might just be missing the UI element I need to click to debug. The "Debug File" option is greyed out when I have a unit test open. Any suggestions? Great job to all you guys on this, having a real debugger is going to be awesome.

Posted by Greg on May 18, 2007 at 05:08 AM PDT #

Hi Greg. It is a bug. I forgot to enable debugging of single files in Rails application. In "standard" Ruby application it should work. Thanks for the report. I'll fix it soon.

Posted by Martin Krauskopf on May 18, 2007 at 06:06 AM PDT #

Great news. Thanks!

Posted by Greg on May 18, 2007 at 01:18 PM PDT #

Now, with ML9, and latest bits from the build, cause a conflict and netbeans complains about Common Scripting Framework 4 required, but found 3. I have been hitting on this issue, for a while. However, for bits older than 1846 work alright with netbeans ML9. Also, importing of textmate templates didn't work at all for me.

Posted by hemant kumar on May 18, 2007 at 03:42 PM PDT #

Common Scripting Language Support - The module Experimental Editor Hints SPI was requested in implementation version "4" but only "3" was found. 7 further modules could not be installed due to the above problems.

Posted by hemant kumar on May 18, 2007 at 04:02 PM PDT #

I'm playing with the Ruby-only IDE downloaded from Hudson. First of all, I'm impressed by the Ruby and Rails support you're building into NetBeans -- you're doing a truly exceptional job! Now a small issue with the debugging support: when launching a debugging session I don't get any debug toolbar or menu -- either on the main menu or on the right-click context menu. This makes for a less-than-ideal debugging experience as I have to hunt for the keyboard shortcuts. It would be great if you could fix this.

Posted by Eugene on May 18, 2007 at 07:54 PM PDT #

Wow, for adding a simple text file to the project, I had to jump so many hooves(click-click-click-type-click) . Not trying to sound like a ass, but sometimes IDEs overdo things. I thing, that should be simpler. Although this is not related to Ruby part of IDE.

Posted by hemant kumar on May 18, 2007 at 07:57 PM PDT #

Hemant, regarding the implementation-version problem: On May 16 one of the APIs the Ruby support depends on changed incompatibly. I adjusted the Ruby support about 36 hours later (when I discovered it), so all the builds in between would have had problems. But it should be working now. Unfortunately, deadlock.nbextras.org seems to be down at the moment (sigh! Luckily it's scheduled to be replaced by a much beefier production system shortly) so I can't verify.

Eugene, I had forgotten about the debugging toolbar problem. Ugh, that means I probably shouldn't have pointed to the Ruby-only IDE in a blog entry on debugging! This happens in the Ruby-only IDE at the moment (there's an open bug report on it) and I believe it will be addressed shortly. Martin is on the case :-) The problem was that the debugging toolbar is getting registered by a Java-related debugger module which isn't present in the ruby-only IDE.

Hemant, do you have any ideas for how we should make it easier to add a file? I'm thinking of adding some quick-tip style functionality which should make it easier to create methods and classes for the symbol under the caret, but do you have other ideas?

Posted by Tor Norbye's Weblog on May 19, 2007 at 01:41 AM PDT #

Hemant, I overlooked your TextMate comment. Have you looked at this blog entry: http://blogs.sun.com/tor/entry/ruby_screenshot_of_the_week7. One very important part about that article is that it has a link to a separate module you have to download and install. This mechanism isn't in the base IDE yet.

I'd really like to add some more bundles into the default IDE rather than relying on import from others. If anyone has any snippets they'd like to contribute, please send them my way.

Posted by Tor Norbye's Weblog on May 19, 2007 at 01:44 AM PDT #

Thanks for your quick response. I'll wait for Martin's fix for the debugger toolbar. In the meantime, I'm relying on this cheat sheet ;-) On the bundles topic: is there a way to export snippets "en masse"?

Posted by Eugene on May 19, 2007 at 02:11 AM PDT #

So I broke down and just downloaded Netbeans (I'm an IntelliJ user with the Ruby Plugin)... I'm impressed, but I have a question. Is there an equivalent for the CTRL-N or CTRL-SHIFT-N in Intellj (CTRL-R in Eclipse)? The "super open" command where you can put in a partial name and select from the results for a class/file... This is the single biggest, most useful feature in an IDE IMO. I don't see it... Thanks, phil

Posted by phil swenson on May 19, 2007 at 03:20 AM PDT #

Hi Phil,
it's being added for Milestone 10. But you can download a plugin and use it now - it works well (I use it all the time): http://deadlock.nbextras.org/hudson/job/go%20to%20file/

There's also a preliminary Go To Type module (will also be part of the standard build - more info and download link here: http://blogs.sun.com/tor/entry/saturday_morning_hack

Posted by Tor Norbye's Weblog on May 19, 2007 at 05:38 AM PDT #

Is there a way to set a conditional breakpoint? I've tried Ctrl+Shift+F8 without any result. Thanks, - Eugene

Posted by Eugene on May 19, 2007 at 06:57 PM PDT #

Hi Eugen,

regarding toolbar and menu, I'm trying to solve this. Hopefully on Monday. http://www.netbeans.org/issues/show_bug.cgi?id=102945

Conditional breakpoint: http://www.netbeans.org/issues/show_bug.cgi?id=100096
Again, should be for 6.0. I'm leaving for 2 weeks next week. So the debugger progress will be probably stopped a little bit until I return.

Posted by Martin Krauskopf on May 20, 2007 at 02:44 AM PDT #

Regarding TextMate bundles, yes obviously i got to learn about them from that post only. So i downloaded nbm file from here . And i downloaded bundle from here . And I got this error when trying to import the bundles:
ava.lang.NullPointerException
	at org.netbeans.modules.codetemplatetools.ui.view.CodeTemplatesPanel.importTemplates(CodeTemplatesPanel.java:216)
	at org.netbeans.modules.codetemplatetools.ui.view.CodeTemplatesPanel.importButtonActionPerformed(CodeTemplatesPanel.java:554)
	at org.netbeans.modules.codetemplatetools.ui.view.CodeTemplatesPanel.access$400(CodeTemplatesPanel.java:63)
	at org.netbeans.modules.codetemplatetools.ui.view.CodeTemplatesPanel$8.actionPerformed(CodeTemplatesPanel.java:466)
	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
	at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
	at java.awt.Component.processMouseEvent(Component.java:6038)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
	at java.awt.Component.processEvent(Component.java:5803)
	at java.awt.Container.processEvent(Container.java:2058)
	at java.awt.Component.dispatchEventImpl(Component.java:4410)
	at java.awt.Container.dispatchEventImpl(Container.java:2116)
	at java.awt.Component.dispatchEvent(Component.java:4240)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
	at java.awt.Container.dispatchEventImpl(Container.java:2102)
	at java.awt.Window.dispatchEventImpl(Window.java:2429)
	at java.awt.Component.dispatchEvent(Component.java:4240)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:177)
	at java.awt.Dialog$1.run(Dialog.java:1039)
	at java.awt.Dialog$3.run(Dialog.java:1091)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.awt.Dialog.show(Dialog.java:1089)
	at java.awt.Component.show(Component.java:1419)
	at java.awt.Component.setVisible(Component.java:1372)
	at java.awt.Window.setVisible(Window.java:801)
	at java.awt.Dialog.setVisible(Dialog.java:979)
	at org.netbeans.modules.codetemplatetools.ui.view.CodeTemplatesPanel.promptAndInsertCodeTemplate(CodeTemplatesPanel.java:72)
	at org.netbeans.modules.codetemplatetools.actions.ShowTemplatesAction.performAction(ShowTemplatesAction.java:44)
	at org.openide.util.actions.NodeAction.performAction(NodeAction.java:267)
	at org.openide.util.actions.CallableSystemAction$1.run(CallableSystemAction.java:96)
	at org.netbeans.modules.openide.util.ActionsBridge.doPerformAction(ActionsBridge.java:55)
	at org.openide.util.actions.CallableSystemAction.actionPerformed(CallableSystemAction.java:92)
	at org.openide.util.actions.NodeAction.actionPerformed(NodeAction.java:255)
	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
	at javax.swing.AbstractButton.doClick(AbstractButton.java:357)
	at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1216)
	at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1257)
	at java.awt.Component.processMouseEvent(Component.java:6038)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
	at java.awt.Component.processEvent(Component.java:5803)
	at java.awt.Container.processEvent(Container.java:2058)
	at java.awt.Component.dispatchEventImpl(Component.java:4410)
	at java.awt.Container.dispatchEventImpl(Container.java:2116)
	at java.awt.Component.dispatchEvent(Component.java:4240)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
	at java.awt.Container.dispatchEventImpl(Container.java:2102)
	at java.awt.Window.dispatchEventImpl(Window.java:2429)
	at java.awt.Component.dispatchEvent(Component.java:4240)
[catch] at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

And thanks for quick response, and sorry i polluted your blog a bit. Although I am subscribed to netbeans mailing list and hence i can post errors there also. Also, for adding a file, there should be a option like quick add, which won't open any big dialog box and would let me specify fullname and won't try to detect file templates and stuff.

Posted by hemant kumar on May 20, 2007 at 03:28 AM PDT #

Also, when i try to update to latest build from deadlock.nbextras.org, i still get this error:
Warning - could not install some modules:
	Common Scripting Language Support - The module Experimental Editor Hints SPI was requested in implementation version "4" but only "3" was found.
	8 further modules could not be installed due to the above problems.
Here is my install info:
NetBeans IDE 6.0 Preview (M9, build 070502)
1.6.0_01; Java HotSpot(TM) Client VM 1.6.0_01-b06
Linux version 2.6.15-28-386 running on i386
en_IN (nb); UTF-8
In fact, I tried various combinations, but latest ruby builds just refuse to work. I tried to blow away, entire nbm installation and downloaded bare latest milestone 9 IDE and tried to install latest ruby builds from hudson, but no avail.
Which led to another problem, when i blew away my nbm installation, i lost all my snippets that i created manually(\*sigh\*). Yes, there should be way to export snippets or at least back them up.

Posted by hemant kumar on May 20, 2007 at 03:48 AM PDT #

Hi Hemant, thanks for the exception; the only way I can see this happening from inspecting the code is if you point the importer to a .tmbundle directory that doesn't contain a "Snippets" subdirectory?

Would you mind mailing me directly (tor.norbye@sun.com) a zip of the snippets directory you're trying to import? It's also important that you choose the directory named "<whatever>.tmbundle" as the bundle to be imported - not individual snippet files. I thought the file import filter tried to enforce that, but it may not be working properly.

Posted by Tor Norbye's Weblog on May 20, 2007 at 03:50 AM PDT #

Sorry about that. My suspicion is that there are older copies of the Ruby modules in your user directory (installed via the plugin manager) and that somehow they are interrupting?

One thing you can try is to run with a new userdirectory; e.g. netbeans --userdir /tmp/nonexistent/. Does that help?

I tried downloading a nbrubyide build yesterday, blew away my ~/.nbrubyide dir and it started without the warning.

There also should be a way to export snippets via the CodeTemplateTools module, I'll go look for it (but it will have to be later tonight, I have to run now). In any case, using --userdir to point to an alternative user directory is safer since you don't actually delete your old userdir (where the snippets live).

Sorry about all the installation trouble. Hopefully soon we'll have this ironed out such that you can use only the plugin manager to fetch updates.

Posted by Tor Norbye's Weblog on May 20, 2007 at 03:55 AM PDT #

yes, my mistake regarding absence of snippets directory from tmbundle. I wasn't familiar with Textmate snippets mechanism actually. Sorry about this stupidity.

Anyways, I am really puzzled with userdir stuff. I would try to list out my woes.

1. I download plain nbm ML9 and install ruby module via zip file provided at deadlock.nbextras.org. Now, I don't have a .nbrubyide directory, neither do i have a ~/.netbeans/dev directory as suggested in one of your earlier posts. I have a ~/.netbeans/netbeans-6.09 and ~/.nbi and ~/.netbeans-derby. So i delete them all and try to restart netbeans with latest ruby bits and i get above said problem. I think, my problem is, you guys are using latest build of netbeans which comes with version 4 Common Scripting framework, and ML9 with 3 and hence the problem.

2. I download nbrubyide from deadlock.nbextras.org. and i experience following problems. It goes in some kind of infinite loop when its scanning Typo gem. So top shows netbeans running with almost 100% of CPU and 10% of memory usage and library scanning halted, although IDE is still responsive. nbrubyide, hangs when i try to open a netbeans project which was created by IDE installed using approach #1. I tried to run nbrubyide with strace and find out, where the heck its going in infinite loop, but strace doesn't cut through JVM as i see.

Posted by hemant kumar on May 20, 2007 at 05:09 AM PDT #

FYI - the debugger toolbar issue has been fixed for the slim Ruby IDE, so go ahead and try it!

Posted by Tor Norbye's Weblog on May 21, 2007 at 07:34 AM PDT #

Hi Tor, great stuff. Is there any support for cross-platform remote debugging? IE, running my web-server on ubuntu and debugging from netbeans running on windows?

Posted by Stephen Brown on May 21, 2007 at 10:51 AM PDT #

Hi Stephen. This is not supported yet. However it is supported by the backends. At least by Kent's ruby-debug. So it should not be problem to add it. I've filed an RFE for it. You may add yourself to the CC. Thanks for the feedback.

Posted by Martin Krauskopf on May 21, 2007 at 04:51 PM PDT #

Yes the debugging toolbar now works perfectly in the slim Ruby IDE. Thanks for the quick turnaround!

Posted by Eugene on May 22, 2007 at 07:08 AM PDT #

Since build 1301 I get this error when trying to use Ruby with NetBeans 6.0M9: "Warning - could not install some modules: Common Scripting Language Support - The module Experimental Editor Hints SPI was requested in implementation version "4" but only "3" was found. 7 further modules could not be installed due to the above problems." I have removed my .netbeans dir but it doesn't help.

Posted by Jonas Tehler on May 22, 2007 at 04:04 PM PDT #

Yep. Catch-22: using M9 netbeans w/ trunk ruby plugin doesn't work, but using rubyide build prevents using my jvi plugin for vi keybindings. I guess I am stuck waiting for the new hotness :)

Posted by Greg on May 23, 2007 at 04:15 AM PDT #

I downloaded the newest nightly build and it seems to work fine. http://bits.netbeans.org/download/6.0/nightly/

Posted by Jonas Tehler on May 23, 2007 at 05:02 AM PDT #

Hi Jonas, I'm glad you found a workaround using the current nightly (and a tip to others; the "latest" link often isn't fully populated, so use latest.last; e.g. http://bits.nbextras.org/download/6.0/nightly/latest.old/installers/.

I'm not sure what to do about the incompatibility; one of the APIs the Ruby support depends on changed incompatibly. I've adjusted the Ruby code such that it compiles and runs with the IDE trunk; making it work with M9 seems harder (I thought I had made it work but it sounds like it's not). Hopefully these APIs will be stabilizing when we reach feature freeze!

Hi Greg - regarding the catch-22: What is the problem with the jvi plugins and rubyide? I don't see why it would depend on the Java support (which is missing in rubyide). I downloaded it to take a look but it looks like the jvi code depends on JDK 6! (java.util.Deque) - and I don't have that on this Mac. If there's something in jvi which depends on java I'd like to talk to the developer to see if we can make it work. Or, if it simply depends on some other infrastructure module that I've needlessly ripped out in the rubyide, I can place it back in.

Posted by Tor Norbye's Weblog on May 23, 2007 at 01:11 PM PDT #

Wow, first of all I'm impressed with the Ruby support built in Netbeans. Kudos! After reading the wiki, I was really excited to learn about fast debugger support and rpsec support! I finally got fast debugger and rspec working, but I can't debug rspec specs. It looks like the IDE does a run rather than a debug on rspec specs. Any idea? I went to a bit of trouble to make my setup work though. To let others know, I'm running Ubuntu 7.04. The only way I could make fast debugger and rspec support work was to have my own writable installation of ruby with rubygems installed. I then used that install and downloaded the rspec and ruby-debug-ide gems using the Ruby Gems manager. The hard part was installing ruby from source with rubygems support (ran into zlibc install issues). I wanted to post the steps on how to do that on the wiki, but I get an error trying to register. Will try later or I can send you an email with the instructions if you'd like.

Posted by Vincent Tencé on May 24, 2007 at 02:02 AM PDT #

I've updated the wiki entry http://wiki.netbeans.org/wiki/view/RubyGems with instructions for setting up a private installation of ruby on Ubuntu. I hope that will help some of you.

Posted by Vincent Tencé on May 24, 2007 at 02:38 AM PDT #

Hey Tor, re: jvi, to be honest, I don't know much about how it is implemented. When I tried installing the plugin to rubyide it said I had missing dependencies (5-6 of them) and they all said large scary things like "Java Platform Support" etc. And yeah, the Java 6 dependency is pretty annoying. I don't know why he implemented it using those collections since it makes things difficult for those of us on Mac OSX. I had to install the Apple preview distribution of Java 6 in order to get vi in netbeans :P

Posted by Greg on May 24, 2007 at 04:32 AM PDT #

Hi Vincent, thanks for the wiki page on rubygems. I've just checked in some support for rspec debugging. See http://wiki.netbeans.org/wiki/view/RubyRecentChanges. (This is usually Martin's territory, but he's on vacation so I took a quick stab at it, and it worked for my simple test case). For Ruby debugging with NetBeans in general, see the Ruby debugging page, since there's some important configuraiton you have to do to set it up - http://wiki.netbeans.org/wiki/view/RubyDebugging.

This should be available in build 1362 shortly on http://deadlock.nbextras.org/hudson/job/ruby/.

Posted by Tor Norbye's Weblog on May 28, 2007 at 08:39 AM PDT #

Great Tor, RSpec debuuging works perfectly. Have you planned adding a interactive mode to the debugger? I'd like to be able to stop at a break point and start an embedded irb session ... That would be really great

Posted by Vincent Tencé on June 04, 2007 at 07:16 AM PDT #

Hi Tor, I must be missing something but I can't make tests debugging work in my rails application. Rails debugging works fine though. But test debugging seems to do a run rather than a debug. I set the debugger to verbose mode but I don't see any output. Any idea? Also, the Test menu item under Run -> Run File does nothing. The Debug Test for file is grayed out, so I suspect it's an upcoming feature. Thanks for your help

Posted by Vincent Tencé on June 05, 2007 at 12:01 PM PDT #

I'm using the Ruby ide only build 070604

Posted by Vincent Tencé on June 05, 2007 at 12:02 PM PDT #

Hi Vincent, I'm not sure - but Martin Krauskopf who wrote the Ruby debugger in NetBeans is coming back from vacation in just a couple of days now and I'm sure he will be able to look into it and fix this.

Posted by Tor Norbye on June 05, 2007 at 12:53 PM PDT #

Greg, regarding jvi for NetBeans requiring Java 6 and the Mac Java 6 VM having problems: jVi 1.0.0.beta2 was just announced and it claims to support Java 5.

Posted by Tor Norbye's Weblog on June 11, 2007 at 01:28 PM PDT #

Post a Comment:
Comments are closed for this entry.
About

Tor Norbye

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today