How to execute dotty code from Visual Studio Code

2019-08-12 01:56发布

问题:

I'm trying to use Visual Studio Code to run dotty code. I started IDE using sbt launchIDE according to the instruction from this page, and I also installed Dotty Language Server and Code Runner extensions. Dotty is installed using brew and I can compile and execute dotty code from CMD.

The problem is that I cannot run this code from Visual Studio Code because Code Runner is trying to execute it using scala instead of dotty.

Can't find any useful configuration to adjust this plugin to use dotty.

Is there any way to make it works from Visual Studio Code UI?

回答1:

Clone repository https://github.com/lampepfl/dotty-example-project (it's mentioned at the page https://dotty.epfl.ch/docs/usage/getting-started.html) and run

sbt launchIDE

(this is mentined at https://dotty.epfl.ch/docs/usage/ide-support.html).

The code should be run with scala (runtime is the same). If the code is compiled with scalac instead of dotty this can mean that either scalaVersion is wrong in build.sbt or dotty sbt plugin is not switched on in plugins.sbt.

build.sbt

lazy val root = project
  .in(file("."))
  .settings(
    name := "dottydemo",
    version := "0.1",
    scalaVersion := "0.13.0-RC1"
)

plugins.sbt

addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.3.0")

Also you can try IntelliJ IDEA (although it's not officially supported) Run Scala Dotty project using Intellij IDE