Skip to content

Commit 1601cda

Browse files
committed
Remove nop command
We use `connection.onClose` to automatically reconnect when the connection with sbt is closed.
1 parent a3555c8 commit 1601cda

File tree

3 files changed

+3
-24
lines changed

3 files changed

+3
-24
lines changed

sbt-dotty/src/dotty/tools/sbtplugin/DottyIDEPlugin.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,6 @@ object DottyIDEPlugin extends AutoPlugin {
269269
Command.process("runCode", state1)
270270
}
271271

272-
/** An sbt command that does nothing. We use it to check that sbt server is still alive. */
273-
def nopCommand = Command.command("nop")(state => state)
274-
275272
private def projectConfigTask(config: Configuration): Initialize[Task[Option[ProjectConfig]]] = Def.taskDyn {
276273
if ((sources in config).value.isEmpty) Def.task { None }
277274
else Def.task {
@@ -307,7 +304,7 @@ object DottyIDEPlugin extends AutoPlugin {
307304
)
308305

309306
override def buildSettings: Seq[Setting[_]] = Seq(
310-
commands ++= Seq(configureIDE, compileForIDE, launchIDE, nopCommand),
307+
commands ++= Seq(configureIDE, compileForIDE, launchIDE),
311308

312309
excludeFromIDE := false,
313310

vscode-dotty/src/extension.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ let sbtProcess: ChildProcess | undefined
2727
/** The status bar where the show the status of sbt server */
2828
let sbtStatusBar: vscode.StatusBarItem
2929

30-
/** Interval in ms to check that sbt is alive */
31-
const sbtCheckIntervalMs = 10 * 1000
32-
33-
/** A command that we use to check that sbt is still alive. */
34-
export const nopCommand = "nop"
35-
3630
const sbtVersion = "1.2.3"
3731
const sbtArtifact = `org.scala-sbt:sbt-launch:${sbtVersion}`
3832
const workspaceRoot = `${vscode.workspace.rootPath}`
@@ -108,8 +102,8 @@ function connectToSbt(coursierPath: string): Thenable<rpc.MessageConnection> {
108102

109103
return offeringToRetry(() => {
110104
return withSbtInstance(coursierPath).then(connection => {
105+
connection.onClose(() => markSbtDownAndReconnect(coursierPath))
111106
markSbtUp()
112-
const interval = setInterval(() => checkSbt(interval, connection, coursierPath), sbtCheckIntervalMs)
113107
return connection
114108
})
115109
}, "Couldn't connect to sbt server (see log for details)")
@@ -130,16 +124,6 @@ function markSbtDownAndReconnect(coursierPath: string) {
130124
connectToSbt(coursierPath)
131125
}
132126

133-
/** Check that sbt is alive, try to reconnect if it is dead. */
134-
function checkSbt(interval: NodeJS.Timer, connection: rpc.MessageConnection, coursierPath: string) {
135-
sbtserver.tellSbt(outputChannel, connection, nopCommand)
136-
.then(_ => markSbtUp(),
137-
_ => {
138-
clearInterval(interval)
139-
markSbtDownAndReconnect(coursierPath)
140-
})
141-
}
142-
143127
export function deactivate() {
144128
// If sbt was started by this extension, kill the process.
145129
// FIXME: This will be a problem for other clients of this server.

vscode-dotty/src/sbt-server.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ import * as rpc from 'vscode-jsonrpc'
1818

1919
import * as vscode from 'vscode'
2020

21-
import { nopCommand } from './extension'
22-
2321
/** The result of successful `sbt/exec` call. */
2422
export interface ExecResult {
2523
status: string
@@ -70,7 +68,7 @@ export function connectToSbtServer(log: vscode.OutputChannel): Promise<rpc.Messa
7068
log.appendLine(`<<< [${messageTypeToString(params.type)}] ${params.message}`)
7169
})
7270

73-
return tellSbt(log, connection, nopCommand).then(_ => connection)
71+
return connection
7472
})
7573
}
7674

0 commit comments

Comments
 (0)