Google Summer of Code 2010 @ Scala IDE
UPDATE: an update site including Jin’s GSoC work is now available.
I was lucky enough to be the mentor on a Scala IDE for Eclipse project which was selected for this year’s Google Summer of Code. Jin Mingjian was the student for this project, and it’s been wonderful to work with him over the last few months.
Jin completed his Doctoral degree at the Institute of Electrical Engineering in the Chinese Academy of Sciences this summer … having to deal with his PhD defence at the same time as the GSoC project was quite a tall order!
He had this to say about himself and about his project …
I have been involved with the Eclipse community for a long time. When I discovered Scala this year, I realized that it was the language that I need. The openness of Scala struck me, as much as the technical merits of the language itself. The Scala IDE community combines two great open source communities and this summer’s GSoC gave me the opportunity to work on it. I like being part of this community. Join us to help to create great Scala tools!
Now that the GSoC ‘pencils down’ date has arrived, it is time to report to the community about the achievements of my Scala IDE project. The goal of this project is to provide Advanced Semantic Tools for the Scala IDE for Eclipse.
First, I am very appreciative for lots of helpful suggestions, advice and encouragement from my mentor Miles Sabin and other guys in the community. Without their help, it would not have been possible to finish this project.
There is a wiki page on the Scala IDE project site which explains some aspects of the features. Let me introduce them by starting with an example code snippet,
object String2Int {
val a = "1";
var b: java.lang.String = "3";
implicit val somewords = new SomeWords("yeah!")
implicit def string2Int(s: String) = {
((s.toInt)+1)
}
def main(args:Array[String]) {
printInt(string2Int("3"))
printInt(a+b)
printIntWithSomeWords("5")(new SomeWords("..."))
printIntWithSomeWords(2)
val map = Map( 1 ->"one",2->"two")
}
def printInt(a:Int) {
println(a)
}
def printIntWithSomeWords(a: Int)(implicit sw: SomeWords) {
println(a)
println(sw.words)
}
class SomeWords(val words: String)
}
This code stems from an example in Programming in Scala. But I modified it to be “more implicit”.
When you open the editor, all the places where implicit conversions and implicit parameters occur (not the implicit definitions themselves) have been highlighted, as follows,
Perhaps you don’t like the default green squiggly underlines as the visual indicator of implicit occurrences? Then you can customize the highlight style via Windows -> Preferences -> Scala -> Editor -> Syntax Coloring as follows,
You can hide the highlighting by clearing the checkboxes and setting the underline style to “none”. In future we will add an enable/disable check box to simplify this process.
Along with the visual annotation for implicits, we provide automation around the annotation, known in Eclipse terminology as “quick assists”. The default shortcut for quick assist is “Ctrl+1″. The following screenshot shows the quick assist for an implicit conversion,
After applying this quick assist we get the explicit version of above implicit conversion,
The following screenshot shows the quick assist for implicit parameters,
After the applying the quick assist, we see the implicit arguments defined in the scope explicitly inlined as follows,
One of Scala’s important features is support for type inference. With type inference we are not forced to write many tedious type decorations. However, Scala is a strongly type language and in some contexts it is better to declare the type explicitly, for example method return types.
So we have added functionality which provides explicit type completion, activated automatically by typing “:”. The current implementation is limited to val and method definitions for which the type can be inferred.
The following screenshot shows that I want to add an explicit type for val map. So I type the “:” after the map identifier. Then I get the inferred type quick assist here,
When I press Enter, we see the following,
Currently the explicit type is a little long. In future we will allow the qualified part to be moved to the import section.
It is a best practice to add explicit return types for methods (other than for methods which return Unit type). And sometimes you forget to add the “=” when defining a method. This makes the whole method return Unit unfortunately. With our new functionality and that best practice quick assist, you can find and fix this kind of mistake easily. For example, suppose you wanted to add the type for the method by “:” auto-completion. But you find that the proposed type is Unit. Then you will realize that you missed the “=”,
Correct it and add the right type again as follows,
Adding explicit types for val and method definition is a piece of cake now. In future we will improve explicit type completion to propose types from the classpath if the exact type cannot be inferred.
What do you think about these new features? A build/update site of the GSoC branch will be available shortly and any feedback will be appreciated. When the features has been proven stable, we will merge them into the main distribution. Then everyone can try them out!










