Wednesday, June 20, 2007

Ruby Screenshot of the Week #14: RHTML

WARNING: This blog entry was imported from my old blog on blogs.sun.com (which used different blogging software), so formatting and links may not be correct.


Phew - it's been a very busy past couple of weeks. We had feature freeze for NetBeans 6 just a couple of days ago (Friday night at midnight to be exact) so I was focusing all my energy on getting as many things done as possible by the deadline. From here on out, focus will be on stability. I'm starting to work my way through the bug list, and it's looking promising.



The feature I'd like to show this time is a recent addition: Improved RHTML support. In particular, RHTML completion, RHTML goto declaration, and displaying Ruby errors in RHTML files.



Here's RHTML completion (click for full size):








Things to notice here is that first of all, the various methods you might want completion (and more importantly, documentation) for that are coming from ActionView are showing up as expected - link_to, form_tag, and so on. In addition, methods from your Helper class for this controller also show up. There's also an inherited attribute from ActionView here.



Second, note the enhanced display of the rdoc. It turns out lots of Rails documentation have code snippets, and the colorizer (which I
discussed recently) now properly handles language embedding too - RHTML fragments containing Ruby and HTML colors.) Speaking of colors, NetBeans 6 recently got a makeover in the default color scheme. In addition, there are some new color themes available in the options dialog - including the old colors. You can see the new colors in these screenshots.



Go To Declaration is pretty self explanatory - it works the same way that it does in Ruby files; hold the Ctrl-key and click on identifiers and it will warp to the definition for that method, class or variable assignment. Another new feature is displaying source errors in the file. Behind the scenes, NetBeans now models what ERB will do to the file in a Rails server, and maps these errors back to the RHTML source. Thus, if you have an error like the below, you get an error annotation with a tooltip displaying the error:






One thing which is still missing is indentation of the Ruby code in RHTML files. Marek Fukala is working on this for all the embedded languages, and I believe this feature is still going in after the freeze, so look for it in upcoming builds.



