I can get auto-complete in an Ensime buffer containing Scala code but not in the Scala REPL launched from ensime. I wish to have auto-complete work in the Scala REPL launched from ensime. How can I fix this? I am using the following:
Scala 2.9.1
sbt 0.13.5
scala-mode2 from elpa
I also have this for the contents of plugins.sbt:
addSbtPlugin("org.ensime" % "ensime-sbt-cmd" % "0.1.2")
Now, the only other thing I have noticed is that in my .ensime file, it appears to be compiling for scala version 2.10. Note, that I can get auto-complete if I open scala from a terminal.
In summary, how can I get auto-complete from the scala REPL launched from ensime?
I am going to repost CodeKingPlusPlus's own comment on this question:
Apparently this is not a feature of Ensime, I asked on their github.
Related
I want to follow the book on Scala[1] but it uses Scala 3 and I have Scala 2 installed. I want to use both the versions, something on the lines of python2 and python3.
I tried installing Scala3 on my local using the official source but I could only grasp the project-level working directory. The sbt prompt does not work like a REPL would and I can only open REPL using Scala 2 (I checked the version everytime).
How do I open the REPL of Scala3 given I cannot uninstall Scala2?
The sbt prompt does not work like a REPL
If you execute sbt console from within project directory it will drop you into REPL version corresponding to the project's scalaVersion. For example, executing sbt console within project created with sbt new lampepfl/dotty.g8 would start Scala 3 REPL.
but I could only grasp the project-level working directory
For system-wide installation first install coursier and then execute cs install scala3-repl. This will install Scala 3 REPL alongside the Scala 2 one. Now Scala 3 REPL can be started with scala3-repl command whilst Scala 2 REPL simply with scala command.
I'm trying to run Scala in my command line.
I checked my java, went to the Scala website, downloaded and installed it, updated my environment variables.
So far the only thing different from guides online is that the folder where sbt is installed does not include a "lib" folder.
I then run sbt command in my prompt, and I get this message:
It looks like I'm missing a file called build.sbt, what is this? and do i need it?
Edit:
If I press 'continue' on the picture above, I get
sbt:scalaproj>
Which looks fine, but if i type some code, like this:
sbt:scalaproj> var a : Int = 12;
Then it returns errors:
[error] Expected ';'
[error] var a : Int = 12
What in the world is going wrong? can someone point me to a guide for writing Scala in the prompt that is not too old to work?
Let's first understand the terminology. Scala is the language you are writing. SBT is an acronym for Scala Build Tool. Both of them have REPL.
When you call sbt in the command line, you initiate the REPL of sbt. The commands you can run there, are all commands sbt supports. You can find here the common commands. For example, if you run compile, it will compile the build.sbt located at the directory where you called the sbt command. Anyway, Scala commands WILL NOT work here. Scala commands are not sbt commands.
In order to run Scala REPL, you need to type console in the sbt REPL. You can find here the Scala REPL documentation. Within the Scala REPL you can run Scala commands.
P.S.
You can find the Scala download page here.
I created a basic Scala Dotty project using Dotty template and import the project to IntelliJ IDE.
Everything works fine when I use the sbt command line.
When I try to build or run it inside IntelliJ IDE, I got following errors:
Error:scalac: Multiple 'scala-library*.jar' files (scala-library-0.9.0-RC1.jar, scala-library-2.12.6.jar) in Scala compiler classpath in Scala SDK sbt: ch.epfl.lamp:dotty-library_0.9:0.9.0-RC1:jar
Any ideas how to solve this?
IDE support for Dotty
Currently, the only IDE we officially support is Visual Studio Code.
Anyway when you import a project to IntelliJ IDEA check "use sbt shell". At least for me after that a test project compiles and runs with Ctrl+Shift+F10.
It's possible that not everything will work. For example Dotty macros don't but if I compile and run manually then they do.
Using the Cats library for Scala in IntelliJ IDEA leads to errors even if terminal SBT works. Can we fix this? Or some workaround that isn't switching editor?
Cats seems to work fine on my IntelliJ 2018.1.4. If it is working in the terminal but not in IntelliJ, it could be because of using in-built IntelliJ compiler. Have you tried enabling Use sbt shell for build and import, which delegates building to SBT:
Open sbt projects tool window: View | Tool Windows | sbt
Click sbt settings icon
Select Use sbt shell for build and import (required sbt 0.13.5+)
Use sbt shell might resolve compilation issues, however note that in-editor error highlighting might still give false positives because it uses custom-built typechecker.
Metals is an alternative that uses Scala proper for both compilation and in-editor error diagnostics.
I am very interested at using the Scala script engine that we have now in scala 2.11
I saw that within the REPL everything works but if I do it from a test (I tried from sbt and maven) then the ScriptEngine for scala is not found.
I tried that to see which ScriptEngine are present
println("manager:" + manager.getEngineFactories.size())
manager.getEngineFactories.toList.foreach(factory => println(factory.getClass.getSimpleName))
But I only get NashornScriptEngine (I have JDK8)
Does anybody have an idea why I can't find it? I had previously issues with NashornScript in SBT that could be resolved by added fork in Test but this is not the issue here.
It is as if the ScriptEngine is not present in the classpath when you are outside the REPL
Did you add the REPL (and, maybe, the compiler?) to the classpath? I imagine that if you don't specify the dependency and bring only the library, it would definitely not work.
If you did do that, perhaps if you could be more forthcoming with details on how you are doing this test?