Skip to content

Commit 3395f20

Browse files
committed
Visual Studio Code extension for Dotty
This extension uses the Dotty Language Server to provide IDE features in Visual Studio Code.
1 parent d6f468a commit 3395f20

File tree

10 files changed

+509
-1
lines changed

10 files changed

+509
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ project/local-plugins.sbt
1717
.ensime
1818
.ensime_cache/
1919

20+
# npm
21+
node_modules
22+
2023
# Scala-IDE specific
2124
.scala_dependencies
2225
.cache

build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ val `scala-reflect` = Build.`scala-reflect`
2121
val scalap = Build.scalap
2222

2323
val `sbt-dotty` = Build.`sbt-dotty`
24+
val `vscode-dotty` = Build.`vscode-dotty`
2425

2526
inThisBuild(Build.thisBuildSettings)

project/Build.scala

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ object Build {
8282
bootstrapFromPublishedJars := false
8383
)
8484

85+
// Only available in vscode-dotty
86+
lazy val unpublish = taskKey[Unit]("Unpublish a package")
87+
88+
8589

8690
lazy val commonSettings = publishSettings ++ Seq(
8791
organization := dottyOrganization,
@@ -762,7 +766,20 @@ object DottyInjectedPlugin extends AutoPlugin {
762766
libraryDependencies ++= Seq(
763767
"org.eclipse.lsp4j" % "org.eclipse.lsp4j" % "0.2.0",
764768
Dependencies.`jackson-databind`
765-
)
769+
),
770+
javaOptions := (javaOptions in `dotty-compiler-bootstrapped`).value,
771+
772+
run := Def.inputTaskDyn {
773+
val inputArgs = spaceDelimited("<arg>").parsed
774+
775+
val mainClass = "dotty.tools.languageserver.Main"
776+
val extensionPath = (baseDirectory in `vscode-dotty`).value.getAbsolutePath
777+
778+
val codeArgs = if (inputArgs.isEmpty) List((baseDirectory.value / "..").getAbsolutePath) else inputArgs
779+
val allArgs = List("-client_command", "code", s"--extensionDevelopmentPath=$extensionPath") ++ codeArgs
780+
781+
runTask(Runtime, mainClass, allArgs: _*)
782+
}.dependsOn(compile in (`vscode-dotty`, Compile)).evaluated
766783
)
767784

768785
/** A sandbox to play with the Scala.js back-end of dotty.
@@ -896,6 +913,95 @@ object DottyInjectedPlugin extends AutoPlugin {
896913
}).evaluated
897914
)
898915

916+
lazy val `vscode-dotty` = project.in(file("vscode-dotty")).
917+
settings(commonSettings).
918+
settings(
919+
EclipseKeys.skipProject := true,
920+
921+
version := "0.0.1", // Keep in sync with package.json
922+
923+
autoScalaLibrary := false,
924+
publishArtifact := false,
925+
includeFilter in unmanagedSources := NothingFilter | "*.ts" | "**.json",
926+
watchSources in Global ++= (unmanagedSources in Compile).value,
927+
compile in Compile := {
928+
val coursier = baseDirectory.value / "out/coursier"
929+
val packageJson = baseDirectory.value / "package.json"
930+
if (!coursier.exists || packageJson.lastModified > coursier.lastModified) {
931+
val exitCode = new java.lang.ProcessBuilder("npm", "run", "update-all")
932+
.directory(baseDirectory.value)
933+
.inheritIO()
934+
.start()
935+
.waitFor()
936+
if (exitCode != 0)
937+
throw new FeedbackProvidedException {
938+
override def toString = "'npm run update-all' in vscode-dotty failed"
939+
}
940+
}
941+
val tsc = baseDirectory.value / "node_modules" / ".bin" / "tsc"
942+
val exitCode = new java.lang.ProcessBuilder(tsc.getAbsolutePath, "--pretty", "--project", baseDirectory.value.getAbsolutePath)
943+
.inheritIO()
944+
.start()
945+
.waitFor()
946+
if (exitCode != 0)
947+
throw new FeedbackProvidedException {
948+
override def toString = "tsc in vscode-dotty failed"
949+
}
950+
sbt.inc.Analysis.Empty
951+
},
952+
sbt.Keys.`package`:= {
953+
val exitCode = new java.lang.ProcessBuilder("vsce", "package")
954+
.directory(baseDirectory.value)
955+
.inheritIO()
956+
.start()
957+
.waitFor()
958+
if (exitCode != 0)
959+
throw new FeedbackProvidedException {
960+
override def toString = "vsce package failed"
961+
}
962+
963+
baseDirectory.value / s"dotty-${version.value}.vsix"
964+
},
965+
unpublish := {
966+
val exitCode = new java.lang.ProcessBuilder("vsce", "unpublish")
967+
.directory(baseDirectory.value)
968+
.inheritIO()
969+
.start()
970+
.waitFor()
971+
if (exitCode != 0)
972+
throw new FeedbackProvidedException {
973+
override def toString = "vsce unpublish failed"
974+
}
975+
},
976+
publish := {
977+
val exitCode = new java.lang.ProcessBuilder("vsce", "publish")
978+
.directory(baseDirectory.value)
979+
.inheritIO()
980+
.start()
981+
.waitFor()
982+
if (exitCode != 0)
983+
throw new FeedbackProvidedException {
984+
override def toString = "vsce publish failed"
985+
}
986+
},
987+
run := Def.inputTask {
988+
val inputArgs = spaceDelimited("<arg>").parsed
989+
val codeArgs = if (inputArgs.isEmpty) List((baseDirectory.value / "..").getAbsolutePath) else inputArgs
990+
val extensionPath = baseDirectory.value.getAbsolutePath
991+
val processArgs = List("code", s"--extensionDevelopmentPath=${extensionPath}") ++ codeArgs
992+
993+
val exitCode = new java.lang.ProcessBuilder(processArgs: _*)
994+
.inheritIO()
995+
.start()
996+
.waitFor()
997+
if (exitCode != 0)
998+
throw new FeedbackProvidedException {
999+
override def toString = "Running Visual Studio Code failed"
1000+
}
1001+
}.dependsOn(compile in Compile).evaluated
1002+
)
1003+
1004+
8991005
lazy val publishSettings = Seq(
9001006
publishMavenStyle := true,
9011007
isSnapshot := version.value.contains("SNAPSHOT"),

vscode-dotty/.vscodeignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## This is used to exclude files from "vsce publish"
2+
target/**
3+
.vscode/**
4+
.vscode-test/**
5+
out/test/**
6+
test/**
7+
src/**
8+
**/*.map
9+
.gitignore
10+
tsconfig.json

vscode-dotty/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# IDE support for Dotty, the experimental Scala compiler
2+
3+
## Prerequistes
4+
To use this in your own Scala project, you must first get it to compile with
5+
Dotty, please follow the instructions at https://github.com/lampepfl/dotty-example-project
6+
7+
## Starting Visual Studio Code from sbt
8+
Once your project succesfully compiles with dotty, you can simply use the
9+
`launchIDE` command provided by the sbt-dotty plugin:
10+
11+
```shell
12+
sbt launchIDE
13+
```
14+
15+
## More information
16+
17+
See http://dotty.epfl.ch/docs/usage/ide-support.html

0 commit comments

Comments
 (0)