If I have the contents of an object imported at the top of a Scala worksheet in Intellij, when I add new things to the object, they cannot be found in the worksheet. Even after I build the project and reevaluate the worksheet, it can't find the new property. Autocomplete works. If I quit and restart IntelliJ it works.
This is the error:
java.lang.NoSuchMethodError: Arith$.foo()Ljava/lang/String;
at #worksheet#.get$$instance$$res6(ArithWS.sc:15)
at A$A1$.main(ArithWS.sc:41)
at #worksheet#.#worksheet#(ArithWS.sc)
Weirdly, it seems to compile, but fails at runtime. This is a normal SBT project. IntelliJ 2017.2.5, Scala 2.12.3. Selecting the "Make project" checkbox doesn't help. Actually no combination of checkboxes makes it work. No amount of rebuilding the project or the worksheet helps either. Only restarting IntelliJ will get the worksheet to pick up the new code.
Example project code in Arith.scala:
object Arith {
val foo = "foo"
}
Example worksheet ArithWS.sc:
import Arith._
foo
This seems to fix it, though I would love to know why the default setting is broken, or what this undocumented setting does: Go to File -> Settings -> Languages & Frameworks -> Scala -> Worksheet (tab) . Unselect "Run worksheet in the compiler process".
In case others end up here as bewildered as I was and find that the above doesn't resolve the issue, try unchecking the "Use external compile server for scala" tick box in Preferences > Build, Execution, Deployment > Compiler > Scala Compiler > Scala Compile Server (you can also get to this view from the speedometer-like icon in the bottom right of Intellij).
Combined with "Make project" on the Scala worksheet view, this seems to ensure that changes are properly compiled and visible from within the worksheet.
Related
When I select File -> Settings -> Languages & Frameworks -> Scala -> Worksheet (tab) . Unselect "Run worksheet in the compiler process". I get an error as follows
Error:source file '/home/username' could not be found
I needed to untick the option to fix a the problem whereby Scala Worksheets aren't registering my changes after I change my source code. The following posts asked me to untick that checkbox. I'm using Ubuntu Debian if that is relevant.
Scala worksheets are not picking up my changes without a restart so I tried
Intellij scala worksheet can't find project classes
and
IntelliJ: Scala worksheet don't pick up code changes without restart
This is a known bug, please vote on the issue: https://youtrack.jetbrains.com/issue/SCL-14694
I downloaded IntelliJ IDEA 14.0.3, SBT, Scala and SBT plugins, set environment variables correctly, i guess (if i can run Scala repl is it correct?)
When i start IntelliJ IDEA and choose new SBT-based project i get some problems:
1) no /src/ folder in project structure. How i can fix that?
2) can't compile manually created Scala file: IDEA suggest me edit configuration with Alt+Shift+F10 then i get window with various settings, so what directly should i edit?
Sorry for possibly stupid questions, but i just want to run miserable
"hello world" in Scala...
You don't need any extra plugins besides the Scala plugin. Assuming you have that installed, then
Step One: Fire up IntelliJ and Click on "Create New Project"
Step Two: Choose Scala from the left hand side panel and choose SBT on the right hand side panel (i.e SBT-based Scala project) and click Next.
Step Three: Fill in your project details and click Finish
Step Four: Wait for Intellij to download all SBT dependencies and to construct the folder structure and to index.
Step Five: Begin hacking!
I've got the Scala-IDE installed on my Mac and on my pc with Ubuntu 12.04. In there I created a project, with a package and in there a worksheet. On my mac, the worksheet shows results of every line on the same line on the right. For example:
package mypackage
object myworksheet {
println("Hello World!") > Hello World!
}
On Ubuntu however, I do not see the result on the right. I've tried making changes in the worksheet and saving it, but it makes no difference.
Does anybody know how I can get these inline results on my Ubuntu machine as well?
I had the same issue, adding -Dfile.encoding=UTF8 to eclipse.ini fixed the issue.
For more details look at answer to the question: Results encoding in Scala Worksheet Eclipse plugin
Having a space in the Project name was the problem for me.
Creating a new project without the space resolved it.
See this answer New scala worksheets not evaluated in Eclipse
A very simple answer to your question-
I agree that the project name should not contain a space, you can also
get Inline Result in Scala Worksheet
New Project < Scala Project < Type a Name < Finish
GO to src < Right CLick < Scala Worksheet
P.S. Also here you don't need to Run (just hit Ctrl+S to save) also you don't need to append extends App to the obj worksheet name.
Change the scala installation to default version.
Follow these steps:
Project -> Right click -> Properties -> Scala Compiler
Click Scala Installation drop down.
Select "Latest 2.12 bundle (dynamic)" in drop down
I'm developing a Scala application using IntelliJ Idea 12, sbt and sbt-idea plugin. I generated all necessary files by saying "gen-idea" and everything goes well -- I was able to compile the sources in command line in sbt as well in IntelliJ Idea 12 itself using menu Build->Make Project.
Here is my main class (Application.scala)
object Application extends App {
val a = 12345
println("application entry point 1235")
}
I have a breakpoint at val a = 12345.
1) There were other errors before, but now says "Module is not specified". How do I solve this?
I'll be posting updates since there would be other errors as my gut tells me.
To debug just like to run, you need to create a run configuration (menu Run -> Edit Configurations). If you haven't done yet, you need to add an Application entry with the + button.
Not only do you need to specify the main class, but also which "module" that class belongs to. By default, "Use classpath of module" will be empty. Here in the popup menu, you need to select the main module (not the one ending in "-build"). After you choose that and close with "Ok", it should work.
Although not necessary, I also recommend to use sbt for building instead of "Make". In the configuration in the "Before launch" part, select "Make" and click on "-", then click on "+" and choose sbt -> test:products.
Edit: Here is the reference for the SBT plugin for IntelliJ.
I have Playframework 2 project with Scala (very small one). It uses Scala Anorm library.
I have the code like this:
package models
..
import anorm.SqlParser._
...
val rowParser = scalar[Long]
So, I would like to see source of scalar method. Trying to attache the sources I have in my plaframework source folder, but IDEA just swallows my request and does nothing back.
I use last version of IDEA and Scala plugin. Is it bug, probably?
First download source code :
1.) Click on this link : http://www.scala-lang.org/download/all.html
2.) Choose any scala version.
3.) Now in the last section 'Other Resources' you can see 'Sources' link. Click on it to download. In my case (https://codeload.github.com/scala/scala/tar.gz/v2.11.7)
Now point to this Source Code from IntelliJ.
1.) Open Project Structure in IntelliJ. Shorcut (Cmd + DownArrow)
2.) Select Global Libraries from the left section.
3.) Then on right side, Under 'Scala Library' section. Click '+' and point to source directory. See the screenshot.
Aha.. fixed.
So: I used to use 'attach source' in the top of the window editor - it does not work (I guess it is a bug - maybe related to the scala plugin, because usually it works).
But if try to attache sources to particular library - in "Project Structure -> Library -> +Attach File or Directories -> Sources" then it works.
Thanks.
To fix it we need to do some changes into IntelliJ IDEA platform. Most probably it will be fixed in IntelliJ IDEA 13.1.
I have the same problem. I installed "Scala Imports Organizer", and problem was solved.
for "automatically attaching source jars" when using Bloop and BSP you can add one line:
bloopExportJarClassifiers in Global := Some(Set("sources"))
to your build.sbt, also sbt updateClassifiers, also Reload all BSP Projects to refresh, also Invalidate Caches/Restart to trigger indexing (if not done automatically)
reference