How to configure IntelliJ Scala Plugin to use Scala's native presentation compiler?

人走茶凉 提交于 2020-06-17 12:56:40

问题


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?


回答1:


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

  1. 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)
  2. Install 2020.1
  3. Make sure Nightly Builds update channel is set under Preferences | Languages & Frameworks | Scala | Updates

  4. Remove .idea from the root of the project: rm -fr .idea
  5. Re-import the project and select BSP project

  6. There should be .bloop directory under project root if all OK
  7. Open IntelliJ registry: Help | Find Action... | Registry
  8. Set key scala.highlighting.compiler.errors.in.editor



来源:https://stackoverflow.com/questions/61099741/how-to-configure-intellij-scala-plugin-to-use-scalas-native-presentation-compil

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!