I'm pleased to announce that I have been accepted as a student for this year's GSoC. After having worked on Nepomuk (now Baloo), I will have the chance to work on KDevelop, the wonderful IDE based on KDE technologies.
How KDevelop Supports Languages
The code editor component of KDevelop is based on Kate, which provides the basic syntax highlighting and editing capabilities (history, cut and paste, formatting, code folding, etc). KDevelop adds some nice features on top of that, for instance code completion and refactoring.
These features require that KDevelop understands the language used by the user. KDevelop has to know how a variable is declared, when it is used, what is a class in the language used, how functions look like, which symbols are visible in a particular context, etc. This is done using language support plugins that build something called a definition-use chain.
The job of these plugins is to parse a document and to build the definition-use chain for them. For instance, when a variable assignation is encountered (
a = 2), the plugin informs KDevelop that the variable "a" has been used. When a variable declaration is encountered, the plugin tells KDevelop where this declaration occurs. This way, KDevelop can highlight the variables in different colors, and if the cursor is on a variable, KDevelop can show on which line the variable has been declared.
The plugin is also responsible for finding the types of the variables. For instance, "a" has been declared on a particular line and is of type "int". This information is very useful to the user.
Type inference is an intersting topic and I worked on it for about two weeks (the first one was mainly thinking and discovering how KDevelop language plugins work, the second one was actual coding, and the third one was dedicated to submitting review requests for all that). The above screenshot shows that KDevelop is able to infer the return type of the function (the equality operator always returns a type), the type of the parameters (when the function is called, I give it integers, so these parameters are likely to be integers), and the type of the variable.
Other type inference mechanisms are also implemented. If I declare a variable and give it a value, the variable will take the type of the value.
var a = "foo"; declares a variable of type string, and writing
a = 3; after this line will change the type of "a" to "unsure (string, int)", because KDevelop cannot say if the variable is a string or an int (I advise the user to avoid writing code like that :-) ).
Plan for the Summer
var o = new Object(); declare o as being an object, with methods and members.
Furthermore, special QML constructs need to be supported. QML has import statements, a special way of declaring objects (by attributing them an "id"), properties having their type declared, etc. This is all very interesting and I hope to be able to support all that by the end of the summer!