Scala Docs in IntelliJ - scala

How do I access Scala docs in IntelliJ? The other answers in SO are for earlier versions. I added the scala doc jar file, but still I am unable to link scala docs with IntelliJ.
I do get the Quick Documentation as shown:
But I want the complete doc as here
Also, clicking on the Actor hyperlink shows me this code, but not the API doc. There are the download and Attach sources link and I dont understand what they are.

What do you mean by "link scala docs"? You can get documentation for a symbol (class, method) by pressing Ctrl-Q (or menu View > Quick Documentation). This seems to work at least with sbt based projects, even if in Project Structure > Project Settings > Libraries > SBT: org.scala-lang:scala-library:2.12.1:jar there is only classes and sources, and no explicit pointer to javadocs (I guess IntelliJ might extract them directly from the sources).
Also, are you using the latest version of IntelliIJ and the Scala plugin? For me, if I create a global Scala SDK (which you don't actually need when you use sbt build projects), IntelliJ by default does not have javadocs checked, but sources, and again I think it will extract the documentation from the sources. This is how it looks here with IntelliJ IDEA 2016.3.1 and Scala plugin 2016.3.5:

I added this:
to make it work. From the +, choose Scala SDK, select the version that matches your project and then add it to the module of your choice.

Related

Creating a scala project on intellij

Trying to create a scala based project on intelli and all the tutorials i see ask me to click on new project and select scala on the left and sbt on the right.
I cannot see a scala option on the left.
I have already installed the scala plugin. Also restarted intellij several times.
The project wizard in recent IntelliJ versions looks and works a bit differently than before. You need to select the primary language for the new project and then specify additional details such as SDK and build tool versions.
In your case, you need to choose Scala in the "Language" selector, then sbt in the "Build system" section (the options in the section change based on the language chosen):
For more information, consult the documentation.

Intellij Idea: Scala plugin: No compile library set for module

Wanted to start using intellij idea for my scala project and stumbled upon this link - http://theyougen.blogspot.in/2010/01/how-to-setup-maven-scala-project-with.html
Followed the steps, created a new Scala Project (without sbt), Create a new Scala Class, and copied the HelloWorld code from Scala tutorial - http://www.scala-lang.org/old/node/166.html
Went to Build > Make Project and got following error -
No compiler library set for module.
Went to File > Project Structure. On the left side, clicked on facets, and noticed that Under Compiler Compiler Library was set to none. And there is no other option available in the drop down.
How to solve this?
PS: Googled a lot, could not find any clue on how to fix this.
If on MAC
Download scala from http://www.scala-lang.org/download/
Extract it to some-location/scala
In Intellij Idea go to File, Project Structure and select Global Libraries.
Click on + button
Select Java
Give the path to some-location/scala/lib
Click ok
Apply and OK.
Go to File, Project Structure, facets. You will see a new Scala library in drop-down.

Can't configure Scala in Intellij IDEA 13

I entered Scala courses on Coursera and used to write Scala projects in Eclipse Indigo. All worked well. But now I gonna to convert to my favorite IDE - Intellij IDEA.
But I can't configure it for Scala usage.
What I've already done:
Install Scala, set system SCALA_HOME variable
Install SBT
Install Scala plugin on Intellij IDEA
What a problem:
When I import coursera assignments, Intellij doesn't see some classes like List, Array etc. For example, when I try to import it via Alt+Enter key it propose me java.jang.reflect.Array, java.sql.Array, com.sun.xml....Array. So I can't import Scala Array with tail and head methods.
When I try: New Project -> Scala Module the are to problems:
a) When I choose Set Scala Home it complains that there are missing files
b) When I choose Existent Library there is nothing to choose in Compiler/Standart fields.
Question:
How to configure Intellij properly?
It can be a problem with caches, try File -> Invalidate Caches
Is the directory you specified the right one? It should have bin, doc, etc. in it. If so, try entering the following by hand:
For compiler library, scala-compiler
For standard library, scala-library
IDEA found these for me automatically, but perhaps something went wrong for you.
Make sure to manually add the scala-library as a dependency to your module.
This is not done automatically when adding the Scala facet to an existing module.

Viewing Scaladoc in Eclipse

In Eclipse I have set the Javadoc Location property of my Scala project to file:/D:/EclipseWorkspace/MyProject/target/scala-2.9.1/api where D:/EclipseWorkspace/MyProject is the location of my scala project.
Now, if I am in a Scala file that implements a class/trait, when I type Shift+F2, Eclipse opens the Scaladoc page of that class/trait. However, this does not work if it is an object since Eclipse tries to open <ObjectName>.html whereas the Scaladoc-generated file name is <ObjectName>$.html.
Is there any workaround?
Scaladoc is now integrated since release 4.0.0 RC1 of the Scala-IDE plugin. You can just hover over your term, or press F2 while the cursor is on the identifier.
Typesafe has announced a plugin for the Scala compiler which generates JavaDoc for your Scala API. The plugin and its documentation is available on github. Maybe this helps as a workaround.

