@@ -75,6 +75,7 @@ import { telemetryListener } from "../common/vscode/telemetry";
7575import { redactableError } from "../common/errors" ;
7676import { ResultsViewCommands } from "../common/commands" ;
7777import { App } from "../common/app" ;
78+ import { Disposable } from "../common/disposable-object" ;
7879
7980/**
8081 * results-view.ts
@@ -157,6 +158,12 @@ function numInterpretedPages(
157158 return Math . ceil ( n / pageSize ) ;
158159}
159160
161+ /**
162+ * The results view is used for displaying the results of a local query. It is a singleton; only 1 results view exists
163+ * in the extension. It is created when the extension is activated and disposed of when the extension is deactivated.
164+ * There can be multiple panels linked to this view over the lifetime of the extension, but there is only ever 1 panel
165+ * active at a time.
166+ */
160167export class ResultsView extends AbstractWebview <
161168 IntoResultsViewMsg ,
162169 FromResultsViewMsg
@@ -168,6 +175,9 @@ export class ResultsView extends AbstractWebview<
168175 "codeql-query-results" ,
169176 ) ;
170177
178+ // Event listeners that should be disposed of when the view is disposed.
179+ private disposableEventListeners : Disposable [ ] = [ ] ;
180+
171181 constructor (
172182 app : App ,
173183 private databaseManager : DatabaseManager ,
@@ -176,14 +186,16 @@ export class ResultsView extends AbstractWebview<
176186 private labelProvider : HistoryItemLabelProvider ,
177187 ) {
178188 super ( app ) ;
179- this . push ( this . _diagnosticCollection ) ;
180- this . push (
189+
190+ // We can't use this.push for these two event listeners because they need to be disposed of when the view is
191+ // disposed, not when the panel is disposed. The results view is a singleton, so we shouldn't be calling this.push.
192+ this . disposableEventListeners . push (
181193 vscode . window . onDidChangeTextEditorSelection (
182194 this . handleSelectionChange . bind ( this ) ,
183195 ) ,
184196 ) ;
185197
186- this . push (
198+ this . disposableEventListeners . push (
187199 this . databaseManager . onDidChangeDatabaseItem ( ( { kind } ) => {
188200 if ( kind === DatabaseEventKind . Remove ) {
189201 this . _diagnosticCollection . clear ( ) ;
@@ -981,4 +993,12 @@ export class ResultsView extends AbstractWebview<
981993 editor . setDecorations ( shownLocationLineDecoration , [ ] ) ;
982994 }
983995 }
996+
997+ dispose ( ) {
998+ super . dispose ( ) ;
999+
1000+ this . _diagnosticCollection . dispose ( ) ;
1001+ this . disposableEventListeners . forEach ( ( d ) => d . dispose ( ) ) ;
1002+ this . disposableEventListeners = [ ] ;
1003+ }
9841004}
0 commit comments