Skip to content

Commit d57c16a

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 7bea59e commit d57c16a

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,12 +92,15 @@ export function activate(context: ExtensionContext) {
9592
return Promise.reject()
9693
}
9794
})
95+
.then(_ => connectToSbt(coursierPath))
96+
.then(sbt => {
97+
withProgress("Configuring Dotty IDE...", configureIDE(sbt))
98+
.then(_ => sbtserver.tellSbt(outputChannel, sbt, "exit"))
99+
})
98100
}
99101

100102
if (!fs.existsSync(disableDottyIDEFile)) {
101103
configuredProject
102-
.then(_ => connectToSbt(coursierPath))
103-
.then(sbt => withProgress("Configuring Dotty IDE...", configureIDE(sbt)))
104104
.then(_ => runLanguageServer(coursierPath, languageServerArtifactFile))
105105
}
106106
}
@@ -111,34 +111,14 @@ export function activate(context: ExtensionContext) {
111111
* connection is still alive. If it dies, restart sbt server.
112112
*/
113113
function connectToSbt(coursierPath: string): Thenable<rpc.MessageConnection> {
114-
if (!sbtStatusBar) sbtStatusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right)
115-
sbtStatusBar.text = "sbt server: connecting $(sync)"
116-
sbtStatusBar.show()
117114

118115
return offeringToRetry(() => {
119116
return withSbtInstance(coursierPath).then(connection => {
120-
connection.onClose(() => markSbtDownAndReconnect(coursierPath))
121-
markSbtUp()
122117
return connection
123118
})
124119
}, "Couldn't connect to sbt server (see log for details)")
125120
}
126121

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

0 commit comments

Comments
 (0)