Thursday, September 20, 2007

Ruby Screenshot of the Week #18: Errors and Snippets

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

Tim Bray just wrote about error messages and their occasional difficulty for users. I ran into the same issue myself a couple of weeks ago when somebody filed a bug that NetBeans didn't correctly handle Ruby documentation markers. When looking at the user's source, I realized the error was right in the user's source file - but the parser message hadn't been particularly helpful: Syntax error, unexpected =.

This of course seems like an area where the IDE can help. So, as of the latest builds, there are some error rule handlers (in the experimental hints plugin) to help with this. Suppose you try to add in a documentation block like this:

The lightbulb on top of the stop sign tells you there's an associated suggestion. Press Alt-Enter to see the error message and suggested fix:

Applying the fix will obviously correct the indentation of =begin and =end. Here's another example - opening a file with ambiguous parameters:

I would really like your ideas on other common error patterns I can detect and better yet, fix. (See
RubyFeedback or leave comments here.)

While we're on the topic of quick fixes, the experimental hints also include some new suggestions for converting between brace blocks and do/end blocks. If you place the caret within the first line of a do-block or a {}-block, a little lightbulb will appear in the left margin. If you press Alt-Enter, you'll see some applicable fixes:

The exact list of choices shown obviously depends on the block. If you do this from a do/end block, the conversion goes in the opposite direction. And if you're looking at a multi-line block rather than a single line block, it will offer to collapse the block into a single line rather than expanding it as shown here. (It only offers this if it can fit the statements on a single line within the right-hand side margin, as shown by the faint red line in the editor.)

Unsurprisingly, applying the first fix gives us this source code for the block:

(This operation will sometimes also insert parentheses around the previous argument list when necessary, since {}-blocks have different precedence than do-end blocks.)

Finally, I just fixed some bugs in the code template handling code. If you invoke code completion you should now see the possible code snippets that match your input - along with their tab trigger names on the right and the full code template in the documentation popup:

That's it for now. Don't forget that NetBeans 6.0 Beta 1 was just released. The
New And Noteworthy document has the rundown on the new features included since Milestone 10. (Most of the things I've described in this blog entry were checked in after the beta cut off but beta is more stable for regular use.)

P.S. Rails creator David Heinemeier Hansson had some nice things to say about Sun's Ruby and Rails efforts. There's no evil plan, I promise!

No comments:

Post a Comment