Skip to content

Commit d27f5a4

Browse files
committed
Start sbt only if necessary, don't keep server alive
This commit changes the behavior of the IDE so that it runs `configureIDE` only if the project hasn't been configured yet. sbt will now be started only if necessary, and the server will not be kept alive longer than necessary.
1 parent db52072 commit d27f5a4

File tree

1 file changed

+5
-25
lines changed

1 file changed

+5
-25
lines changed

vscode-dotty/src/extension.ts

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ export let client: LanguageClient
2626
/** The sbt process that may have been started by this extension */
2727
let sbtProcess: ChildProcess | undefined
2828

29-
/** The status bar where the show the status of sbt server */
30-
let sbtStatusBar: vscode.StatusBarItem
31-
3229
const sbtVersion = "1.2.3"
3330
const sbtArtifact = `org.scala-sbt:sbt-launch:${sbtVersion}`
3431
export const workspaceRoot = `${vscode.workspace.rootPath}`
@@ -95,11 +92,14 @@ export function activate(context: ExtensionContext) {
9592
return Promise.reject()
9693
}
9794
})
95+
.then(_ => connectToSbt(coursierPath))
96+
.then(sbt => {
97+
return withProgress("Configuring Dotty IDE...", configureIDE(sbt))
98+
.then(_ => { sbtserver.tellSbt(outputChannel, sbt, "exit") })
99+
})
98100
}
99101

100102
configuredProject
101-
.then(_ => connectToSbt(coursierPath))
102-
.then(sbt => withProgress("Configuring Dotty IDE...", configureIDE(sbt)))
103103
.then(_ => runLanguageServer(coursierPath, languageServerArtifactFile))
104104
}
105105
}
@@ -109,34 +109,14 @@ export function activate(context: ExtensionContext) {
109109
* connection is still alive. If it dies, restart sbt server.
110110
*/
111111
function connectToSbt(coursierPath: string): Thenable<rpc.MessageConnection> {
112-
if (!sbtStatusBar) sbtStatusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right)
113-
sbtStatusBar.text = "sbt server: connecting $(sync)"
114-
sbtStatusBar.show()
115112

116113
return offeringToRetry(() => {
117114
return withSbtInstance(coursierPath).then(connection => {
118-
connection.onClose(() => markSbtDownAndReconnect(coursierPath))
119-
markSbtUp()
120115
return connection
121116
})
122117
}, "Couldn't connect to sbt server (see log for details)")
123118
}
124119

125-
/** Mark sbt server as alive in the status bar */
126-
function markSbtUp() {
127-
sbtStatusBar.text = "sbt server: up $(check)"
128-
}
129-
130-
/** Mark sbt server as dead and try to reconnect */
131-
function markSbtDownAndReconnect(coursierPath: string) {
132-
sbtStatusBar.text = "sbt server: down $(x)"
133-
if (sbtProcess) {
134-
sbtProcess.kill()
135-
sbtProcess = undefined
136-
}
137-
connectToSbt(coursierPath)
138-
}
139-
140120
export function deactivate() {
141121
// If sbt was started by this extension, kill the process.
142122
// FIXME: This will be a problem for other clients of this server.

0 commit comments

Comments
 (0)