Scala Plugin for NetBeans - Rewrite in Scala #3: Ready for Beta Test

I struggled with  new redesigned IDE / compiler interface (interative.Global) during this weekend, and finally, got it attached to NetBeans Scala plugin, which runs as a background daemon thread, thus the plugin is more responsive when coding (the first benefit). It was a hard work though, I had to modify some of the original code to get whole things stable and responsive (balance), it paid me 2 sleepless nights.

So here's what's new on current nightly built:

  • Tested and work with Scala 2.8.0.r18542 snapshot
  • Better supporting for mixed Java/Scala project
  • Better indentation and formatter for unfinished line after 'if', 'else', '=', 'for', 'while', 'do' etc
  • Better code completion even for implicit methods (some times)
  • Implicit method call will be highlighted by underline
  • Select parts of code, press '{', '[', '(', '"', '`' etc will add/replace surrounding pair, press '~' will remove them. Specially, press '/' will block comment it
  • Some basic hints, for example, fix import (from Milos' work)
  • Code template now works, check or add your own via [Options/Preferences] -> [Editor] -> [Code Templates] -> [Scala] (from Milos' work)

Note: wait until Monday night for NetBeans' hudson builds those whole new nbms.

I think this plugin is qualifiable for beta using/testing now. If you are interested in testing/reporting bugs, you can get the latest NetBeans nightly built, and got the new Scala plugin from Update Center, download a Scala-2.8.0 snapshot, live your $SCALA_HOME to this Scala 2.8.0 snapshot, change $PATH to including $SCALA_HOME/bin.

By testing/using Scala 2.8.0 right now, we can also push it improved more quickly.

BTW, I'm using this plugin on whole Scala' trunk source and of course, this plugin.

  • Posted: 2009-08-22 09:00 (Updated: 2009-12-30 04:18)
  • Author: dcaoyuan
  • Categories: NetBeans

Comments

1. Gordon Tyler -- 2009-08-22 09:00

Thanks for your hard work on this. I'm looking forward to trying it out.

2. Andrew -- 2009-08-23 09:00

Indeed great news (I mean your hook with Martin's last IDE-related work)! I appreciate your sleepless nights! Thanks!

Heh... Hope, Oracle understands Scala is The Language, and NB is The Platform :-)

P.S. It seems mercurial read access has some time lag - have not noticed any changes in trunk yet .

3. Caoyuan -- 2009-08-23 09:00

@Andrew, you can get a quick view of logs of hg repository at browser:  http://hg.netbeans.org/main/contrib/

4. Fred -- 2009-08-23 09:00

I keep getting this error when using the NetBeans Scala Plugin. Why is this?

Exception in thread "main" java.lang.NoClassDefFoundError?: scalaapplication3/Main Caused by: java.lang.ClassNotFoundException?: scalaapplication3.Main

at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController?.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader?.loadClass(ClassLoader?.java:307) at sun.misc.Launcher$AppClassLoader?.loadClass(Launcher.java:301) at java.lang.ClassLoader?.loadClass(ClassLoader?.java:252) at java.lang.ClassLoader?.loadClassInternal(ClassLoader?.java:320)

Could not find the main class: scalaapplication3.Main. Program will exit. Java Result: 1

5. Caoyuan -- 2009-08-23 09:00

@Fred, which version of plugin are you using? the source code?

Thanks.

6. MrFred -- 2009-08-23 09:00

The NetBeans (6.8.M1) *Scala Platform Manager" widget says I'm using 2.7.3 (Default). Also I'm on Ubuntu Jaunty Jackalope.

MFred

7. @… -- 2009-08-23 09:00

Make sure to add "package scalaapplication3" Which may not be correctly added when create project from wizard.

This has been fixed on trunk version.

8. Andrew -- 2009-08-23 09:00

Caoyuan,

Thanks for the href. At last Scala trunk is buildable again (few days I haven't 2.8 at all), and I'd want to try current stage of your work, but - looking hg summary, you never stop... Where is that moment when to try?? :-)

9. Caoyuan -- 2009-08-23 09:00

@Andrew, I'll never stop:-), since I'm using it for my daily work, if I find something wrong, I'll try to fix it at once. Until an official Scala 2.8.0 and NetBeans out (I'll then pack a downloadable plugins).

So, if you have hg on your own machine, just try to re-build scala.edtitor module whenever you want, you can upgrade to it at once by: Right click on scala.editor project, choose "Install/Reload in Development IDE".

10. Andrew -- 2009-08-23 09:00

Caoyuan, aha, I see, it's a life... will never stop... :-)

I also see 2.7.3 in platform manager. Where must I add (or verify) "package scalaapplication3"? I have created new project with empty userdir before NB starting and with fresh Scala modules - last your comment is "Processed This/Super tree".

11. Caoyuan -- 2009-08-23 09:00

@Andrew, 2.7.3 is there, but you should set $SCALA_HOME to ignore it, I have no much bandwidth to upload a whole 2.8.0 snapshot every week.

12. Andrew -- 2009-08-24 09:00

Caoyuan,

Thanks, all works now. There was parallel issue - I just upgraded bash shell, and last (4.x) version is more strict wrt env vars, and my SCALA_HOME was lost on that way :-) The problem is resolved, and, at last, I try do something interesting (at first, port from 2.7.x) with my code using your plugin.

Thanks, and sorry for noise.

13. Fred -- 2009-08-24 09:00

Sorry, had to go to bed, just got up!

I checked if the widget creates the *scalaapplication3* package and it does, so I then checked the jar file in the *dist* folder. Inside the jar the *scalaapplication3* folder is also created but the main.class is outside of it (i.e. in root) and not within it as I would expect.

Fred

14. Caoyuan -- 2009-08-24 09:00

@Fred, the source code generated by wizard is something like: ===== package scalaapplication3

object Main {

/**

  • @param args the command line arguments */

def main(args: Array[String]) :Unit = {

println("Hello, world!")

}

} ==== located at src/scalaapplication3/Main.scala,

Aftre a clean/build, there should be two classes Main.class and Main$.class under: build/classes/scalaapplication3

Right click on project's node, choose "Properties"->"Run", the "Main Class:" should be filled with "scalaapplication3.Main"

Are all above correct?

15. smagrath -- 2009-08-24 09:00

Hi, Is this a suitable place to mention the URL link to the NB plugin for Scala sees to be broken... Viz: 1) On the NB Scala Wikipage, 2) In Section 1.6 "Get the Scala plugins binary from:  https://sourceforge.net/project/showfiles.php?group_id=192439&package_id=256544&release_id=686747"...

I get an "Error 500"... ... maybe the problem is with Sourceforge. Certainly, Error 500 doesn't tell me very much...

Also a search on Sourceforge for "Netbeans Scala plugin" doesn't seem to turn it up either...

Thanks

16. -- 2009-08-24 09:00

@smagrath, yes, sourceforge changed something, I've updated wiki page to point to new URL as:

 http://sourceforge.net/projects/erlybird/files/nb-scala/nb-scala%206.7v1/nb-s cala-6.7v1.zip/download

Oh, it has been downloaded 2456 times.

Thanks for the report.

17. -- 2009-08-24 09:00

Yes, ALL of the above is correct, but it still doesn't work.

The only way I can get it to printout *Hello World!* is to change *scalaapplication.Main* in the Projects Properties dialog to just plain *Main*, because as I said in my previous post the main class is in the root of the built jar file not in the *scalaapplication* folder.

It seems that when I run the application I am running it from the jar file in the *dist* directory and its the contents of this jar file that are incorrect.

Thanks for your help, anyways..

Fred.

18. Andrew -- 2009-08-24 09:00

Caoyuan,

Which compiler is used to compile a project? In platform definition I have found library jar only - no compiler jar.

19. Caoyuan -- 2009-08-24 09:00

@Andrew, under scala-build.xml, uses "scala.library" and "scala.compiler", "scala.libs" properties, which are set at nbproject/project.properties

20. Andrew -- 2009-08-24 09:00

Caoyuan,

Sorry, my question wasn't clear. I mean: which compiler does the plugin use to build user's scala project (i.e. inside NB)? The problem is, when I start 'ant clean jar' from command line, all is fine. When I Shift-F11 in NB, I get an exception (too big to show here - I have asked in scala-user mailing list with subject "malformed Scala signature").

21. Caoyuan -- 2009-08-25 09:00

@Andrew, to build current scala plugin, you need to clear $SCALA_HOME, scala-library and scala-compiler are all bundled in libs.scala module, you need not to care about it. After build successfully, you should set back $SCALA_HOME to point to a Scala-2.8.0 snapshot.

I got things a bit hard, because I patched scala's compiler lib a bit.

22. Andrew -- 2009-08-25 09:00

Ok, I'll try inside scala.kit:

#!/bin/bash

SCALA_SAVE=$SCALA_HOME SCALA_HOME="" export SCALA_HOME

ant scala-clean scala-nbm

SCALA_HOME=$SCALA_SAVE export SCALA_HOME

23. Andrew -- 2009-08-25 09:00

Caoyuan,

I have tried to use the plugin built with above scipt with the same "malformed Scala signature" error. How I get this error: I have project A (self-contained), project B (depends on A) and project C (depends on A and B). I do Shift-F11 on project C. Ok, all fine. Than I change something in C and again S-F11 - the error takes place on recompiling B. At case "Build Projects on Classpath" checkbox is unchecked, all works fine.

24. Caoyuan -- 2009-08-27 09:00

@Andrew, yes, I reproduced it (or I forgot I saw it before): malformed Scala signature". Although it seems no much affect currently, but it may be a error worth to file a ticket to scala team?

25. Andrew -- 2009-08-28 09:00

Caoyuan,

I'm ready to create new Scala ticket, but I'm in doubt: there is another strange moment. Say, I heve pressed Shift-F11 on some project - all compiles fine, without errors (and even wornings :-)). Without doing any changes I press F11 on the same project. At this moment two cases possible. Lucky one - just compile something *unchanged", say

init: deps-jar: Compiling 6 source files to /wrk/usr/netbeans/projects/zgs/alog/build/classes compile: Building jar: /wrk/usr/netbeans/projects/zgs/alog/dist/alog.jar jar: BUILD SUCCESSFUL (total time: 2 seconds)

(the project has few dozens files). "Sad" case - again, those "6 source files" compiling starts, but ends with that "malformed Scala signature".

You see, my doubt is about those "6 source files" mythical files :-)

P.S. I'm currently at "scopeMembers may also contain syms from enclMethod.scope" point.

26. Andrew -- 2009-08-28 09:00

P.S. Is the blog an appropriate place for such "deep analysis"? :-) I'm ready for direct emailing to "moc.oknedyag@a".reverse

27. Caoyuan -- 2009-08-28 09:00

@Andrew, would you please email me a piece of code (a zipped project) that can reproduce above case?

28. Andrew -- 2009-08-28 09:00

Caoyuan,

I have tried but still was not able to prepare a short test case. The project itself (with those 'object A') is closed, sorry. I'll try more and report on success.

29. Andrew -- 2009-08-29 09:00

Caoyuan,

With help of Paul Phillips (I have not-humbly reasked my question wrt "malformed Scala signature") I have "found" a reason: nmb pack still goes with old Scala: <NB userdir>/scala dir is created with 2.7.x Scala inside. After just deleting this dir I'm not able to reproduce the error.

Compiling of "mythical files" still exists, but doesn't influence to something (at least, I have not noticed any side effect).

30. Caoyuan -- 2009-08-29 09:00

@Andrew, I think it's time to upload a 2.8.0 snapshot to replace old 2.7.x pack now. I'll try it when I have time.

But I'm not sure if it's a good idea to bundle a whole Scala DK as part of plugins. I'd like to here some suggestions.

Thanks, Andrew.

31. Andrew -- 2009-08-29 09:00

Caoyuan,

From my user's point of view, I don't see a reason to pack the plugin with SDK, especially at this development (for both the plugin and Scala) period.

32. Andrew -- 2009-08-29 09:00

Caoyuan,

What is that feedback way which you prefer? Say, I have something to say, but it isn't directly correlate with this or that your blog post. Direct mail? Google group (which is full of spam)? scala-tools mailing list? Or - just keep a silent to avoid your efforts disturbance :-)

33. Caoyuan -- 2009-08-30 09:00

@Andrew, google-group is ok, spam is not a problem.