How to run scala code on Intellij Idea 11?

I am new to intellij idea and I decided to shift because I found the scala plugin on eclipse to be annoyingly buggy.
But, intellij idea, which I have heard to be very good, looks difficult to use.
I looked through the getting started with scala plugin page but couldn't find documentation specific to the latest version of lightweight ide of intellij idea 11 for scala.
I have created a project and made a hello world object in scala but I am not able to run it.
On trying to run it, it shows the scala interpreter (type in expressions to get them evaluated).
I don't exactly understand what changes to make in the project structure to be able to run scala code. As of now, i added the jsdk to point to my $JAVA_HOME and the scala library is also added. The scala plugin is also working in that syntax highlighting etc is fine.
The intellij idea user interface is also not very friendly and I don't get how to run the code. What modules am I supposed to add? Also, does compiled scala code run with jvm?
I'll be grateful to anyone who helps out.. I have been putting off writing scala code because I am not able to find THE IDE.
EDIT: Thanks for all the help! I am now able to run a basic scala program. I am trying to add external jars. What is the equivalent of doing Project right click-> Configure Build Path -> adding external jar files in eclipse? I tried adding "dependencies " under modules tab in project structure. It's adding the jar files but somehow the classes in the jar files are not still recognised.
With the Scala plugin installed either
A. Create a new project and select the Scala facet in the creation phase. It will create the Scala library lib and Scala compiler lib and setup the facet for you
B. If you already have a project. Go to Project Structure -> Modules and right click the module and go Add facet and add a Scala facet. Now you need to add scala-library.jar as a library of the module and go into the Scala facet and point it to a library containing scala-compiler.jar
Some more information
this is what your module should look like under project settings
select the Scala facet and this is what you should see (Library name for the compiler is unimportant as long as it says (version xxx) next to the library name
these are the jar files in my scala-compiler lib
and these are the jar files in my scala-library lib
With everything setup like that you should be able to right click -> new Scala class (Select object from the dropdown) in a source directory and add
def main(args:Array[String]) {
println("Hello world")
}
then right click on the class and select Run Classnam.main() and IntelliJ will setup a run configuration for you.
Edit: I can see someone posted somewhat the same I want to say here. I hope this can give a few more in-depths hints, so I will post it anyway :-)
If you would like to run Scala native in IntelliJ (I shifted to IntelliJ and still can't get my hands down) you need to make sure a few things are in order. Most of this happens under File -> Project Structure which requires you to create a project (when you get a hang of it, it is much more logical than Eclipse -- and Netbeans for that matter). I am also assuming you have selected a jdk, but this can also be done in the Project Structure.
Now, to Scala:
Make sure you have the Scala plugin. Visit the Settings (File -> Settings; can also be found at the start-up screen) and locate 'Plugins' (for me it's nr. 8 from the bottom). Under "Browse Repositories" you should be able to search for "scala", find and install a plugin.
1 A. If no plugins pops up you are probably using a version of intellij where scala is not (yet) supported. If that happens you can go to the homepage for the plugin and download the nightly build.
Import Scala as a library in File -> Project Structure -> Global Libraries. Click the plus sign, select Java (Scala is a Java-lib), browse to your scala-dir (which can be downloaded here: http://plugins.intellij.net/plugin/?id=1347) and select the lib directory. Press ok and you should see the library popping up on the list.
Make sure the facet (Scala framework) is in place. Goto File -> Project Structure -> Facets. Click on the plus-sign and find Scala. A sublink should appear (if not double-click the Scala link). Clicking the sublink make sure you have selected a compiler before continuing. This should be provided by the modules selected before. I normally use FSC (Fast Scala Compiler) but it's probably a good idea to test the basic settings before experimenting.
Make sure the Scala Module is in place. In Project Structure -> Modules click on the module you want to compile in scala and click the plus icon above and select Scala. Again be sure to select a compiler library.
If you want to, setup configurations for the compiler under the facet
Use sbt with sbt-idea plugin to generate idea project files for complex projects.
Or
For simple projects.
Add scala nature to the project, and you can right click and run any file extending App.
A good walk-through on how to set up a Scala project in Intellij is located here:
http://sonyarouje.com/2011/03/18/running-scala-in-intellij-idea-10/