Some handy things to know in Eclipse

Hi All,

Here are some tips how to improve your development speed by utilizing some of the features in Eclipse.

Key combination to use within Eclipse:

  • Control-Shift-L: Locates/searches for any servoy resource you have, and opens the editor
  • Control-L: shows a popup where you can type the linenumber you want to jump to
  • Control-Shift-F: Formats you (selected) code
  • Control-/: toggles commenting
  • Control-H: shows a search screen to search all the files in your workspace
  • Control - Space: Trigger code completion
  • Control - O: Quick Outline in the javascript editor to quickly jump to another method/variable

Help->Key Assist: Shows you all the available key combinations

Problems View:
Inside Eclipse there is a View called Problems and it shown you both Warnings and Errors. Errors are off course more serious than warnings. If something isn’t working, check if there are any related Errors or Warnings in your workspace and fix them first. Some of the entries support the Quick Fix option in the rightClick contextual menu if you rightClick the entry.

View the same Resource (Form, sourceCode) multiple times:
You can Rightclick editor tabs to open the same resource again in a new editor: RightClick the editor tab and select New Editor. Then you can drag the new tab around, for example to the bottom of the existing Editor, effectively creating a split view. For example handy when refactoring code.

Add task:
Eclipse allows you to add tasks to your code, without placing them as comments withing your code. Just go to the line of code where you want to add the task and select Edit - Add task from the menuBar. All your tasks are accessible through the Tasks view.

Bookmarks:
Eclipse allows you to create bookmarks for yourself in your code. Just go to the line of code you want to bookmark and select Edit - Add bookmark from the menuBar. All your bookmarks are accessible through the Bookmarks view.

Local history:
Eclipse saves all the changes you make in your code (up to a certain configurable limit (Window - Preferences - General - Workspace - Local History)) and you can have a look at them, by rightClicking your sourcecode and select Compare with - Local History. This will activate the history view in Eclipse. there you will see all the local revisions of your source code file. Select 2 of them by control-clicking and then rightclick the selection to open the two revisions in a Compare Editor. Note: the same mechanism is available when you use SVN or CVS for remote history.

Folding
Window - Preferences - JavaScript - Editor - Folding: Gives you the option to enable folding of Comments, possible making it easier to read code.

Templates
Window - Preferences - JavaScript - Editor - Templates: When you find yourself typing or copy-pasting the same block of code or comment everytime, use this option to create a new template for yourself. The template is then accessible through Code Completion (Control-Space).

If you have any Eclipse tips yourself, please post them here!

Regards,

Paul

Great tips - thanks.

I am finding that often when I hit return in my script, it is putting the cursor somewhere odd on the next line.

If I type

if (a == b) 

then it puts me under the ‘a’. If I type

var a = arguments[0]

it puts me under the 0

I would like it instead to place the cursor under the first character in the line I just ended. I believe that’s what the editor in 3.5 did.

I’ve tried turning off every editor-related option I can find, including ‘smart caret position after new line’ and ‘smart caret position at line start and end’ but it’s still doing it.

Any ideas?

if you do:

if (a == b)

then it is correct that it indents for you when you press enter (if you do have a 1 line if then that is the right place)
If you then type { then that will go back up (under the i of the if)
But this was broken a bit in 4.1 and is already fixed in 4.1.1

about that arguments. I guess this could be improved
the solution for that now is to use ; then the parser knows you really are terminating the line, now it is confused with something else
please make a case for this

If you are like me and you like to know what Eclipse is actually doing then you might want to use the Progress view.
How to install ? Simple.
Go into the perspective you want this new view to be installed (like the Form Design perspective).
Go into the menubar > Window > Show View > Other…
You get a dialog window where you can do a search for ‘progress’ (or just the first characters of this).
Select the item and click the OK button.

Now the view is in your perspective but not yet anchored in it (in fact it’s floating over your other views).
Drag the tab of this Progress view to the position in your perspective where you want it (like under the properties view for example).
Let go and you are set.

You can do this for all the perspectives where you want to see what Servoy/Eclipse is actually doing.

Enjoy :)

Thanks Guys,

Great tips !!!

Hans

This is a nice thread… a few of my favourites (sorry only windows, the mac ones are almost simular)

alt- arrow up/down > move
ctrl-alt-arrow up/down > copy
ctrl-d > delete

all the above shortcuts work on:
a) the line the cursor is currently on
b) the selected line(s) of code

There’s just one downside to these shortcuts: once you are used to them, you end up applying them everywhere else… but it’s just eclipse that will work ;-)

Some other shortcuts that I use all the time are the following:
(you can substitute CMD with CTRL when you are not on a Mac)

  • CMD-SHIFT-A to open a form selected in the tree (or from the method editor of this form!)
  • CMD-SHIFT-Z to open the methods of a form selected in the tree (or from the form editor of this form!)

Also handy to retrace your steps is to use the following commands to move to the editor you were in:
-CMD-[ to go back to the last used editor tabs
-CMD-] to go forward

And another great Eclipse feature:

  • click on a method name you use in your code to put your cursor in it and hit F3 to jump to that method. (also available under right-click)

And Paul already mentioned this one but since it’s such a timesaver I mentioned it again.
Don’t browse, but search…use the CMD-SHIFT-L to jump to a form,method, table,etc (any Servoy object).
Use wildcards like *somename when you don’t know for sure what it starts with.
You can find any Servoy object this way and open it in an editor. Saves you the trip to the Solution Explorer tree.

And new in Servoy 5:

-ALT-SHIFT-A to launch the debug rich-client
-ALT-SHIFT-B to launch the debug web-client

