This is an automated email from the ASF dual-hosted git repository.

rstrickland pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil-vscode.git


The following commit(s) were added to refs/heads/main by this push:
     new e43dbd5  DataEditorClient Content Disposal Resolution
e43dbd5 is described below

commit e43dbd55ca0152c27dd91d8a6c9b3e652742433c
Author: stricklandrbls <[email protected]>
AuthorDate: Mon Feb 5 15:40:43 2024 -0600

    DataEditorClient Content Disposal Resolution
    
    Some disposables were being pushed to the context subscriptions
    container when utilized / created within the data editor environment.
    
    This resulted in inconsistent and incomplete resource disposal when
    running instances of the data editor.
    
    - Added disposables container to the DataEditorClient
    
    Closes #932
---
 src/dataEditor/dataEditorClient.ts | 40 +++++++++++++++++---------------------
 1 file changed, 18 insertions(+), 22 deletions(-)

diff --git a/src/dataEditor/dataEditorClient.ts 
b/src/dataEditor/dataEditorClient.ts
index 3b357ef..f71f607 100644
--- a/src/dataEditor/dataEditorClient.ts
+++ b/src/dataEditor/dataEditorClient.ts
@@ -148,7 +148,7 @@ export class DataEditorClient implements vscode.Disposable {
   private omegaSessionId = ''
   private sendHeartbeatIntervalId: NodeJS.Timeout | number | undefined =
     undefined
-
+  private disposables: vscode.Disposable[] = []
   constructor(
     protected context: vscode.ExtensionContext,
     private view: string,
@@ -162,8 +162,12 @@ export class DataEditorClient implements vscode.Disposable 
{
       enableScripts: true,
       retainContextWhenHidden: true,
     })
-
-    this.context.subscriptions.push(
+    this.panel.webview.onDidReceiveMessage(this.messageReceiver, this)
+    this.panel.onDidDispose(async () => {
+      await this.dispose()
+    })
+    this.disposables.push(
+      this.panel,
       vscode.debug.onDidReceiveDebugSessionCustomEvent(async (e) => {
         const debugEvent = e
         const eventAsEditorMessage = extractDaffodilEvent(debugEvent)
@@ -175,14 +179,15 @@ export class DataEditorClient implements 
vscode.Disposable {
       })
     )
 
-    this.panel.webview.onDidReceiveMessage(this.messageReceiver, this)
     this.svelteWebviewInitializer = new SvelteWebviewInitializer(context)
     this.svelteWebviewInitializer.initialize(this.view, this.panel.webview)
     this.currentViewportId = ''
     this.fileToEdit = fileToEdit
     this.displayState = new DisplayState(this.panel)
   }
-
+  addDisposable(dispoable: vscode.Disposable) {
+    this.disposables.push(dispoable)
+  }
   async dispose(): Promise<void> {
     if (this.sendHeartbeatIntervalId) {
       clearInterval(this.sendHeartbeatIntervalId)
@@ -191,8 +196,9 @@ export class DataEditorClient implements vscode.Disposable {
 
     // destroy the session and remove it from the list of active sessions
     removeActiveSession(await destroySession(this.omegaSessionId))
-    await serverStop()
-    this.panel.dispose()
+    await serverStopIf(NoSessionsExist)
+    for (let i = 0; i < this.disposables.length; i++)
+      this.disposables[i].dispose()
   }
 
   show(): void {
@@ -850,7 +856,6 @@ async function createDataEditorWebviewPanel(
     editor_config.WorkspaceKeyword,
     editor_config.rootPath
   )
-
   const dataEditorView = new DataEditorClient(
     ctx,
     'dataEditor',
@@ -858,22 +863,13 @@ async function createDataEditorWebviewPanel(
     launchConfigVars,
     fileToEdit
   )
-
   await dataEditorView.initialize()
-
-  dataEditorView.panel.onDidDispose(
-    async () => {
-      removeActiveSession(await destroySession(dataEditorView.sessionId()))
-      await serverStopIf(NoSessionsExist)
-    },
-    dataEditorView,
-    ctx.subscriptions
-  )
   if (isDFDLDebugSessionActive())
-    vscode.debug.onDidTerminateDebugSession(async () => {
-      removeActiveSession(await destroySession(dataEditorView.sessionId()))
-      await serverStopIf(NoSessionsExist)
-    })
+    dataEditorView.addDisposable(
+      vscode.debug.onDidTerminateDebugSession(async () => {
+        if (dataEditorView) await dataEditorView.dispose()
+      })
+    )
 
   dataEditorView.show()
   return dataEditorView

Reply via email to