1- import { DisposableObject } from '../pure/disposable-object' ;
21import {
3- WebviewPanel ,
42 ExtensionContext ,
5- window as Window ,
63 ViewColumn ,
7- Uri ,
84} from 'vscode' ;
9- import * as path from 'path' ;
105
11- import { tmpDir } from '../helpers' ;
126import {
137 FromCompareViewMessage ,
148 ToCompareViewMessage ,
@@ -17,26 +11,24 @@ import {
1711import { Logger } from '../logging' ;
1812import { CodeQLCliServer } from '../cli' ;
1913import { DatabaseManager } from '../databases' ;
20- import { getHtmlForWebview , jumpToLocation } from '../interface-utils' ;
14+ import { jumpToLocation } from '../interface-utils' ;
2115import { transformBqrsResultSet , RawResultSet , BQRSInfo } from '../pure/bqrs-cli-types' ;
2216import resultsDiff from './resultsDiff' ;
2317import { CompletedLocalQueryInfo } from '../query-results' ;
2418import { getErrorMessage } from '../pure/helpers-pure' ;
2519import { HistoryItemLabelProvider } from '../history-item-label-provider' ;
20+ import { AbstractInterfaceManager , InterfacePanelConfig } from '../abstract-interface-manager' ;
2621
2722interface ComparePair {
2823 from : CompletedLocalQueryInfo ;
2924 to : CompletedLocalQueryInfo ;
3025}
3126
32- export class CompareInterfaceManager extends DisposableObject {
27+ export class CompareInterfaceManager extends AbstractInterfaceManager < ToCompareViewMessage , FromCompareViewMessage > {
3328 private comparePair : ComparePair | undefined ;
34- private panel : WebviewPanel | undefined ;
35- private panelLoaded = false ;
36- private panelLoadedCallBacks : ( ( ) => void ) [ ] = [ ] ;
3729
3830 constructor (
39- private ctx : ExtensionContext ,
31+ ctx : ExtensionContext ,
4032 private databaseManager : DatabaseManager ,
4133 private cliServer : CodeQLCliServer ,
4234 private logger : Logger ,
@@ -45,7 +37,7 @@ export class CompareInterfaceManager extends DisposableObject {
4537 item : CompletedLocalQueryInfo
4638 ) => Promise < void >
4739 ) {
48- super ( ) ;
40+ super ( ctx ) ;
4941 }
5042
5143 async showResults (
@@ -103,64 +95,24 @@ export class CompareInterfaceManager extends DisposableObject {
10395 }
10496 }
10597
106- getPanel ( ) : WebviewPanel {
107- if ( this . panel == undefined ) {
108- const { ctx } = this ;
109- const panel = ( this . panel = Window . createWebviewPanel (
110- 'compareView' ,
111- 'Compare CodeQL Query Results' ,
112- { viewColumn : ViewColumn . Active , preserveFocus : true } ,
113- {
114- enableScripts : true ,
115- enableFindWidget : true ,
116- retainContextWhenHidden : true ,
117- localResourceRoots : [
118- Uri . file ( tmpDir . name ) ,
119- Uri . file ( path . join ( this . ctx . extensionPath , 'out' ) ) ,
120- ] ,
121- }
122- ) ) ;
123- this . push ( this . panel . onDidDispose (
124- ( ) => {
125- this . panel = undefined ;
126- this . comparePair = undefined ;
127- } ,
128- null ,
129- ctx . subscriptions
130- ) ) ;
131-
132- panel . webview . html = getHtmlForWebview (
133- ctx ,
134- panel . webview ,
135- 'compare'
136- ) ;
137- this . push ( panel . webview . onDidReceiveMessage (
138- async ( e ) => this . handleMsgFromView ( e ) ,
139- undefined ,
140- ctx . subscriptions
141- ) ) ;
142- }
143- return this . panel ;
98+ protected getPanelConfig ( ) : InterfacePanelConfig {
99+ return {
100+ viewId : 'compareView' ,
101+ title : 'Compare CodeQL Query Results' ,
102+ viewColumn : ViewColumn . Active ,
103+ preserveFocus : true ,
104+ view : 'compare' ,
105+ } ;
144106 }
145107
146- private waitForPanelLoaded ( ) : Promise < void > {
147- return new Promise ( ( resolve ) => {
148- if ( this . panelLoaded ) {
149- resolve ( ) ;
150- } else {
151- this . panelLoadedCallBacks . push ( resolve ) ;
152- }
153- } ) ;
108+ protected onPanelDispose ( ) : void {
109+ this . comparePair = undefined ;
154110 }
155111
156- private async handleMsgFromView (
157- msg : FromCompareViewMessage
158- ) : Promise < void > {
112+ protected async onMessage ( msg : FromCompareViewMessage ) : Promise < void > {
159113 switch ( msg . t ) {
160114 case 'compareViewLoaded' :
161- this . panelLoaded = true ;
162- this . panelLoadedCallBacks . forEach ( ( cb ) => cb ( ) ) ;
163- this . panelLoadedCallBacks = [ ] ;
115+ this . onWebViewLoaded ( ) ;
164116 break ;
165117
166118 case 'changeCompare' :
@@ -177,10 +129,6 @@ export class CompareInterfaceManager extends DisposableObject {
177129 }
178130 }
179131
180- private postMessage ( msg : ToCompareViewMessage ) : Thenable < boolean > {
181- return this . getPanel ( ) . webview . postMessage ( msg ) ;
182- }
183-
184132 private async findCommonResultSetNames (
185133 from : CompletedLocalQueryInfo ,
186134 to : CompletedLocalQueryInfo ,
0 commit comments