Tuesday, February 27, 2007

Ruby Screenshot of the Week #5

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.


Tim Bray just posted an entry on his first experiments with the Ruby and NetBeans support and in particular, talks about the syntax highlighting. I was already planning on spending this week's screenshot on the highlighting features, so I'll use Tim's ape.rb source code and show you a few more details:






Notice the following:


  • Notice how unused local variables are highlighted (see dummy which I inserted to make a point - that's not Tim's fault!).
  • Notice how the symbol under the caret gets highlighted along with all other uses of the same symbol! This is pretty useful when you're dealing with
    blocks for example - it will show you that a local variable may be used unintentionally as a block variable and will get modified as a side effect.
  • Notice how methods calls are highlighted in bold. This is handy when you have a typo, and what you thought was a local variable read is actually a call
    to an unbound method.
  • Notice how strings are lexed too. Here you can see that it's telling you (in red italics) "\n" is not expected as an escape code - this is a single quoted String after all.
  • Embedded Ruby code within Strings - #{ } - is properly shown as Ruby code. Occurrences highlighting and code completion works in these sections too.

Regarding the color choices, I should point out that these colors are consistent with the new colors in the Java support in NetBeans 6 - parameters are orange, fields green, unused items gray, and so on.



In doing this screenshot I noticed a couple of bugs I'm off to fix now!


Tuesday, February 20, 2007

Ruby Screenshot of the Week #4

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.


If you try code completion on any complicated arbitrary expression, it will show you a number of possible method completions along with the corresponding class. This gives you much the same information as ri:






However, in many contexts, we know the exact type. For example, if you type File. and invoke code completion, NetBeans will show you only the singleton methods of class File (as well as inherited methods and module mixins):






In some cases, we know more than just the class - we know that we're dealing with an instance of that object. In that case we can show all the instance methods too - not just the class methods:






Here's we're applying code completion on a regular expression literal.



This works for all kinds of literals in your code - Strings, regular expressions (shown above), arrays (try [1,2,3].e to see the each method and its documentation for example), hashes, symbols, numbers, ... you can even try it on the "nil" keyword!


Friday, February 2, 2007

Ruby Screenshot of the Week #3

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.






Yes, the code is now in CVS. Please note that this is under active development. There are known bugs and instability. This is for early adopters only! As things get more stable we'll be making more official builds for a broader audience. I'll post a feature list here soon so you know what you can play with.



Did I mention that this may be unstable? Okay, good. I've posted screenshots here before, but remember that screenshots will show a particular case known to work, not a feature working in all conditions... Don't rush into this with high expectations. I will however be doing my best to fix bugs and add features. Please file bugs with Issuezilla in the scripting category with ruby as a sub category. Join the mailing lists to provide feedback and participate.



Did I mention that this is for early-adopter types only at this stage? Okay, good.



If you felt cheated by the above screenshot, here's another one. Can't remember the escapes in a Regular Expression? No problem!






This is not particular to regular expressions. Try it on dollar variables, or in literal strings. Here's another example: