Scala Help needed - Code completion - scala

I am working on writing an IDE for Scala and need some help. I would like to implement coding assistance so that I could present a list of options when a user presses a period (".") or a space (" "). e.g. if projects is a List, as soon as user types "projects." or "projects ", I would like to show all methods of scala.List that he could use (regular IDE stuff). I know that scala.tools.nsc.interactive package provides this capability, but I am unable to figure out how to do it. Besides, it seems that the interactive package would use REPL and would be slow for this purpose. Is that a fair assumption, and if yes, are there any alternatives?
Also, is there a way I could get a call reference tree for a literal/ method (where all is the method referred to in a code base) ?
Thanks and Best regards
Aishwarya

Well, your best bet is going through the same set of links I provided in answer to this question, even though the questions are different.

Yes, the presentation compiler under scala.tools.nsc.interactive is where the reusable functionality would be.
The presentation compiler is used by Eclipse and ENSIME. May be ENSIME itself which in addition to providing emacs support also provides a server as a backend for an editor would be a good avenue.
The presentation compiler is not slow. It was designed from the ground up to provide good performance for Eclipse and it has largely delivered on this goal.
For some of the presentation compiler capabilities, see scala.tools.nsc.interactive.CompilerControl.
For another project using ENSIME, look at Daniel Spiewak's plugin for jEdit.

Related

navigate to the implementation of a data-type or a function

I was wondering if there was the equivalent of "Ctrl+left-click" in eclipse for java, that takes me to the implementation of a method or a data-type in Rascal. I'm finding it a little hard to sort through a list of references brought up by doing a "Ctrl+H" search everytime.
Thanks,
The short answer is: not yet.
The longer answer is: we are working hard on a type checker and compiler for Rascal and those will provide the basic information for jumping to definitions, uses, and the like. As soon as that information is available we will integrate it in Eclipse.

Is there a Scala like Clojurescript? aka Integrated Scala Single Page Application

So ClojureScript One is rather incredible looking! You can make updates with your REPL in real time to a SPA.
So something like this is rather impossible in Java where you don't have a REPL but it seems very possible in something like Groovy or Scala. I'm sort of a Lisp bigot (I really shouldn't be but oh well) and wondering if there is a Scala or Groovy like Clojurescript?
Update:
In theory it looks like one could wrap Scala/Groovy around Java's ItsNat. However I have some doubts about that project given it hasn't been updated since 2011 (also they have they ugliest website.. its like they tried to make it ugly). The license is also rather restrictive.
Try http://www.scala-js.org/ a A Scala to JavaScript compiler
There's js-scala, but it seems to be quite experimental at the moment.
ItsNat has come to quit a stable stage, this is why it is inactive. Of course new features and more browser support and testing can be leveraged, but so far, we've had a great experience with ItsNat. We've been with ItsNat since version 0.7 and had very (2) issues, that too, quite rare ones.
If you'd like working examples, I'd be glad to show you as our project is open sourced :-)
Works well with both SEO and SPI.
Demo
If you are looking for SPA scala-gwt. Or you are looking for scala-to-javascript compiler?

Is it a good idea to develop an IDE for scala?

I have to choose a sizable (but not too sizable!) project for my next & last term in university. I thought maybe a nice IDE for scala is what the world might need right now :).
Would you like to see an IDE specifically made for scala? Or are you more comfortable using (the already available) plugins for popular (mainly java) IDEs & editors?
What do you think about the whole idea?
P.s. I'd make it open source & would add features one by one, so if it doesn't end in one semester, it won't be a problem from the university perspective.
Actually, not anymore. IntelliJ, Netbeans and Eclipse all have Scala-specific efforts that have more man-hours in it than you could possible start to begin putting in at a last term. And there's two very interesting efforts that were results of projects like that, both of which were made to contribute to any IDE effort: ENSIME and Scala Refactoring.
And, beyond these efforts, most programming editors, such as jEdit or TextMate, also have some Scala support to one degree or another.
So, really, contributing to one of these projects might be a good idea, but making a Scala IDE is not.
For his Masters thesis, Mirko Stocker contributed the refactoring functionality to the Eclipse Scala plugin, see:
http://misto.ch/scala-refactoring-talk-at-scala-days-2010/
Instead of creating an IDE from scratch, why not contribute a major piece of functionality to the Eclipse plugin, all contributions are welcome. For ideas, see tickets.
Or instead of reinventing the wheel.. you can contribute..
http://wiki.netbeans.org/Scala
But I am not sure if it will be somehow enough for your university work. At the same time, as you see, those plug-ins still require a lot of work.
While writing your own IDE you will just trying to solve problems that were already solved and tested. Besides, even if - what kind of IDE is that, which allows you to do
Scala (even if its great) only. So just for simple xml edit of ant file or whatever you will need another tool.
I think Brian Clapper already summed it up nicely.
I'd suggest something like CheckStyle but for Scala might go down well and be reasonable to tackle as a project.
Not a Scala developer but an Eclipse plug-in would probably be a worthy senior project.
Concur. Operating systems, text editors, and IDEs...does the world really need more of them? No. But everyone wants to write one.
If you want to do something useful, as opposed to simply academic, develop an extension for an existing IDE. Eclipse, NetBeans, Komodo, etc. are all nicely extensible through plugins.

More fine grained sorting of methods using Eclipse Ganymede: Is there a good plugin available?

These are the options we have out of the box:
I would like a more fine grained sorting when it comes to methods. I would like to:
Have all methods with a name which does not start with get, is or set first.
Then have the accessor methods (with names starting with get, is or set).
Individually the methods in [1] and [2] above could be sorted in alphabetical order. Apart from my devision of normal methods into two parts I like the existing sort order.
I find this order (with the accessor methods last) better as I'm more likely to find the non-accessor methods interesting when I'm maintaining a class and I need to fix a bug etc.
Is there a plugin I could use? If there is none, would it be hard to create this kind of plugin myself? (I have never created a Eclipse plugin.)
I hope it's not to late for my answer.
As far as I know, there is no such plugin (I looked at eclipse plugin central right now).
If you want to write such plugin, it shouldn't be too hard to write the refactoring (the Java Editor is based on an AST, that can be reached via extension points) itself, but for building a working plugin it might need more study.
Some resources that might help:
Plugin development resources from stackoverflow: question 592391 (sorry, but cannot post two hyperlinks)
An open source refactoring plugin: http://code.google.com/p/tane/ (it currently contains a single refactoring plus the related gui elements, it might be a good example for you)
In 2011, an academic exercise resulted in an Eclipse plugin implementing methods sorting based on ideas in Robert C. Martin's book "Clean Code". I am still trying to work out if I like it or not.
There is an open bug report to enhance sort member functionality in Eclise: Sort Members doesn't provide a means to group getter/setter pairs. It was opened in 2004 and still has no plans to be implemented.

Getting Started with an IDE?

Having programmed through emacs and vi for years and years at this point, I have heard that using an IDE is a very good way of becoming more efficient.
To that end, I have decided to try using Eclipse for a lot of coding and seeing how I get on.
Are there any suggestions for easing the transition over to an IDE. Obviously, some will think none of this is worth the bother, but I think with Eclipse allowing emacs-style key bindings and having code completion and in-built debugging, I reckon it is well worth trying to move over to a more feature-rich environment for the bulk of my development worth.
So what suggestions do you have for easing the transition?
Eclipse is the best IDE I've used, even considering its quite large footprint and sluggishness on slow computers (like my work machine... Pentium III!).
Rather than trying to 'ease the transition', I think it's better to jump right in and let yourself be overwhelmed by the bells and whistles and truly useful refactorings etc.
Here are some of the most useful things I would consciously use as soon as possible:
ctrl-shift-t finds and opens a class via incremental search on the name
ctrl-shift-o automatically generates import statements (and deletes redundant ones)
F3 on an identifier to jump to its definition, and alt-left/right like in web browsers to go back/forward in navigation history
The "Quick fix" tool, which has a large amount of context-sensitive refactorings and such. Some examples:
String messageXml = in.read();
Message response = messageParser.parse(messageXml);
return response;
If you put the text cursor on the argument to parse(...) and press ctrl+1, Eclipse will suggest "Inline local variable". If you do that, then repeat with the cursor over the return variable 'response', the end result will be:
return messageParser.parse(in.read());
There are many, many little rules like this which the quick fix tool will suggest and apply to help refactor your code (including the exact opposite, "extract to local variable/field/constant", which can be invaluable).
You can write code that calls a method you haven't written yet - going to the line which now displays an error and using quick fix will offer to create a method matching the parameters inferred from your usage. Similarly so for variables.
All these small refactorings and shortcuts save a lot of time and are much more quickly picked up than you'd expect. Whenever you're about to rearrange code, experiment with quick fix to see if it suggests something useful.
There's also a nice bag of tricks directly available in the menus, like generating getters/setters, extracting interfaces and the like. Jump in and try everything out!
One thing that helped me transition from Emacs to other IDEs was the idea that IDEs are terrible editors. I scoffed at that person but I now see their point.
An editor, like Emacs or Vim, can really focus on being a good editor first and foremost.
An IDE, like Visual Studio or Eclipse, really focuses on being a good project management tool with a built in way to modify files.
I find that keeping the above in mind (and keeping Emacs handy) helps me to not get frustrated when the IDE du jour is not meeting my needs.
If you've been using emacs/vi for years (although you listed both, so it seems like you may not be adapted fully to one of them), using said editor will probably be faster for you than an IDE. The level of mind-meld a competant emacs/vi user can achieve with a customized setup and years of muscle memory is astounding.
Some free ones:
XCode on the Mac
Eclipse
Lazarus (Open Source clone of Delphi)
Visual Studio Express
Editions
Try making a couple of test applications just to get your feet wet. At first, it will probably feel more cumbersome. The benefits of IDEs don't come until you begin having a good understanding of them and their various capabilities. Once you know where everything is and start to understand the key commands, life gets easier, MUCH easier.
I think you'll find IDE's invaluable once you get into them. The code complete and navigation features, integrated running/debugging, and all the other little benefits really add up.
Some suggestions for starting out and easing transition:
- start by going through a tutorial or demonstration included with the IDE documentation to get familar with where things are in the GUI.
- look at different kinds of sample projects (usually included with the IDE or as a separate download) for different types of areas you may be coding (web applications, desktop applications, etc) to see how they are laid out and structured in the IDE.
- once comfortable, create your own project from existing code that you know well, ideally not something overly complex, and get it all compiling/working.
- explore the power! Debug your code, use refactorings, etc. The right click menu is your friend until you learn the keyboard shortcuts just to see all the things you can do. Right click different areas of your code to see what is possible and learn (or re-map) the keyboard shortcuts.
Read the doc...
And see what shortcuts/keybindings equivalents are with your familiar ones. Learn the new ones...
Old question, but let me suggest that in some circumstances, something like Notepad++ might be appropriate for the OP's situation which may be encountered by others. Especially if you are looking for something lightweight, Notepad++ can be part of a developer's arsenal of tools. Eclipse, Visual Studio and others are resource hogs with all their automagic going on and if you are looking to whip out something pretty quick with a whole bunch of keyboard shortcuts and the like or if you are interested in viewing someone else's source, this can be quite useful. Oh yeah, and it is free too.