Cannot import third party module in Scala worksheet VSCode - scala

I have used Scala 3 in VSCode with metals via Windows Subsystem for Linux.
First, I created the cats effect 3 project using sbt new typelevel/ce3.g8. There are Main.scala file which can be run just fine using sbt run.
Then, I created the scala worksheet to try some code. However, I can't import cats into scala worksheet. I wonder why?
I have seen similar question which can be solved by adjusting Scala worksheet setting Run type from REPL to plain in Intellij idea, but this setting doesn't seem to exist in VSCode.
Thanks in advance guys!

I had exactly the same issue with a worksheet in src\test\myworksheet.sc (no dependencies would resolve). When moved to src\test\scala\myworksheet.sc it worked fine. (See #luis response as well)

Related

Scala in IntelliJ error

I just downloaded the plug in for Scala in IntelliJ and have created a project but now have various errors I read that the problem can be that I am missing a library. But when I try and go to project structure -> dependencies to add a library I have no clue where in the files to look for a library.
The errors are really simple but I can't seem to figure it out.
Any suggestions would be helpful :)
Here's everything you need to properly set up Scala plugin in Intellij. Furthermore your code has several errors:
Are you sure you created a Scala project (when you did File->New->Project)? This looks to me like a Java project? That class file looks to me like a Java class not a Scala class (that's why you're getting compilation errors on def but not public class).
1) value is not defined anywhere, of course it will throw a compilation error
2) classes in Scala are by default public, you do not (cannot) mark them as such
You can save yourself a lot of trouble by creating a simple SBT project that specifies all of your dependencies, etc. and then just pointing the IDE at that. Then when you change build.sbt, IntelliJ IDEA will notice that and update itself automatically. Plus, your build.sbt gets checked into your code base so that anyone you are collaborating with sees your changes to the dependencies. And the project can be built in batch mode using sbt compile and friends.
The following page talks about IntelliJ IDEA's "SBT Import" feature:
https://confluence.jetbrains.com/display/IntelliJIDEA/Getting+Started+with+SBT
Scala source files end in .scala, not .java. Try renaming Counter.java to Counter.scala. This should improve things a lot.

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.

Using playframework with the scala worksheet plugin for eclipse

I tried to use the worksheet plugin in eclipse in combination with a play project but it doesn't seem to work. Every import is marked as not being found.
Has anyone got this working, is there anything special I need to do?
Yeap, I had that problem. What I've done to solve it was:
If you're not using it, I would recommend you start using Scala-IDE for eclipse
Even though I've previously got scala-ide, when I tried to use scala worksheet with a play project I still had that problem. I tried to do the default action to the scala worksheet plugin when you have a computer problem: reboot-update-reboot. And it worked! The version of Scala Worksheet that I'm currently using is (as seen in my Eclipse Installation details):
Scala
Worksheet: 0.1.2.v-2_09-201210230838-85b738a
Check if your version is the same as mine. If it's try to remove it and install it againt. If it isn't, then try to update it. Tell me if it works.
Cheers!
the question is a bit general, but:
if worksheet is working correctly without play framework => problem should lies in the installment of the framework:
did you update PATH (http://www.playframework.org/documentation/2.0.4/Installing)?
is command play help working ?
You are asking about Play's Eclipse plugin specifically:
did you follow guide at http://www.playframework.org/documentation/1.0.1/ide#eclipse ?
Which step didn't work for you?

IntelliJ scala console, interactive developement

I have just started "coding" in Scala, coming from F# I am trying to find a way to have a similar environement.
Currently I am using IntelliJ 10.0.2. with the Scala plugin. On any given project I am trying to set up the following:
When opened the scala console loads the external libraries of the project ( this works )
A command/way to load the files where code is under developement. For instance you define a few modules in your project that you would like to test, so you would do something like load "module1.scala", load"module2.scala" etc.. in the console.
Is this possible?
Note:
com.intellij.rt.execution.application.AppMain.org.jetbrains.plugins.scala.compiler.rt.ConsoleRunner seems to load all the external libraries
there seems to be a function :load but when I supply it arguments it returns "file does not exist") actually was just a silly mistake was using C: instead of c:
Many thanks
Google for the sbt plugin for idea. SBT (Simple Build Tool) is an interactive build tool for Scala. It has a "console" command that loads the dependencies and your classes when it starts up. SBT offers other goodies, as well. The idea plugin lets you use the two together.
It's not possible like IntelliJ IDEA feature.
You can add appropriate issue to Scala plugin issue tracker: http://youtrack.jetbrains.net/issues/SCL.

How to use Scala in IntelliJ IDEA (or: why is it so difficult to get a working IDE for Scala)?

