Problematic Imports

I'm teaching myself scala and have been using IDEA with the Scala plugin as my IDE. As such, I've been looking at and loading a lot of existing code/sample code, but while most of the code compiles and runs fine, IDEA lists a ton of errors. I've seen other discussions here about this.

One example of a fairly complex Lift based app is from the Lift book at http://github.com/tjweir/pocketchangeapp/tree/master. It would seem to me that looking at projects like these and making sure they all load in IDEA with at worst yellow status would help get things like import handling in line.

--Tim

8 comments

You shouid say something about the errors you're seeing.

Did you configure a proper complement of Scala library and compiler JARs into your project? The IDEA Scala plug-in should download the latest Scala release (not 2.8, which isn't released yet) when first installed, but you have to add them to your project's library configuration.


Randall Schulz

0

For the case of Pocket Change, I took the following steps:

- Grabbed the code with "git clone".
- Built and did a quick test with "mvn jetty:run".
- Opened the pom.xml with Idea.

The project indicates that it is using Scala 2.7.3, so I don't think that should be an issue. Pretty much every file I open has some red, some of it quite a bit. But as mentioned, the project compiles and runs. So their seems to be some disconnect between how IDEA parses the code and the compiler. I've been able to write code that is clean in IDEA and that runs, so I don't think there is a fundamental issue with my installation. I think it is just a matter of certain projects using somewhat different conventions.

I mention this example in particular as it is the sample app from the Lift book, but I've run into similar issues working through some of the examples in some of the straight Scala books.

I realize that I'm working with an EAP plugin and as I said, I'm using this as a learning exercise, but I think these are the kind of things which one would hope would work out of the box once it comes out of EAP.

--Tim

0

mumbly wrote:

For the case of Pocket Change, I took the following steps:


- Grabbed the code with "git clone".
- Built and did a quick test with "mvn jetty:run".
- Opened the pom.xml with Idea.


The project indicates that it is using Scala 2.7.3, so I don't think that should be an issue. Pretty much every file I open has some red, some of it quite a bit. But as mentioned, the project compiles and runs. So their seems to be some disconnect between how IDEA parses the code and the compiler. I've been able to write code that is clean in IDEA and that runs, so I don't think there is a fundamental issue with my installation. I think it is just a matter of certain projects using somewhat different conventions.


There is no such "disconnect." At the moment, I am aware of only one spurious error, and it is not syntactic, but rather a case of the Scala plug-in improperly failing to determine that a symbol is in scope for particular (and somewhat peculiar) kind of use. (See http://www.jetbrains.net/devnet/message/5243210 if you're interested.)

And it is not about "different conventions," since by definition conventions do not intersect with correctness.

I realize that I'm working with an EAP plugin and as I said, I'm using this as a learning exercise, but I think these are the kind of things which one would hope would work out of the box once it comes out of EAP.


--Tim


It is not final, but it not only works well, it works better than any of its competitors.

If you are seeing a lot of spurious errors (and you still haven't given any specific information about those erros) then it is almost certainly because you have not configured your project correctly. I ask you again, did you specify the Scala libraries as dependencies of your project?


Randall Schulz

0

Scala, it seems to me, has a fairly complex import system, at least when compared to Java and there seem to be different ways of accomplishing the same thing. I don't think it is out of line to wonder if the plugin might work correctly for one way of importing a class/package and not another. It is, after all, an EAP and has a bug list. Correct may be correct, but is rarely that simple in reality.

I did the three steps listed, no more, no less. It seemed to be a fairly simple, reproducible test case. It also is a method which seems to work generally well for non-Scala projects and is how I would expect most developers would go about importing an existing Maven Scala project into IDEA. Perhaps the problem is not in its Scala support, which may be the best available, but in loading a project via Maven or in detecting a Scala project. I will take a closer look and see if I can put together some more specific details about the environment and what may or may not be working.

An example of one import:

  import scala.xml.{NodeSeq,Text}

fails on scala:

  import _root_.scala.xml.{NodeSeq,Text}

fails on NodeSeq & Text:

  import _root_.scala.xml.Text

works. By fails I mean is highlighted in red and works meaning no indicated error. The first entry is the original and works fine compiling from the command line.

--Tim

0

Please, oh please, look in your Project definition and see what library dependencies are configured.

Are you aware that in addition to the red highlight, there is a tool-tip with the actual error message on the red gutter marks? It would be helpful to know more than just "it's marked red." All errors are marked red.


Randall Schulz

0

Hi Tim,

What version of IntelliJ are you using? IntelliJ 8 (Diana), or (9 Maia). Which build?
What version of the Scala plugin?
Can you see the Scala SDK in the Libraries under the Project view?

I checked out your project and imported it into Maia 10624 with the (unreleased) trunk revision of the plugin, and the resolution works okay. This sounds similar to a bug we fixed about 2 weeks ago, if you wait for the next build it may be solved. There has been a lot of work recently to support the new Scala 2.8 package nesting, but I believe Alexander has been merging many fixes from the Maia plugin version to the Diana version. Keep an eye on this forum and on http://jetbrains.net/confluence/display/SCA/Version+History for the next release.

You are right, the plugin implements its own parser and identifier resolution, so there are cases when valid code can appear red. This is either a plugin bug, or a classpath error. If you are a pom to define your classpath, it is more likely a plugin error.

regards,

-jason

0

I'm using 9M1 with the latest released version of the plugin. I'm going to wait for the next plugin release and follow the same steps for creating the project. If it doesn't work as expected then, I will file a bug. A quick look at the project makes me think that the project was not properly imported by loading the pom.xml, so this may be more of a 9M1 issue than a Scala issue, so I'll also try loading it in 8.x and using "mvn idea:idea" to generate the project files.

I'll follow up with what I find in any case.

Thanks to the both of you for the help.

--Tim

0

I guess I should have taken the five minutes to try my last suggestion before posting so I wouldn't have to reply to myself, but.....

So it definitely looks like the importing of the project from the pom.xml. I wiped away the IDEA files and used "mvn idea:idea". With this configuration, everything (or at least the handful of items I looked at) looked good. Just to make sure that it really was loading from the pom.xml, I wiped the working config files and then loaded once again from the pom.xml and the red came out again. So I'll wait for 9M2 to see if it fixes this issue and if not, file an issue on IDEA.

Thanks again.

--Tim

0

Please sign in to leave a comment.