Yesterday, we have released an early access version of the upcoming Code Recommenders 2.1, which will be part of Eclipse Luna. But what’s new in Code Recommenders 2.1? First and foremost there’s Snipmatch, Code Recommenders’s integrated snippet search engine.
As all developers know, finding the right code snippet to solve a particular problem can be quite time-consuming. Suppose you want to experiment with some SWT widget. To do so, you know that you need to set up a new Shell together with an event loop, as that’s what just about every SWT snippet does. But the exact details of how to set up such a loop are often hard to recall. So, what do developers do? They search the Web.
Unfortunately, searching the Web is not a very effective way to find valuable snippets. Not only do you have to leave your the comfort of your IDE, you are also faced with thousands (if not millions of results), only some of which provide you with bits of source code that you can copy and paste back into your IDE. (In this example, the search engine’s first hit actual brings you to an excellent tutorial on SWT, including a ready-made event loop, but frequently you end up with hard to digest information in the form of bug reports, mailing-list posts, etc.)
Now, one of the comforts of the Eclipse IDE are so-called templates: If you remember that there exists a template named
mainloop, you are good to go; just enter mainloop, trigger Content Assist, and Eclipse inserts your very own SWT event loop into your code.
But what happens if you know don’t that such a template exists or how exactly it is called (swtloop, eventloop,…)? That’s where Snipmatch comes in. Snipmatch combines the templates’ tight IDE integration with the flexibility of a search engine. Whether you search for a snippet by name, description, or tags (or any combination thereof), Snipmatch will find just the snippet for you. Just press Ctrl + Alt + Space (the default key binding can be changed, of course).
Want to try Snipmatch for yourself? New users can install the Snipmatch addon to Code Recommenders from the project’s milestones update site. Users who have tried out Snipmatch when it was still in incubator project of Code Recommenders’ can simply switch the update site; upgrading will then be seamless.
Next week, in part two of this article on Snipmatch, we will show you how you can create your own snippets and share them with the Eclipse community through the power of (E)Git, Gerrit-based (snippet) code review included.