Migration to GitHub

As you probably know we have GitHub mirror of Scala plugin sources: https://github.com/JetBrains/intellij-scala

From now it’s not a mirror, it’s working repository. So it’s good idea to start social activity on GitHub right now.

Posted in Uncategorized | 4 Comments

How to configure Scala plugin project

This post is inspired by Scalathon 2012 conference, where we found few enthusiasts, who want to improve their favorite IDE for Scala, they just didn’t know how to do it.

Scala plugin project setup was simplified a lot recently. Additionally we added full guides about such setup:

  • Here you can find full guide about setting up Scala plugin project.
  • Here you can find complete guide about how to start writing new plugins for Scala (in case, for example, if you have your own compiler plugin and you want to have the same things in IntelliJ IDEA).

In case if you want to try, you can contact me for any question (including questions about bugs and API questions): Alexander Podkhalyuzin

Posted in Uncategorized | 2 Comments

I18n for Scala

The internationalization (I18N) support is available now in Scala plugin with following features:

  • Folding for i18n messages

  • Create new property intention

  • Navigation

  • Completion


    Posted in Uncategorized | 4 Comments

    Play 2.0 support

    We are announcing start of Play 2.0 support. Alpha version of new Play 2.0 plugin  for IntelliJ IDEA just released: http://plugins.intellij.net/plugin/index?pr=&pluginId=7080

    It comes with basic template language support, which includes go to declaration, completion and some features inherited from Scala and Html editors.

    Plugin screen

    We are planning to implement other cool features like formatter, project wizard, refactorings and etc. Please feel free to report any problems and new features suggestions to our Scala plugin bugtracker (Play 2.0 plugin is part of Scala plugin infrastructure): http://youtrack.jetbrains.com/issues/SCL

    Posted in Uncategorized | 9 Comments

    Format and convert

    The truth is that programmers often need to embed dynamic variables into static string patterns. To accomplish this feat we used to write something like:

    or even

    A good news is that Scala 2.10 brings a shiny new string interpolation:

    The new syntax is more concise, offers more static checking and provides a better runtime performance.

    To facilitate the transition, Scala plugin introduced a new group of intentions to easily convert between all the variants of string formatting:





    In addition, we now have a complete format string and argument verification in the following places:

    • "…".format(…)
    • ….formatted("…")
    • String.format("…", …)
    • printf("…", …)
    • System.out.printf("…", …)
    • Interpolated strings

    The verification is even more fine-grained than the similar one in Java:

    All the functionality is already available in the Scala plugin nightly builds (Nika | Leda).

    Enjoy!

    Posted in Uncategorized | 2 Comments

    Mutable/immutable collections prefix convention support

    As described here we should prefer the following code style for mutable and immutable collection names:

    Scala plugin for IntelliJ IDEA (nightly builds) now supports this code style by default.

    First of all, it brings useful code inspection, helping to migrate from different code style:

    Second is class name completion and auto-import features. They both support this code style. And everywhere, where you need to import something mutable, it will be imported with such prefix according to this code style.

    Third thing is that basic completion considers “import scala.collection.mutable” import as placeholder import. So there is no necessity to use class name completion everytime, when you want to use mutable completion.

    And it’s not all. The last thing is that it works not only for collections. You can define any set of classes, which should support such code style.

    Check “Settings -> Scala -> Imports -> Classes to use only with prefix”. Here you can add your own classes (if you have some other name clashes), or you can remove current classes (in case if you don’t want to use this code style for mutable colletions).

    Posted in Uncategorized | 3 Comments

    Embrace Recursion

    Recursion is an essential tool in functional programming (FP) – it is the canonical way (and often the only way) to represent iteration.

    Being a hybrid object/functional language, Scala offers both recursion and imperative control structures (like do, while, etc) to express iteration. However, imperative control statements imply using mutable state, while Scala (and FP in general) encourages data immutability. That is why you may prefer to use recursion (or higher order functions) in the first place.

    To facilitate the FP approach to recursion, Scala offers:

    So far so good. Yet the underlying platform (i.e. JVM) still uses up a call stack for non-tail recursive methods, so we can get a nasty stack overflow in no time while processing reasonably large amounts of data. Therefore it is a good idea to know where recursion lurks (and to easily distinguish its type).

    While, in real-life code, recursion is not always obvious, new icons help us to reveal it:

    Method with recursion icon

    Let’s (for the sake of example) rewrite our linear recursion to tail recursion:

    Method with tail recursion

    We can use an intention (Alt + Enter) to automatically add @tailrec annotation which guarantees that compiler will always optimize the method (or will refuse to compile it).

    An intention to add @tailrec annotation

    After we (accidentally) change the method back to the linear recursion, we can immediately notice the violation of the contract:

    Method with linear recursion annotated as @tailrec

    If you wish, you may enable an optional “No @tailrec annotation inspection” which suggests to add @tailrec annotation when needed.

    Posted in Uncategorized | 6 Comments

    New intentions for Scala

    Intentions were extended with several new.

    • Now you can simply switch between two different ways of writing expressions – infix and method call. Convert infix notation to method call (and vice versa) intention provides you this possibility. It appears when you put caret to the operation in your statement.


    Result:

    • Intention for removing unnecessary ‘apply’ simplifies your code.


    Result:

    But in some cases it’s impossible to do this action. So, you will see error hint, which explains you reasons of rejecting your action. For example:


    • Now you are able to introduce explicit parameters in anonymous function (and vice versa). Sometimes you meet with situations, when you write function with implicit parameters, but then realize that you  must add new parameters or do something else that is impossible to do with implicit parameters. This intention provides you possibility to replace your infix expression with function expression. If you put caret near the placeholder you will be able to use this intention.

    After converting you can change parameters names:

    Also you can perform reverse converting. But in some cases it is impossible to refactor this authomatically, because of, for example, incorrect order of parameters usages. So you will see error hint with explanations.

    • Replace ‘==’ with ‘equals’ and replace ‘equals’ with ‘==’ intentions work both in infix and method call expressions. You should put your caret into ‘==’ or ‘equals’.

    • Swap operands intention swaps the operands of a comparison expression. It works with all following operators: ‘<’, ‘>’, ‘<=’, ‘>=’, ‘!=’, ‘==’, ‘eq’, ‘ne’, ‘equals’ and both in infix and method call expressions.

    Posted in Uncategorized | 5 Comments

    What’s changed in completion

    Recently completion was improved, so I want to describe most significant changes:

    • Basic completion works as Class Name completion in case if nothing found. If something is found, you can invoke second basic completion to observe classes, which you want to import.
      So if you want to import for example HashMap you can just type HashMap and choose appropriate variant (in case if autopopup completion is enabled).
    • Completion after ‘@’ is smarter now. Both class name and basic completions show only annotations (scala and java).
    • Added false, true, this and prefixed this to smart completion. Added prefixed this and super to basic completion (so now it’s much simpler to type such code).
    • String.length, String.hashCode, String.trim has no side effects, so it’s always completing without unnecessary, annoying parentheses.
    • Class name completion after point tries to find possible implicit conversions (with fixing imports), for example:
    • Basic completion can filter inappropriate variants after implicit conversions in case if there are two implicit conversions, which lead to two elements with same signature. It means that this is impossible to use such variant, because of implicit ambiguity. For example parameter ‘x’ in class ‘Ensuring’ and parameter ‘x’ in class ‘ArrowAssoc’, these variants are bad, so it can be filtered.
    • All completion can choose variants of same name, which have the biggest priority in place, where completion was invoked, so you will see only variant, to which actually will be resolved reference after completion. So it means that shadowing is supported by completion.
    • classOf completion always inserts ‘[]’.
    • Class name completion supports aliased imports.
    • Improved completion from Java for Scala keywords like ‘Thread.yield’ (it suggests only back-ticked variant).
    • Added smart completion for eta expanded functions:
    • Added smart completion for enum elements (Java and Scala).
    • Added smart completion for factory methods (static methods for Java classes, methods from companion object for Scala classes).
    • Name completion for classes. On toplevel if there is no class matching to file name, it suggests file name as class name. For all possible companion classes it suggests name of these classes (to make creation of companion objects faster and less error-prone).
    • Some completion now works on first invocation (http://blog.jetbrains.com/scala/2011/09/16/some-smart-completion/).
    • Second smart completion searches chains of methods:
    • Fixed many bugs and usability problems.
    Posted in Uncategorized | 7 Comments

    Scaladoc 2 Support

    Last releases are coming with full scaladoc 2 support

    • Go to declaration and Auto completion for entity links and @throws tags
    •  

       

       

    • Go to declaration, Auto completion, Renaming and Generation by signature for @tparam and @param tags
    •  

       

       

    • Highlighting and Brace matching for wiki syntax and html tags  

    • Some Inspections (unknown tag, missing parameter, unknown or duplicating parameter, inspections for wiki syntax, missing parameter description) and Quick fixes (delete unknown tag/parameter, quick fixes for wiki syntax)   

     

     

     

    • Alignment for @tags
      Posted in Uncategorized | 6 Comments