@@ -41,20 +41,18 @@ import { loadModeledMethods, saveModeledMethods } from "./modeled-method-fs";
4141import { pickExtensionPack } from "./extension-pack-picker" ;
4242import { getLanguageDisplayName } from "../common/query-language" ;
4343import { AutoModeler } from "./auto-modeler" ;
44- import { INITIAL_HIDE_MODELED_METHODS_VALUE } from "./shared/hide-modeled-methods" ;
4544import { telemetryListener } from "../common/vscode/telemetry" ;
45+ import { ModelingStore } from "./modeling-store" ;
4646
4747export class ModelEditorView extends AbstractWebview <
4848 ToModelEditorMessage ,
4949 FromModelEditorMessage
5050> {
5151 private readonly autoModeler : AutoModeler ;
5252
53- private methods : Method [ ] ;
54- private hideModeledMethods : boolean ;
55-
5653 public constructor (
5754 protected readonly app : App ,
55+ private readonly modelingStore : ModelingStore ,
5856 private readonly databaseManager : DatabaseManager ,
5957 private readonly cliServer : CodeQLCliServer ,
6058 private readonly queryRunner : QueryRunner ,
@@ -63,23 +61,16 @@ export class ModelEditorView extends AbstractWebview<
6361 private readonly databaseItem : DatabaseItem ,
6462 private readonly extensionPack : ExtensionPack ,
6563 private mode : Mode ,
66- private readonly updateMethodsUsagePanelState : (
67- methods : Method [ ] ,
68- databaseItem : DatabaseItem ,
69- hideModeledMethods : boolean ,
70- ) => Promise < void > ,
7164 private readonly showMethod : (
7265 method : Method ,
7366 usage : Usage ,
7467 ) => Promise < void > ,
75- private readonly handleViewBecameActive : ( view : ModelEditorView ) => void ,
76- private readonly handleViewWasDisposed : ( view : ModelEditorView ) => void ,
77- private readonly isMostRecentlyActiveView : (
78- view : ModelEditorView ,
79- ) => boolean ,
8068 ) {
8169 super ( app ) ;
8270
71+ this . modelingStore . initializeStateForDb ( databaseItem ) ;
72+ this . registerToModelingStoreEvents ( ) ;
73+
8374 this . autoModeler = new AutoModeler (
8475 app ,
8576 cliServer ,
@@ -97,8 +88,6 @@ export class ModelEditorView extends AbstractWebview<
9788 await this . postMessage ( { t : "addModeledMethods" , modeledMethods } ) ;
9889 } ,
9990 ) ;
100- this . methods = [ ] ;
101- this . hideModeledMethods = INITIAL_HIDE_MODELED_METHODS_VALUE ;
10291 }
10392
10493 public async openView ( ) {
@@ -107,20 +96,15 @@ export class ModelEditorView extends AbstractWebview<
10796
10897 panel . onDidChangeViewState ( async ( ) => {
10998 if ( panel . active ) {
110- this . handleViewBecameActive ( this ) ;
111- await this . updateMethodsUsagePanelState (
112- this . methods ,
113- this . databaseItem ,
114- this . hideModeledMethods ,
115- ) ;
99+ this . modelingStore . setActiveDb ( this . databaseItem ) ;
116100 await this . markModelEditorAsActive ( ) ;
117101 } else {
118102 await this . updateModelEditorActiveContext ( ) ;
119103 }
120104 } ) ;
121105
122106 panel . onDidDispose ( ( ) => {
123- this . handleViewWasDisposed ( this ) ;
107+ this . modelingStore . removeDb ( this . databaseItem ) ;
124108 // onDidDispose is called after the tab has been closed,
125109 // so we want to check if there are any others still open.
126110 void this . app . commands . execute (
@@ -309,11 +293,11 @@ export class ModelEditorView extends AbstractWebview<
309293 break ;
310294 case "switchMode" :
311295 this . mode = msg . mode ;
312- this . methods = [ ] ;
296+ this . modelingStore . setMethods ( this . databaseItem , [ ] ) ;
313297 await Promise . all ( [
314298 this . postMessage ( {
315299 t : "setMethods" ,
316- methods : this . methods ,
300+ methods : [ ] ,
317301 } ) ,
318302 this . setViewState ( ) ,
319303 withProgress ( ( progress ) => this . loadMethods ( progress ) , {
@@ -324,11 +308,9 @@ export class ModelEditorView extends AbstractWebview<
324308
325309 break ;
326310 case "hideModeledMethods" :
327- this . hideModeledMethods = msg . hideModeledMethods ;
328- await this . updateMethodsUsagePanelState (
329- this . methods ,
311+ this . modelingStore . setHideModeledMethods (
330312 this . databaseItem ,
331- this . hideModeledMethods ,
313+ msg . hideModeledMethods ,
332314 ) ;
333315 void telemetryListener ?. sendUIInteraction (
334316 "model-editor-hide-modeled-methods" ,
@@ -409,19 +391,8 @@ export class ModelEditorView extends AbstractWebview<
409391 if ( ! queryResult ) {
410392 return ;
411393 }
412- this . methods = queryResult ;
413394
414- await this . postMessage ( {
415- t : "setMethods" ,
416- methods : this . methods ,
417- } ) ;
418- if ( this . isMostRecentlyActiveView ( this ) ) {
419- await this . updateMethodsUsagePanelState (
420- this . methods ,
421- this . databaseItem ,
422- this . hideModeledMethods ,
423- ) ;
424- }
395+ this . modelingStore . setMethods ( this . databaseItem , queryResult ) ;
425396 } catch ( err ) {
426397 void showAndLogExceptionWithTelemetry (
427398 this . app . logger ,
@@ -527,6 +498,7 @@ export class ModelEditorView extends AbstractWebview<
527498
528499 const view = new ModelEditorView (
529500 this . app ,
501+ this . modelingStore ,
530502 this . databaseManager ,
531503 this . cliServer ,
532504 this . queryRunner ,
@@ -535,11 +507,7 @@ export class ModelEditorView extends AbstractWebview<
535507 addedDatabase ,
536508 modelFile ,
537509 Mode . Framework ,
538- this . updateMethodsUsagePanelState ,
539510 this . showMethod ,
540- this . handleViewBecameActive ,
541- this . handleViewWasDisposed ,
542- this . isMostRecentlyActiveView ,
543511 ) ;
544512 await view . openView ( ) ;
545513 } ) ;
@@ -617,4 +585,17 @@ export class ModelEditorView extends AbstractWebview<
617585
618586 return addedDatabase ;
619587 }
588+
589+ private registerToModelingStoreEvents ( ) {
590+ this . push (
591+ this . modelingStore . onMethodsChanged ( async ( event ) => {
592+ if ( event . dbUri === this . databaseItem . databaseUri . toString ( ) ) {
593+ await this . postMessage ( {
594+ t : "setMethods" ,
595+ methods : event . methods ,
596+ } ) ;
597+ }
598+ } ) ,
599+ ) ;
600+ }
620601}
0 commit comments