Finally, thanks to those of you who have been using the regular builds and providing feedback and bug reports. I apologize for the last couple of weeks - because of the heavy feature focus before the deadline I haven't been very responsive, and the builds have gone through a huge amount of flux. One of the things which is going on is that all the keyboard shortcuts have been changing - the details are outlined here - so if you thought something was broken, perhaps it's just using a different shortcut now. (We're still tweaking this.) Things will get more and more stable from day to day now. Milestone 10 should be out in a couple of weeks.


Tuesday, June 5, 2007

Ruby Screenshot of the Week #13: Refactoring

WARNING: This blog entry was imported from my old blog on blogs.sun.com (which used different blogging software), so formatting and links may not be correct.


As of this evening there are two new features in the builds: Find Usages, and Rename. Let's start with Find Usages. Right click on a symbol and choose "Find Usages" (or use the keyboard shortcut). Let's say I search for the usages of the UserMail class in the Mephisto Rails blogging application (click for full size):








This feature also knows about .rhtml and .erb files - it parses the embedded Ruby and analyzes it. Here's an example where I've searched for the usages of a @comments field in a controller - notice the .rhtml matches:






(Sorry, I know these images might be a bit large on some screens; I should have taken the screenshots at a smaller screen resolution than my usual 1680x1050.)



In the Find usages dialog I can also ask NetBeans to find subtypes of the class rather than usages. Here's an example of what I get if I search for subclasses of the ApplicationController class:






Next, Rename refactoring. Let's say that I want to rename the @comments field in my Rails application controller. I right click on it, choose a new name and hit OK. I then click "Preview", and in the bottom window I get a list of refactoring operations, along with diffs for the currently selected item. I can (and should!) walk through the changes with the Up/Down arrows, and I can unselect any changes that I don't like before I click the Refactor button to apply the changes. Click on the image for full size (I'm showing both the dialog and the results window here; in reality you'd first get the dialog, and when you hit Preview it disappears and you see the bottom window.)








Again, notice how the renaming operation includes changes in .rhtml files. The advantage of this approach over a regular Search/Replace editor operation is that by using parse trees, we have a lot more confidence in the matches. The IDE will not confuse a local variable reference to foo with a method named foo. It does however still have difficulties knowing whether symbols and method names that occur in multiple places refer to say the same method, so at this point it errs on the side of optimism and presents them all as potential uses.



WARNING: This feature is definitely preliminary!! Hopefully the bold red warning in both the Rename and Find Usages dialog makes this really clear. The Refactor button will be disabled and Preview required shortly.



However, this feature should be improving rapidly as I get feedback and implement some more things on my todo-list. Find Usages at least should be quite useful as a navigation tool. If you're going to use the Rename feature, please make a backup of your code first!



(This feature requires the very latest builds - try the Ruby IDE from nbextras.org, or for fuller instructions, see the wiki page. Auto updating from M9 isn't working any more because I'm relying on private APIs that have changed incompatibly.)



P.S. A great big thank you to all of you who have tried the NetBeans Ruby support, and especially to those of you who have provided feedback!


Friday, May 25, 2007

Ruby Screenshot of the Week #12: Improved Ruby Documentation

WARNING: This blog entry was imported from my old blog on blogs.sun.com (which used different blogging software), so formatting and links may not be correct.


One of the things I did this week was to rewrite the code which extracts documentation for all the core Ruby APIs (which are defined in the C Ruby implementation). This fixes some bugs where a method here and there were missing its documentation.



In doing so, I started looking at the actual IDE presentation of the documentation as well, and thought I could make it a lot more appealing. Without further ado, here's how the documentation looks now:






The most interesting part here is that the IDE now figures out whether portions of the documentation corresponds to Ruby code, and then presents it with syntax highlighting right there in the documentation popup. (I've also improved the way the method signatures are displayed so it should use less space and be more readable now, although that's harder to spot than if you compare before-and-after shots.)



Heres another example. This shows a migration in a Rails application, where you're getting code completion on the create_table method.






One interesting aspect of this highlighting is that it's easier to spot mistakes in your comments. As I was testing this feature, I pulled up the documentation on the Rails send_file method - and the following code fragment looked wrong:






Sure enough, it looks like it's missing a single-quote right after 404.html. This is the kind of thing which will be a lot easier to spot and fix with the new enhanced highlighting!



P.S. You don't have to use code completion to get the documentation popup - just hit Ctrl-Shift-Space with the caret on the symbol you want to look up - or Command-Shift-Space on the Mac.



(P.S.2: If you're trying to download this, see my other blog entry on the current temporary download location.)


Where's nbextras.org?

WARNING: This blog entry was imported from my old blog on blogs.sun.com (which used different blogging software), so formatting and links may not be correct.


Updated Monday May 28: The machine is back up and running (and much faster than before). You can grab up to date builds from the old location again (and the wik installationi page points back to it again). The latest builds have both a fix for the RHTML problem as well as support for encoding properties on projects, so the old file.encoding=UTF-8 system property workaround should no longer be necessary.





The deadlock.nbextras.org machine, which I've been pointing to regularly as the best place to get up to date builds of the Ruby support, is off-line. It is being replaced by a brand new machine, much faster and more reliable, and should be back up on-line on Monday (May 28th).



Apologies to those of you relying on deadlock.nbextras.org for regular updates. The service should be getting a lot better from now on. The reason it's taking several days to perform the migration is that this is a volunteer-driven effort, so there's a bit of cooperation necessary to get the machine picked up at the ISP, the disks mirrored over to the new machine and the machine taken back in to the ISP and get back up and running.



In the meantime, I've set up a temporary location where you can get up to date bits. The instructions and URL will be kept up to date on this wiki page.


Friday, May 18, 2007

Ruby Screenshot of the Week #11: Rails Debugging

WARNING: This blog entry was imported from my old blog on blogs.sun.com (which used different blogging software), so formatting and links may not be correct.


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.


Monday, May 14, 2007

It's Over!

WARNING: This blog entry was imported from my old blog on blogs.sun.com (which used different blogging software), so formatting and links may not be correct.


JavaOne 2007 is over. I haven't been blogging lately, and I can truly blame that on JavaOne. It turned out really busy for me: Two keynote demos, one technical session, two Java Posse appearances (our BOF, and NetBeans Day), and a half hour demo at NetBeans day. In addition, the Java Posse got full press treatment this time around, so we had tons of interviews lined up. The picture below was taken right after the Friday keynote when we chatted with James Gosling - in full Posse regalia.






If that doesn't sound all that busy, remember that keynote demos have rehearsals as well as machine setup times, the technical session needed slide edits, etc. I haven't posted any Ruby feature updates recently, and that's partially because I've been busy preparing for JavaOne. That doesn't mean the time has been wasted, though - in actually using the Ruby support as opposed to just building it and testing simple scenarios to see whether a new feature works or not, I discovered lots of issues that have been fixed. Thus, the current trunk build is in much better state than the Milestone 9 bits. Somebody asked us after the Ruby Tooling talk whether the bits we were using are available. They are; get NetBeans 6 milestone 9, and then install the trunk Ruby bits. There are some new features to use as well - I will document those in a separate blog entry.



First however I need to go through my inbox and catch up on all those e-mails I've been ignoring lately. If you're one of them, I sincerely apologize.



Finally, let me end by saying that it was really fun meeting so many of you at JavaOne. To those of you who stopped by and just said thanks for either the Ruby support, or the Java Podcast podcast, I truly appreciate it. Knowing that people find it fun or useful really inspires me to keep going. And don't forget, the Java Posse is doing a live recording tomorrow night at the Silicon Valley Java Users Group, hosted by Verisign. There will be free pizza and beer - and we'll be summing up our impressions from JavaOne. Hope to see some of you there!


Saturday, April 21, 2007

Saturday Morning Hack

WARNING: This blog entry was imported from my old blog on blogs.sun.com (which used different blogging software), so formatting and links may not be correct.


I've heard from a number of people that the ability to jump to a file by type (Open Type), or by filename (Open File) are really important to them. To the point of being adoption blockers.



Both are in the works.



NetBeans has always had a Go To Type for Java (Alt/Ctrl-Shift-O), which we're now retrofitting to become a generic Goto Type facility that other languages can plug into. That means introducing a new API etc. which requires some more effort - so this isn't there for Milestone 9.
However, in the meantime, I've taken the early work on that and hacked it into a Ruby-only module which will let you jump to Ruby types. It's there in the editor context menu (under Go To), bound to a different shortcut. Unlike the general Open Type which will work from any file (or even when you're in a non-source editor window), this will only work from Ruby files. You can get the module
here. That's an NBM file - a netbeans module bundle - which you can install via Tools | Plugins - just switch to the Downloaded tab and point to your NBM. Click Add Plugins. (Sorry, the modules are not signed so you'll get a warning.) It will require a restart. Also, the revamped Plugin Manager is brand new and is stabilizing right now - you may run into some issues. One thing to try is to install one module at a time. You need brand new Ruby bits for this too - go to nbextras.org.



Here's a screenshot of what it looks like (although this includes Java type matches, which the provided hacked module won't do) :






The ability to jump to any file based only on the filename (not the path) is tracked in
issue 44586, and there's been some work happening in a branch. Even though it's not done, you may find it useful in your day to day work. To get it, you can download the module here. Once done, you'll have a Goto File In Project item in your Navigate menu. The operation is faster after the first time.



Finally, I've updated the TextMate snippet importer I recently discussed with some bug fixes - get the latest version here.