Skip to content

Commit c1f0e75

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

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
val depClasspath = Attributed.data((dependencyClasspath in config).value)
277274

@@ -314,7 +311,7 @@ object DottyIDEPlugin extends AutoPlugin {
314311
)
315312

316313
override def buildSettings: Seq[Setting[_]] = Seq(
317-
commands ++= Seq(configureIDE, compileForIDE, launchIDE, nopCommand),
314+
commands ++= Seq(configureIDE, compileForIDE, launchIDE),
318315

319316
excludeFromIDE := false,
320317

vscode-dotty/src/extension.ts

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

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

123117
return offeringToRetry(() => {
124118
return withSbtInstance(coursierPath).then(connection => {
119+
connection.onClose(() => markSbtDownAndReconnect(coursierPath))
125120
markSbtUp()
126-
const interval = setInterval(() => checkSbt(interval, connection, coursierPath), sbtCheckIntervalMs)
127121
return connection
128122
})
129123
}, "Couldn't connect to sbt server (see log for details)")
@@ -144,16 +138,6 @@ function markSbtDownAndReconnect(coursierPath: string) {
144138
connectToSbt(coursierPath)
145139
}
146140

147-
/** Check that sbt is alive, try to reconnect if it is dead. */
148-
function checkSbt(interval: NodeJS.Timer, connection: rpc.MessageConnection, coursierPath: string) {
149-
sbtserver.tellSbt(outputChannel, connection, nopCommand)
150-
.then(_ => markSbtUp(),
151-
_ => {
152-
clearInterval(interval)
153-
markSbtDownAndReconnect(coursierPath)
154-
})
155-
}
156-
157141
export function deactivate() {
158142
// If sbt was started by this extension, kill the process.
159143
// 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)