I'm doing Scala web development using the Play framework's scala module, and using Emacs+Ensime to edit the code. Sometimes even when Ensime shows no errors, Play will still show a compilation error for a .scala file (like a type parameter mistake, or even a typo'd override, which is such a basic error).
How can I make ensime show all compilation errors that Play would show?
I'm using Scala 2.8.1, with ensime_2.8.2-SNAPSHOT-0.5.1 (which seemed like the best of the available options when I downloaded it).
I don't think this is supported, because ensime only uses the presentation compiler, which does not do all the checks that the full scalac compiler does.
Related
Although IntelliJ Scala Plugin uses Scala compiler proper to generate the actual bytecode, it seems to use its own implementation of presentation compiler to provide real-time type-aware error highlighting in the editor:
syntax highlighting feature that is implemented by Idea's Scala
plugin and it requires immediate re-processing of all the files you
change in a way similar but now exactly the same as what the real
compiler does.
This might be the reason why sometimes projects build successfully and yet IntelliJ shows false positive red underlines in the editor. This seems to be the case even if use sbt shell is selected as evident by open ticket SCL-11079
By default, the sbt compile should mark additional errors it finds in
the editor and project view. False positive errors reported by the
internal annotator should be removed if possible. There should be an
option to use sbt output as the "single source of truth" for
highlighting errors, at the cost of instant error highlighting.
or if project is imported as BSP project
sbt shell indeed won't help with error highlighting in the editor, nor
will BSP (for the time being). In-ide highlighting uses a method that
is completely separate from regular compilation
Is there anyway to configure IntelliJ to use Scala out-of-the-box presentation compiler instead of its own custom implementation such that we can decrease the chance false positive errors akin to what Metals provides?
According to show bsp diagnostics in editor SCL-16610 there exists a IntelliJ registry flag
scala.highlighting.compiler.errors.in.editor
which enables experimental feature
As error highlighting using the built-in parser and type-checker
continues to be a problem for the Scala plugin, we can experiment with
using compiler output from BSP... Potential downsides: Less rich error highlighting on type mismatch
problems: BSP and the compiler expose only raw string messages and
positions. We would lose type diffs and type error hints.
Here are the steps that made it work on my machine
Install JetBrains Toolbox which enables installation of Early Access Programs alongside releases (such that you can revert to your working system if anything goes wrong)
Install 2020.1
Make sure Nightly Builds update channel is set under Preferences | Languages & Frameworks | Scala | Updates
Remove .idea from the root of the project: rm -fr .idea
Re-import the project and select BSP project
There should be .bloop directory under project root if all OK
Open IntelliJ registry: Help | Find Action... | Registry
Set key scala.highlighting.compiler.errors.in.editor
When I open a maven module with scala code (link) which compiles and runs fine, I get bad error highlights:
Code-complete seems broken as well. How to fix this? (I don't want to switch to SBT since I only want this one module in the project to use scala, and I've tried the "Invalidate Caches / Restart" fix suggested here in vain.)
It is a known problem in IntelliJ with Scala because of the complex type system of scala.
I mostly use sbt. If I encounter such problem, first I compile it with sbt in the command line, most time wrong error highlights disappear.
If this does not help, clear IntelliJ cash and restart it (File -> Invalidated Caches / Restart).
Suspicious that at least a part of this post might be an April Fool's joke, I set about installing Dotty on my Linux laptop and was pleased and surprised to discover that it seems to be completely straight - I was able to get the Fibonacci function as given in German working fine from the REPL.
Now I want to code in Dotty/Scala in German in the IntelliJ IDE, but have not so far managed to achieve this, or for that matter English Language 'Hello World' for which will the Dotty compile fails with an SBT error, see below (there are no errors in the IntelliJ code window for the object).
Opening a new Dotty project via the IntelliJ new project dialogue puts a new instance of Dotty in my .ivy2 directory, distinct from that I use in the REPL. I have found Felix Mulder's Dotty plugin but I'm not sure how to use a plugin from source. After the project has set itself up:
German keywords are not recognised in any new Scala file I create in src > main.
In build.sbt some operators and keywords are not recognised
In build.sbt each entry gives the error Expression Def.Setting[SomeType] must conform to DslEntry in SBT file
I get this error log warning (twice):
Binary version (0.1.1-20170410-0bd7821-NIGHTLY) for dependency
ch.epfl.lamp#scala-library;0.1.1-20170410-0bd7821-NIGHTLY in
default#skala_2.11;0.1-SNAPSHOT differs from Scala binary version in
project (2.11).
which I think might be a consequence of the skala and dotty paths in my PATH environment variable.
Searching on the error message in point 3 led me here: I can switch to an unbundled SBT I know to be good easily enough, but HW will still not compile, instead giving a quite lengthy SBT error.
Unfortunately I don't understand the syntax of the entries in build.sbt well enough to change them according to the advice of murmelssonic. If I just have to learn that then OK, I'm sure I can.
I believe I have read posts which suggest that the build.sbt errors can be ignored as they do not actually lead to compile errors, but I can't confirm this as I can't compile anything yet. Even if this be true, I want to eliminate these, the better not to obscure legitimate warnings and errors.
My question might be better expresses as simply "How do I install the Dotty plugin for IntelliJ?", but I'm not sure that's the complete solution to this collection of symptoms.
System info:
OS Kubuntu 16.10
Java 1.8_121
IntelliJ 2017.1
Dotty v0.1.1-20170410
SBT 0.13.13 and 0.13.15 (each attempted) via IntellliJ dialogue
SBT 0.1-SNAPSHOT (from sbt version on command line in sbt dir, used by changing IntelliJ settings).
While Skala is a natural development for the Scala language, seeing how its creator Martin Odersky is a German and should have implemented German keywords in the first place, JetBrains is a company founded by Russians. As such, we are committed to exporting cyrillic keywords into the world of programming.
In a way, IntelliJ-Scala is already an alternative compiler for the Scala programming language specification. This will be increasingly true with the release of the all-new Скала plugin for IntelliJ!
This is a totally official statement by the IntelliJ-Скала team's only German member.
I have started using Play 2.1.0 and I would like to be able to use NetBeans to develop Play Java applications. I'm not really interested in using the IDE to run or test the applications since I can do that from the command line (not that I would mind if I could also have IDE support for that) but I would like to be able to open and edit my project in NetBeans without getting annoying errors where they don't really exist. I am currently using NetBeans 7.3 so I first tried to use the nbplay plugin, however it wouldn't recognise all my imports or managed classes produced by Play. I then tried to import the project as Eclipse project, as described in this and this question, which worked better, but while working my way through one of Play's Java tutorials I am still getting the following errors which make it really annoying to work with NetBeans:
I get an "Expected an operand but found error" error in main.scala.html where #content is used, although I have instructed the IDE to disable HTML error checking for this file.
In my model classes I get errors because the classes do not declare a no-argument constructor and have public variables for persistent attributes.
Any other errors I have not come across yet?
Has anyone managed to make Play 2.1.0 work with NetBeans without getting any of the above errors? I could probably live with the first one (although it would really annoy me) but the rest are showstoppers.
Be aware that the Java hints can be enable or disable in Tools -> Options -> Editor -> Hints -> Select java language.
NetBeans now has Native Support for Play Framework 2.3.x and above: http://nbpleasureplugin.com/documentation/installation.html No Command line needed at all.
The most important features are:
Create, run, debug and test your app directly in the IDE
Routes files support (Syntax coloring, Syntax Error highlighting, Autocompletion, Code navigation, Show implementation code (without navigate to source), Hint to Create method when it doesn’t exist, formatting, Mark occurrences)
Scala Template support (Syntax coloring, Syntax Error highlighting, Autocompletion, Code navigation, Show implementation code (without navigate to source), formatting, Mark occurrences)
application.conf support (Syntax coloring, autocompletion with documentation, formatting, mark occurrences)
Dependency Management (Search on Maven and add them to build.sbt)
2 Code Coverage too.s supported (jacoco and scoverage)
Test Single File
SBT file minimal support
Configurations (Formatting indentation, syntax coloring, port to use, activator parameters, etc.)
*Support play version from 2.3.x and above
Note: I created this plugin.
Also I see this could help you: How do I use Play Framework 2.0 in netbeans
I go back and forth between Eclipse and IntelliJ for Scala development. IntelliJ's code-complete, refactoring and error-highlighting are all better (in my experience) but I end up going back to Eclipse because whenever I run a Scala application in IntelliJ, it goes through this very long compilation process that Eclipse somehow avoids.
I can see the status bar whiz by as it loads each individual class and then runs them through several phases. I know that scalac is slow in general, but it's much quicker to use the command line or Eclipse than it is to use IntelliJ.
Is anyone else seeing this behavior? Will turning on fsc support make a big difference?
Either use the IDEA SBT plugin to delegate compilation to SBT, or enable use of Fast Scala Compiler (FSC) under Settings → Compiler → Scala.
Otherwise IntelliJ starts and stops a scalac process to compile each batch of files, and this has some overhead.