I recently gave up trying to use Scala in Eclipse (basic stuff like completion doesn't work). So now I'm trying IntelliJ. I'm not getting very far.
I've been able to edit programs (within syntax highlighting and completion... yay!). But I'm unable to run even the simplest "Hello World". This was the original error:
Scala signature Predef has wrong version
Expected 5.0
found: 4.1 in .... scala-library.jar
But that was yesterday with IDEA 9.0.1. See below...
UPDATE
Today I uninstalled IntelliJ 9.0.1, and installed 9.0.2 Early Availability, with the 4/14 stable version of the Scala plug-in.
Then I setup a project from scratch through the wizards:
new project from scratch
JDK is 1.6.u20
accept the default (project) instead of global / module
accept the download of Scala 2.8.0beta1 into project's lib folder
Created a new class:
object hello {
def main(args: Array[String]) {
println("hello: " + args);
}
}
For my efforts, I now have a brand-new error :)
Here it is:
Scalac internal error: class java.lang.ClassNotFoundException [java.net.URLClassLoader$1.run(URLClassLoader.java:202), java.security.AccessController.doPrivileged(Native Method), java.net.URLClassLoader.findClass(URLClassLoader.java:190), java.lang.ClassLoader.loadClass(ClassLoader.java:307), sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301), java.lang.ClassLoader.loadClass(ClassLoader.java:248), java.lang.Class.forName0(Native Method), java.lang.Class.forName(Class.java:169), org.jetbrains.plugins.scala.compiler.rt.ScalacRunner.main(ScalacRunner.java:72)]
FINAL UPDATE
I uninstalled 9.0.2 EA and reinstalled 9.0.1, but this time went with the 2.7.3 version of Scala rather than the default 2.7.6, because 2.7.3 is the one shown in the screen-shots at the IntelliJ website (I guess the screen-shots prove that they actually tested this version!). Now everything works!!!
I have encountered the same scalac error when trying to run a Scala project in Intellij Idea 9.0.2 and I've managed to find a solution by chance :). These are the steps I took in creating the project and running it.
I have created a Scala project in Intellij Idea 9.0.2 final (it was released today). I have installed the Scala plugin, restarted the IDE and created a new Scala project (with the name "TestScala") with scala-2.8.0.Beta1 as project library. Once the project is created and the scala libraries downloaded, I have created a Test.scala file with the following content:
object Test {
def main(args:Array[String]){
println("hello")
}
}
After that, I created a launch configuration ("Edit Configurations"), choosing the "Application" template. I set as main class Test and choose the project name ("TestScala") in the "Use classpath and JDK of module" combo box. When I run the configuration I get the same error as you reported ("Scalac internal error: class java.lang.ClassNotFoundException") .
Now comes the freaky part :). I right click on the project, choose "Module Settings", have a look on all settings but I don't change anything . Click "apply" and "ok", try to run configuration again and it works :) .
I use Intellij Idea 9.0.2 the final release (build 95-66); Ubuntu 9.10 and JDK 1.6.0_18. I also have to mention that I had a JDK configured in Intellij, otherwise there is an extra step to configure it.
UPDATE:
When checking the setting of the module, one needs to click on the Module->Scala and Facets->Scala (expand it and click on Scala(ProjectName)) . Both of these settings are about the scala compiler and scala library location. I would guess these values are not properly set when the project is created but are saved once the user touches them and saves the settings.
To answer your question, it's difficult to get a working IDE for Scala for two reasons:
(a) Scala is only just beginning to reach a wide audience and
(b) due to (a), there is no business case for spending time on a Scala IDE.
Also, if you are old enough to cast your mind back and young enough to still remember, you would know that for the first five or more years of Java, we were stuck with okay-ish tools like JBuilder that did little more than compile your code when you said so - no error highlighting, no auto-importing, and the word refactoring didn't even exist. If you want to pioneer, you need to be prepared to cut some of the road yourself, or at least bush-bash.
I know it won't help you, but I have successfully used IDEA for Scala on Linux, Mac and Windows. I typically have the Scala SDK installed somewhere locally and point IDEA at that rather than using the 'download' option.
Presently, I am mostly using an EAP version of IDEA 9 on Mac OS X with Scala 2.8.0.Beta1-RC5 and it's working well (except that fsc doesn't seem to worked with mixed sources).
You could try your luck over at the IDEA Scala Plugin Discussion Forum, though I haven't had a great lot of responses to my own postings there.
Installing the plug-in is prerequisite one.
The next thing you should do is define a library (global or project-specific; I use global) that holds the Scala library and compiler JAR files (at a minimum, that's scala-compiler.jar and scala-library.jar). Adding source JARs and a documentation JAR or URLs is a good idea, too. Then make this library a dependency of any modules in your project that include Scala code.
Lastly, find the Scala facets in those modules and de-select both check-boxes there.
I just did a fresh install and had exactly this same problem myself.
It turned out that, because I had created the file in the root package, IDEA had added a package statement at the top with naming a package. I assume that this then got compiled as "package object Main" - valid syntax in 2.8? Anyway, I deleted the line that said package and it all worked fine.
I had the same problem yesterday while trying to set it up. Solution is pretty simple, you just have to set scala somewhere in project settings.
You are mixing code compiled with two different Scala versions.
I use Netbeans to write scala programs. So far it works very well with my codes. You can try the plugin here: http://wiki.netbeans.org/Scala68v1.
I was getting this error and also had to right click on the project and "Open Module Settings". However, it was more than just hitting apply. I had to make sure that my Content Root was correct for each project. For some reason, there were some incorrect Source and Test Folders.
My project uses maven as the main build tool and importing the project into Intellij is probably what created these incorrect settings.
I had similar problem, following this blog post instructions solved the problem for me