Imports miss nested package references since 0.2.26899

In scala plugin versions 0.2.26899 and 0.2.27038 IntelliJ compiles my scala code without a problem, but in the editor my imports appear broken (and class usages in the code are not resolved).  The problem appears to be that the parser doesn't allow nested packages.  For example, given package struture like this:

#File MyTestApp.scala
package edu.testing.applications
class MyTestApp

#File MyTest2.scala
package edu.testing.anotherapplication
import applications.MyTestApp

In the last line, IntelliJ fails to allow this import (it's marked in red), and auto-import suggests the line "import edu.testing.applications.MyTestApp"

It would take a great deal of time to visit every one of my scala files in order to give the fully specified packgaes for imports instead of the package-relative imports, which are currently specified.  Is this a known bug in the recent plug-in?  Or is this a change to scala?  Or is this a permanent feature of the new plug-in?  I'm just trying to avoid having to visit all my files to make all my imports absolute, unless/until it's necessary.  This was working properly in the latest 8.1.3 scala plugin.

Thanks,
Sam Reid

6 comments

It's necessary for scala 2.8. In scala 2.8 for relative packages you need to do following:

#File MyTestApp.scala
package edu.testing.applications
class MyTestApp

#File MyTest2.scala
package edu.testing
package anotherapplication
import applications.MyTestApp



Second file is shorthand for:

#File MyTest2.scala
package edu.testing {
  package anotherapplication {
    import applications.MyTestApp
  }
}



In case it's scala 2.8 feature, to use relative imports, you need to use scala 2.8. (I hope, that in few monthes you want to migrate on scala 2.8)
If you still want to use scala 2.7 you need to use only absolute names (autoimport works fine in this case).
This is not very good, that we force you for it (it would be better if you can choose language version), but this is how we did.
Scala 2.8 now installed with pluigin.

Best regards,
Alexander Podkhalyuzin.
0

Thanks for your prompt response to my question.  I tried replacing my packages of the form:
package a.b.c
with the new syntax
package a
package b
package c

This caused my code to pass IntelliJ's syntax highlighter (no more red), but then compilation using the scala compiler fails, probably because I'm still using a 2.7 compiler.  So here are my options, and I'm not sure which will be the best solution:

1. Rewrite all imports to use the 2.8-style absolute references
     This will require some manual labor, but I think the result should work under IntelliJ 9 (with 2.8 syntax) and with the 2.7 compiler
2. Use the nested packages as above, and update to whatever beta version of 2.8 is available
     I'm a bit skeptical about this since I'm not sure how stable the 2.8's are.
3. Stick with IntelliJ 8.0 and scala 2.7 for now.
     I'd rather keep up to date with the plugin

What do you think is the best short term solution and the best long term solution?

Also, I hadn't seen this new "feature" discussed in any of the scala pages, can you point me to documentation about the new packages/imports changes for 2.8?

Thanks,
Sam Reid

0

In our code we chose 2. Now we compile under 2.8, and use 2.8 syntax of nested annotations. Also we can use naming and default parameters (it's handy, when compiler compiles without crashes).
About changes you can read in scala-internals@listes.epfl.ch mailing list, on in scala language trunk.
Scala plugin for intelliJ IDEA now includes some scala-language snapshot (under which we compile our plugin), so it's more or less stable. You can simply change compiler in scala facet page (project settings).
If you don't like scala 2.8, then I suggest you to choose 1. If you use setting "Add unambiguous imports on fly" then it will be simple. Just to write regexp replace to delete all imports. And after it open every file and add missed imports (moreover, you'll possible find some autoimport bugs:) and we will be happy for it:)). Certainly, it's harder as I described, but not really hard.

Best regards,
Alexander Podkhalyuzin.

0

Thanks for your suggestions.  I tried using the "Add unambiguous imports on the fly" but it did not seem to do anything for scala files in Idea 10762 + scala 0.2.27038 (I didn't test whether it worked for Java files).  Does this feature work for you in scala files?  It seems like it will be the best way to move to 2.8.

Thanks again,
Sam Reid

0

You said about Java setting. Use same setting in scala settings page (imports tab).

Best regards,
Alexander Podkhalyuzin.

0

Thanks, I didn't know about the scala-specific setting page.  Now it looks like everything's working very well.

Thanks again for your help,
Sam Reid

0

Please sign in to leave a comment.