Tor Norbye's Weblog
"Creator" on this page refers to Sun Java Studio Creator.
« Progress | Main | Jump In - The Water'... »

20070711 Wednesday July 11, 2007

Ruby Screenshot of the Week #15: Hints and Quick Fixes!

I've justed checked in support for Ruby hints and quickfixes. Most Java IDE users should be familiar with this, but I'll illustrate with some screenshots:

I've opened a Ruby file - notice the little lightbulb thingy and the underline on one of the lines:

The tooltip for the lightbulb will tell you that you have a block variable which is reusing a local variable. This means that the local variable will be modified by the block - which is sometimes not intentional. Let's put the caret there and press Alt-Enter (or invoke the "Fix Code..." item from the Source menu)

You can now use the arrow keys to choose among the available fixes, and press Return to apply one. This will initiate in-place editing of only the local variable references (or only the block variable references, depending on which fix you selected). When you're done you have a unique block variable that is no longer aliasing or side-effecting the local variable:

(The in-place editing is still a bit buggy because of issue 108889. Hopefully we can get it fixed soon.)

Here's another hint: Rails Deprecations. This looks for usages of deprecated Rails idioms, and adds little warning signs with a description. Here's an example of how this looks:

In the above code, you're using the @request field, instead of the request or request= attribute methods. And by the way, if any Rails experts are reading this: The Rails Deprecation document describes these fields are deprecated, yet the Rails code generator itself spits out code which uses them (specifically, in the controller's functional test). Is there a good reason for this? For now, the rails deprecation hint skips Rails test files when scanning for this issue.

Here's another Rails deprecation example - using one of the various deprecated methods. The tip also states the suggested replacement:

And finally, here's a line-specific quickfix. It only kicks in to analyze the current line and is suitable for things you wouldn't want splattered all over your file, such as offers to create classes and methods etc. This tip looks for class or method definitions on a single line, and offers to split and reformat them across multiple lines (I think Charlie requested this one). Here's a typical same-line-class put into a rails controller test:

Applying the fix yields the expected result - semicolons removed, newlines placed in the right places and indentation fixed as expected:

You can configure the available hints under options. (The Ruby options are going to be expanded and reorganized shortly). Here's the hints panel which lets you see the available hints, enable/disable them, and configure whether each hint is shown as a warning, an error, or a warning on the cursor-line only.

Notice how the list of hints is kinda short today... That will be the topic of my next blog entry!

P.S. We're after feature freeze so whether this appears on the update center or in the default product remains to be seen, but I'm always an optimist. In any case, it will be easy to access it. For now however it's in the daily builds

(2007-07-11 15:45:09.0) Permalink Comments [6]

Comments:

Is there a hotkey to access the IDE annotations on the current line without using the mouse?

Posted by 217.74.220.92 on July 11, 2007 at 04:23 PM PDT #

Alt-Enter - or did you mean something else?

Posted by Tor Norbye on July 11, 2007 at 04:26 PM PDT #

As a Rails and Ruby newbie, I need all the help I can get. This is awesome stuff!

Posted by Nathan Fiedler on July 11, 2007 at 05:22 PM PDT #

Hi Tor! The macroses stop to work in the last release (2897) - i create macros, set shortcut for it, but it doesn't work. and another thing - after creating the macros and setting the shortcut i need go to options and reset shortcut again - cause it vanish (this was in previous versions too). Also code templation works badly - try to use .each for example - you will see. And still problems with editing rhtml code - stings get screwed Thanks!

Posted by freeman on July 11, 2007 at 07:30 PM PDT #

Hi Freeman, there were some recent changes in editor settings storage which caused some problems. We discussed them on dev@ruby.netbeans.org, and here's what one of the editor developers said:
Yes, I did some cleaning and there were several defects that should already be fixed. Please try again in the latest dev build. If it does not work file a defect for editor/settings. As a workaround it usually helps to just open and close (cancel) Tools-Options dialog. If not, try Tools-Options -> Advanced Options, find Editor Settings node and click its handle to show all children. The side-effect of this is the reset and reload of settings for all editors.
and
Yes, that was a problem in all editors, but it should already work in recent dev builds. Sorry for the troubles.
and
Please try it again in the latest dev build. It should already work. If it does not file a bug to editor/settings and I'll see if there is some more fixing needed for Schliemann based editors.
So, hopefully the problems you've described with YAML and other editor settings (such as macros?) in previous blog comments are fixed now. If not, please let me know, either with the issue tracker (preferred) or by direct mail - see http://wiki.netbeans.org/wiki/view/RubyFeedback.

Can you providde a few more details on "code templation" - did you mean code templates or code completion? I tried with code completion and each seems to work okay. Also, can you be a bit more specific about what the problem is with editing rhtml code - is it the keybinding issue you've described earlier, or something else?

Posted by Tor Norbye on July 12, 2007 at 08:45 AM PDT #

hi Tor! i've checked the last build - the macrosess don't work, and also "Scripting Language Options" dissapeared from [Advanced Options => Editor setting], so now it's impossible to turn off the Text Limit Line

Posted by freeman on July 16, 2007 at 09:25 PM PDT #

Post a Comment:

Comments are closed for this entry.