Skip to content

Commit aadb30f

Browse files
committed
Replace load-plugin with --addPluginSbtFile
1 parent 76a52c9 commit aadb30f

File tree

2 files changed

+19
-31
lines changed

2 files changed

+19
-31
lines changed

project/Build.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ object Build {
5353
}
5454
val dottyNonBootstrappedVersion = dottyVersion + "-nonbootstrapped"
5555

56+
val sbtDottyName = "sbt-dotty"
5657
val sbtDottyVersion = {
5758
val base = "0.2.3"
5859
if (isRelease) base else base + "-SNAPSHOT"
@@ -935,6 +936,7 @@ object Build {
935936
lazy val `sbt-dotty` = project.in(file("sbt-dotty")).
936937
settings(commonSettings).
937938
settings(
939+
name := sbtDottyName,
938940
version := sbtDottyVersion,
939941
// Keep in sync with inject-sbt-dotty.sbt
940942
libraryDependencies ++= Seq(
@@ -975,9 +977,11 @@ object Build {
975977
includeFilter in unmanagedSources := NothingFilter | "*.ts" | "**.json",
976978
watchSources in Global ++= (unmanagedSources in Compile).value,
977979
resourceGenerators in Compile += Def.task {
978-
val out = baseDirectory.value / "out" / "default-dotty-ide-config"
979-
IO.writeLines(out, Seq(dottyVersion, sbtDottyVersion))
980-
Seq(out)
980+
val defaultIDEConfig = baseDirectory.value / "out" / "default-dotty-ide-config"
981+
IO.write(defaultIDEConfig, dottyVersion)
982+
val dottyPluginSbtFile = baseDirectory.value / "out" / "dotty-plugin.sbt"
983+
IO.write(dottyPluginSbtFile, s"""addSbtPlugin("$dottyOrganization" % $sbtDottyName % "$sbtDottyVersion")""")
984+
Seq(defaultIDEConfig, dottyPluginSbtFile)
981985
},
982986
compile in Compile := Def.task {
983987
val workingDir = baseDirectory.value

vscode-dotty/src/extension.ts

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ export function activate(context: ExtensionContext) {
1616
extensionContext = context
1717
outputChannel = vscode.window.createOutputChannel('Dotty Language Client');
1818

19-
const sbtArtifact = "org.scala-sbt:sbt-launch:1.1.5"
20-
const loadPluginArtifact = "ch.epfl.scala:load-plugin_2.12:0.1.0+2-496ac670"
19+
const sbtArtifact = "org.scala-sbt:sbt-launch:1.2.0"
2120
const buildSbtFile = `${vscode.workspace.rootPath}/build.sbt`
21+
const dottyPluginSbtFile = path.join(extensionContext.extensionPath, './out/dotty-plugin.sbt')
2222
const languageServerArtifactFile = `${vscode.workspace.rootPath}/.dotty-ide-artifact`
2323
const languageServerDefaultConfigFile = path.join(extensionContext.extensionPath, './out/default-dotty-ide-config')
2424
const coursierPath = path.join(extensionContext.extensionPath, './out/coursier');
@@ -51,8 +51,8 @@ export function activate(context: ExtensionContext) {
5151
fs.readFile(languageServerDefaultConfigFile, (err, data) => {
5252
if (err) throw err
5353
else {
54-
const [languageServerScalaVersion, sbtDottyVersion] = data.toString().trim().split(/\r?\n/)
55-
fetchAndConfigure(coursierPath, sbtArtifact, languageServerScalaVersion, sbtDottyVersion, loadPluginArtifact).then(() => {
54+
const languageServerScalaVersion = data.toString().trim()
55+
fetchAndConfigure(coursierPath, sbtArtifact, languageServerScalaVersion, dottyPluginSbtFile).then(() => {
5656
runLanguageServer(coursierPath, languageServerArtifactFile)
5757
})
5858
}
@@ -78,15 +78,10 @@ function runLanguageServer(coursierPath: string, languageServerArtifactFile: str
7878
})
7979
}
8080

81-
function fetchAndConfigure(coursierPath: string, sbtArtifact: string, languageServerScalaVersion: string, sbtDottyVersion: string, loadPluginArtifact: string) {
82-
const sbtPromise = fetchWithCoursier(coursierPath, sbtArtifact)
83-
const loadPluginPromise = fetchWithCoursier(coursierPath, loadPluginArtifact)
84-
85-
return Promise.all([sbtPromise, loadPluginPromise]).then((results) => {
86-
const [sbtClasspath, loadPluginJar] = results
87-
return configureIDE(sbtClasspath, languageServerScalaVersion, sbtDottyVersion, loadPluginJar)
88-
})
89-
81+
function fetchAndConfigure(coursierPath: string, sbtArtifact: string, languageServerScalaVersion: string, dottyPluginSbtFile: string) {
82+
return fetchWithCoursier(coursierPath, sbtArtifact).then((sbtClasspath) => {
83+
return configureIDE(sbtClasspath, languageServerScalaVersion, dottyPluginSbtFile)
84+
})
9085
}
9186

9287
function fetchWithCoursier(coursierPath: string, artifact: string, extra: string[] = []) {
@@ -108,10 +103,6 @@ function fetchWithCoursier(coursierPath: string, artifact: string, extra: string
108103
coursierProc.stdout.on('data', (data: Buffer) => {
109104
classPath += data.toString().trim()
110105
})
111-
coursierProc.stderr.on('data', (data: Buffer) => {
112-
let msg = data.toString().trim()
113-
outputChannel.append(msg)
114-
})
115106

116107
coursierProc.on('close', (code: number) => {
117108
if (code != 0) {
@@ -124,27 +115,20 @@ function fetchWithCoursier(coursierPath: string, artifact: string, extra: string
124115
})
125116
}
126117

127-
function configureIDE(sbtClasspath: string, languageServerScalaVersion: string, sbtDottyVersion: string, loadPluginJar: string) {
118+
function configureIDE(sbtClasspath: string, languageServerScalaVersion: string, dottyPluginSbtFile: string) {
128119
return vscode.window.withProgress({
129120
location: vscode.ProgressLocation.Window,
130121
title: 'Configuring IDE...'
131122
}, (progress) => {
132-
const applyLoadPlugin = `apply -cp ${ loadPluginJar } ch.epfl.scala.loadplugin.LoadPlugin`
133-
const ifAbsentCommands = [
134-
"if-absent dotty.tools.sbtplugin.DottyPlugin",
135-
"\"set every scalaVersion := \\\"" + languageServerScalaVersion + "\\\"\"",
136-
"\"load-plugin ch.epfl.lamp:sbt-dotty:" + sbtDottyVersion + " dotty.tools.sbtplugin.DottyPlugin\"",
137-
"\"load-plugin ch.epfl.lamp:sbt-dotty:" + sbtDottyVersion + " dotty.tools.sbtplugin.DottyIDEPlugin\""
138-
].join(" ")
139123

140124
// Run sbt to configure the IDE. If the `DottyPlugin` is not present, dynamically load it and
141125
// eventually run `configureIDE`.
142126
const sbtPromise =
143127
cpp.spawn("java", [
144128
"-classpath", sbtClasspath,
145129
"xsbt.boot.Boot",
146-
applyLoadPlugin,
147-
ifAbsentCommands,
130+
`--addPluginSbtFile=${dottyPluginSbtFile}`,
131+
`set every scalaVersion := "${languageServerScalaVersion}"`,
148132
"configureIDE"
149133
])
150134

@@ -157,7 +141,7 @@ function configureIDE(sbtClasspath: string, languageServerScalaVersion: string,
157141
}
158142
})
159143

160-
return sbtPromise
144+
return sbtPromise
161145
})
162146
}
163147

0 commit comments

Comments
 (0)