All are big timesavers for me. Less mousing around.

Still forgot one…

ctrl-Q, no in Eclipse not the easy way to quit but the easy way to return to the last edit position.

So… editing a global method, having to look up the context of another global method. Then hit ctrl-Q and you will return to the last edit position of the earlier global method.

I don’t like seeing all the code for all the methods in an editor. Here’s how to restrict the code being shown to the selected method in the outline view.

There is an Eclipse command called “Show selected element only” that is not key-bound. Go to Preferences > General > Keys and set a key binding to this command. Have it run “When in windows”.

This command will now work when you have a method editor sheet open and the outline view has the focus. Notice in the attached screen shots that I don’t show variables in my outline view either to make things easier to navigate.

You can basically keep this on all the time and forget about it. If a method is selected in the outline view, you get filtering. You can go back to unfiltered by not having a method selected (click somewhere empty in the outline view window).

In Eclipse, the challenge is all about filtering out the the stuff you don’t need to see at any given moment. This is my favorite.

ow guys! keep on going! I love this topic! :D :D

Nice one David, emulating Servoy 3.5 behavior in Servoy 4/41/5 :D

David,

no need for a keybinding for this (ofcourse it could be handy)
What you configure is a toolbar action/command

right click on the toolbar (empty part) → customize perspective → Tab: toolbar visibility → Editor Presentation → Select the “show source of selected element only”

That will present you with a toolbar icon in your current perspective

jcompagner:
David,

no need for a keybinding for this (ofcourse it could be handy)
What you configure is a toolbar action/command

right click on the toolbar (empty part) → customize perspective → Tab: toolbar visibility → Editor Presentation → Select the “show source of selected element only”

That will present you with a toolbar icon in your current perspective

Ahha, that’s how that’s done. Servoy 4 had that icon by default. Cool!

In Servoy 5.0 you can set under Preferences / Javascript / Error/ Warnings a setting: STRICT MODE.
This will give you autochecks on your code.


Briefly, Rhino reports warnings in strict mode for

assignments to undefined variables
references to undefined properties
inconsistent return statements in a function
duplicate parameter names
variables that hide parameters
assignment in a conditional
trailing comma in object initializer
indirect calls to eval
useless expressions

It will save a lot of time with debuging/testing your methods. You can see in PROBLEMS view the errors and warnings.

The reports gave a lot of warnings which I didn’t expect. Most of the errors had to do with variables and return values.

Examples:
function x(a,a) {…} //will raise a warning about the duplicate arguments
function x(a) {var a = 10} //will raise a warning about hiding an argument
if (x = 10) //will raise a warning about doing an assignment (“if ((x = 10))” will not!)
var a = 10; var a = 11 //will raise warning about redeclaration of variable
function x() { if (true) { return 1} else {}} //will raise warning about inconsistent returns

I still have some errors “Code has no side effects” DLTK type. It has to do with some find() … search() methods. Something to do with operators “<” or " >"

Our debug perspective setup. Rearranged to make coding and debugging easier (at least to us).

If you haven’t tried this already, you can drag views (click and drag any tab) and whole blocks of views (click and drag the section header) and place them wherever you want in the Eclipse window. Then save under “Window > Save perspective as…”.

I did not see this one posted earlier, but found it really useful.

While in a smart debug client:
Clicking into a form and hitting ctrl-l will open the form in your Eclipse form designer. Very handy during debugging.

Jason

In the debugger you have a Variables view and an Expressions view.
The Variables view shows all variables and objects that are available when you hit a breakpoint or fall into the debugger with an error.
This list can be quite large and you might have to dig deep in a tree to find, lets say a global variable, you wanted to check.
To focus on some specific objects and/or variables you can use the Expressions view. You need to right click on the view and select Add Watch Expression to get a dialog where you can type in your expression to watch. Of course you need to make sure you don’t make any typos.

There is however a faster and easier way of doing all this. Simply drag the variable from the Variables view to the Expressions view and drop it there.

You perhaps want to check out the result of some expression you use in your code ? Just copy the code and paste it into the Expressions view.

So Drag & Drop and Paste are your friends when it comes to the Expressions view

Thanks to Providence for showing me this. :)
Happy debugging!

METHOD EDITOR HYPERLINKING

I’m not sure if “hyperlinking” is the correct term, but the method editor now has this very cool feature where you can jump to referenced objects.

To trigger, hold the cmd key (on a mac anyways) and you will get an underline under various snippets of code that are hyperlinked to their original references. Clicking a link will take you to the source and if necessary even open the editor for that source (if different than the method editor). Hyperlinks we’ve discovered so far:

1- Variables

Will jump you to where the variable is defined.

2- Methods

Will jump you to the method. Will open another method editor if that method is not in the current editor.

3- Relationships

Will open the relationship in the relationship editor.

4. Forms

Will open the form in form design editor.

david:
To trigger, hold the cmd key (on a mac anyways) and you will get an underline under various snippets of code that are hyperlinked to their original references. Clicking a link will take you to the source and if necessary even open the editor for that source (if different than the method editor)

On windows this happens when holding “Ctrl”.
Note that it is even faster to press “F3”, that will take you there directly without having to wait for the hyperlink and click it.

If you’re working with one Servoy Developer instance, but many workspaces, you might want to see in Servoy Developer to which workspace you are currently connected.

This is possible by adding a new line at the top of servoy.ini in the {servoy_install}/developer directory with the following content:

-showlocation

When you do, the workspace you are currently connected to will be displayed in the Servoy Developer Title bar.

Paul