Skip to content

Commit

Permalink
fix: register event listeners for proper disposal of client provider
Browse files Browse the repository at this point in the history
  • Loading branch information
abentkamp committed Jul 7, 2024
1 parent b153d53 commit eb181a0
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions vscode-lean4/src/utils/clientProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class LeanClientProvider implements Disposable {
this.installer = installer

// we must setup the installChanged event handler first before any didOpenEditor calls.
installer.installChanged(async (uri: FileUri) => await this.onInstallChanged(uri))
this.subscriptions.push(installer.installChanged(async (uri: FileUri) => await this.onInstallChanged(uri)))

window.visibleTextEditors.forEach(e => this.didOpenEditor(e.document))
this.subscriptions.push(
Expand All @@ -77,24 +77,26 @@ export class LeanClientProvider implements Disposable {
commands.registerCommand('lean4.stopServer', () => this.stopActiveClient()),
)

workspace.onDidOpenTextDocument(document => this.didOpenEditor(document))
this.subscriptions.push(workspace.onDidOpenTextDocument(document => this.didOpenEditor(document)))

workspace.onDidChangeWorkspaceFolders(event => {
// Remove all clients that are not referenced by any folder anymore
if (event.removed.length === 0) {
return
}
this.clients.forEach((client, key) => {
if (client.folderUri.scheme === 'untitled' || getWorkspaceFolderUri(client.folderUri)) {
this.subscriptions.push(
workspace.onDidChangeWorkspaceFolders(event => {
// Remove all clients that are not referenced by any folder anymore
if (event.removed.length === 0) {
return
}
this.clients.forEach((client, key) => {
if (client.folderUri.scheme === 'untitled' || getWorkspaceFolderUri(client.folderUri)) {
return
}

logger.log(`[ClientProvider] onDidChangeWorkspaceFolders removing client for ${key}`)
this.clients.delete(key)
client.dispose()
this.clientRemovedEmitter.fire(client)
})
})
logger.log(`[ClientProvider] onDidChangeWorkspaceFolders removing client for ${key}`)
this.clients.delete(key)
client.dispose()
this.clientRemovedEmitter.fire(client)
})
}),
)
}

getActiveClient(): LeanClient | undefined {
Expand Down

0 comments on commit eb181a0

Please sign in to comment.