diff --git a/extensions/ql-vscode/src/model-editor/method-modeling/method-modeling-view-provider.ts b/extensions/ql-vscode/src/model-editor/method-modeling/method-modeling-view-provider.ts index 7e70231df..6aafd0906 100644 --- a/extensions/ql-vscode/src/model-editor/method-modeling/method-modeling-view-provider.ts +++ b/extensions/ql-vscode/src/model-editor/method-modeling/method-modeling-view-provider.ts @@ -159,15 +159,17 @@ export class MethodModelingViewProvider extends AbstractWebviewViewProvider< private registerToModelingEvents(): void { this.push( - this.modelingEvents.onModeledMethodsChanged(async (e) => { + this.modelingEvents.onModelingStateChanged(async (e) => { if (this.webviewView && e.isActiveDb && this.method) { - const modeledMethods = e.modeledMethods[this.method.signature]; - if (modeledMethods) { - await this.postMessage({ - t: "setMultipleModeledMethods", - methodSignature: this.method.signature, - modeledMethods, - }); + if (e.modeledMethods !== undefined) { + const modeledMethods = e.modeledMethods[this.method.signature]; + if (modeledMethods) { + await this.postMessage({ + t: "setMultipleModeledMethods", + methodSignature: this.method.signature, + modeledMethods, + }); + } } if (e.modifiedMethodSignatures !== undefined) { @@ -176,18 +178,25 @@ export class MethodModelingViewProvider extends AbstractWebviewViewProvider< isModified: e.modifiedMethodSignatures.has(this.method.signature), }); } - } - }), - ); - this.push( - this.modelingEvents.onModifiedMethodsChanged(async (e) => { - if (this.webviewView && e.isActiveDb && this.method) { - const isModified = e.modifiedMethods.has(this.method.signature); - await this.postMessage({ - t: "setMethodModified", - isModified, - }); + if (e.inProgressMethodSignatures !== undefined) { + const inProgress = e.inProgressMethodSignatures.has( + this.method.signature, + ); + await this.postMessage({ + t: "setInProgress", + inProgress, + }); + } + + if (e.processedByAutoModelMethodSignatures !== undefined) { + const processedByAutoModel = + e.processedByAutoModelMethodSignatures.has(this.method.signature); + await this.postMessage({ + t: "setProcessedByAutoModel", + processedByAutoModel, + }); + } } }), ); @@ -239,36 +248,6 @@ export class MethodModelingViewProvider extends AbstractWebviewViewProvider< } }), ); - - this.push( - this.modelingEvents.onInProgressMethodsChanged(async (e) => { - if (this.method && this.databaseItem) { - const dbUri = this.databaseItem.databaseUri.toString(); - if (e.dbUri === dbUri) { - const inProgress = e.methods.has(this.method.signature); - await this.postMessage({ - t: "setInProgress", - inProgress, - }); - } - } - }), - ); - - this.push( - this.modelingEvents.onProcessedByAutoModelMethodsChanged(async (e) => { - if (this.method && this.databaseItem) { - const dbUri = this.databaseItem.databaseUri.toString(); - if (e.dbUri === dbUri) { - const processedByAutoModel = e.methods.has(this.method.signature); - await this.postMessage({ - t: "setProcessedByAutoModel", - processedByAutoModel, - }); - } - } - }), - ); } private registerToModelConfigEvents(): void { diff --git a/extensions/ql-vscode/src/model-editor/methods-usage/methods-usage-panel.ts b/extensions/ql-vscode/src/model-editor/methods-usage/methods-usage-panel.ts index 1180939ab..863f2eca5 100644 --- a/extensions/ql-vscode/src/model-editor/methods-usage/methods-usage-panel.ts +++ b/extensions/ql-vscode/src/model-editor/methods-usage/methods-usage-panel.ts @@ -80,7 +80,7 @@ export class MethodsUsagePanel extends DisposableObject { ); this.push( - this.modelingEvents.onMethodsChanged(async (event) => { + this.modelingEvents.onModelingStateChanged(async (event) => { if (event.isActiveDb) { await this.handleStateChangeEvent(); } @@ -102,14 +102,6 @@ export class MethodsUsagePanel extends DisposableObject { } }), ); - - this.push( - this.modelingEvents.onModifiedMethodsChanged(async (event) => { - if (event.isActiveDb) { - await this.handleStateChangeEvent(); - } - }), - ); } private async handleStateChangeEvent(): Promise { diff --git a/extensions/ql-vscode/src/model-editor/model-editor-module.ts b/extensions/ql-vscode/src/model-editor/model-editor-module.ts index 6acd88d7f..1390b36f5 100644 --- a/extensions/ql-vscode/src/model-editor/model-editor-module.ts +++ b/extensions/ql-vscode/src/model-editor/model-editor-module.ts @@ -108,16 +108,18 @@ export class ModelEditorModule extends DisposableObject { ); this.push( - this.modelingEvents.onMethodsChanged((event) => { - const modeledMethods = this.modelingStore.getModeledMethods( - event.databaseItem, - ); + this.modelingEvents.onModelingStateChanged((event) => { + if (event.methods !== undefined) { + const modeledMethods = this.modelingStore.getModeledMethods( + event.databaseItem, + ); - checkConsistency( - event.methods, - modeledMethods, - new DefaultNotifier(this.app.logger), - ); + checkConsistency( + event.methods, + modeledMethods, + new DefaultNotifier(this.app.logger), + ); + } }), ); } diff --git a/extensions/ql-vscode/src/model-editor/model-editor-view.ts b/extensions/ql-vscode/src/model-editor/model-editor-view.ts index 3bf4f2a02..40eb83a62 100644 --- a/extensions/ql-vscode/src/model-editor/model-editor-view.ts +++ b/extensions/ql-vscode/src/model-editor/model-editor-view.ts @@ -807,63 +807,29 @@ export class ModelEditorView extends AbstractWebview< private registerToModelingEvents() { this.push( - this.modelingEvents.onMethodsChanged(async (event) => { + this.modelingEvents.onModelingStateChanged(async (event) => { if (event.dbUri === this.databaseItem.databaseUri.toString()) { await this.postMessage({ t: "setModelEditorState", methods: event.methods, - }); - } - }), - ); - - this.push( - this.modelingEvents.onModeledMethodsChanged(async (event) => { - if (event.dbUri === this.databaseItem.databaseUri.toString()) { - await this.postMessage({ - t: "setModelEditorState", modeledMethods: event.modeledMethods, - modifiedMethodSignatures: [...event.modifiedMethodSignatures], + modifiedMethodSignatures: + event.modifiedMethodSignatures === undefined + ? undefined + : [...event.modifiedMethodSignatures], + inProgressMethodSignatures: + event.inProgressMethodSignatures === undefined + ? undefined + : [...event.inProgressMethodSignatures], + processedByAutoModelMethodSignatures: + event.processedByAutoModelMethodSignatures === undefined + ? undefined + : [...event.processedByAutoModelMethodSignatures], }); } }), ); - this.push( - this.modelingEvents.onModifiedMethodsChanged(async (event) => { - if (event.dbUri === this.databaseItem.databaseUri.toString()) { - await this.postMessage({ - t: "setModelEditorState", - modifiedMethodSignatures: [...event.modifiedMethods], - }); - } - }), - ); - - this.push( - this.modelingEvents.onInProgressMethodsChanged(async (event) => { - if (event.dbUri === this.databaseItem.databaseUri.toString()) { - await this.postMessage({ - t: "setModelEditorState", - inProgressMethodSignatures: Array.from(event.methods), - }); - } - }), - ); - - this.push( - this.modelingEvents.onProcessedByAutoModelMethodsChanged( - async (event) => { - if (event.dbUri === this.databaseItem.databaseUri.toString()) { - await this.postMessage({ - t: "setModelEditorState", - processedByAutoModelMethodSignatures: Array.from(event.methods), - }); - } - }, - ), - ); - this.push( this.modelingEvents.onRevealInModelEditor(async (event) => { if (event.dbUri === this.databaseItem.databaseUri.toString()) { diff --git a/extensions/ql-vscode/src/model-editor/modeling-events.ts b/extensions/ql-vscode/src/model-editor/modeling-events.ts index 7853b7dc6..c15fff2c3 100644 --- a/extensions/ql-vscode/src/model-editor/modeling-events.ts +++ b/extensions/ql-vscode/src/model-editor/modeling-events.ts @@ -6,11 +6,15 @@ import type { Method, Usage } from "./method"; import type { ModeledMethod } from "./modeled-method"; import type { Mode } from "./shared/mode"; -interface MethodsChangedEvent { - readonly methods: readonly Method[]; +interface ModelingStateChangedEvent { readonly dbUri: string; readonly databaseItem: DatabaseItem; readonly isActiveDb: boolean; + readonly methods?: readonly Method[]; + readonly modeledMethods?: Readonly>; + readonly modifiedMethodSignatures?: ReadonlySet; + readonly inProgressMethodSignatures?: ReadonlySet; + readonly processedByAutoModelMethodSignatures?: ReadonlySet; } interface HideModeledMethodsChangedEvent { @@ -23,19 +27,6 @@ interface ModeChangedEvent { readonly isActiveDb: boolean; } -interface ModeledMethodsChangedEvent { - readonly modeledMethods: Readonly>; - readonly modifiedMethodSignatures: ReadonlySet; - readonly dbUri: string; - readonly isActiveDb: boolean; -} - -interface ModifiedMethodsChangedEvent { - readonly modifiedMethods: ReadonlySet; - readonly dbUri: string; - readonly isActiveDb: boolean; -} - interface SelectedMethodChangedEvent { readonly databaseItem: DatabaseItem; readonly method: Method; @@ -46,16 +37,6 @@ interface SelectedMethodChangedEvent { readonly processedByAutoModel: boolean; } -interface InProgressMethodsChangedEvent { - readonly dbUri: string; - readonly methods: ReadonlySet; -} - -interface ProcessedByAutoModelMethodsChangedEvent { - readonly dbUri: string; - readonly methods: ReadonlySet; -} - interface RevealInModelEditorEvent { dbUri: string; method: Method; @@ -69,28 +50,20 @@ export class ModelingEvents extends DisposableObject { public readonly onActiveDbChanged: AppEvent; public readonly onDbOpened: AppEvent; public readonly onDbClosed: AppEvent; - public readonly onMethodsChanged: AppEvent; + public readonly onModelingStateChanged: AppEvent; public readonly onHideModeledMethodsChanged: AppEvent; public readonly onModeChanged: AppEvent; - public readonly onModeledMethodsChanged: AppEvent; - public readonly onModifiedMethodsChanged: AppEvent; public readonly onSelectedMethodChanged: AppEvent; - public readonly onInProgressMethodsChanged: AppEvent; - public readonly onProcessedByAutoModelMethodsChanged: AppEvent; public readonly onRevealInModelEditor: AppEvent; public readonly onFocusModelEditor: AppEvent; private readonly onActiveDbChangedEventEmitter: AppEventEmitter; private readonly onDbOpenedEventEmitter: AppEventEmitter; private readonly onDbClosedEventEmitter: AppEventEmitter; - private readonly onMethodsChangedEventEmitter: AppEventEmitter; + private readonly onModelingStateChangedEventEmitter: AppEventEmitter; private readonly onHideModeledMethodsChangedEventEmitter: AppEventEmitter; private readonly onModeChangedEventEmitter: AppEventEmitter; - private readonly onModeledMethodsChangedEventEmitter: AppEventEmitter; - private readonly onModifiedMethodsChangedEventEmitter: AppEventEmitter; private readonly onSelectedMethodChangedEventEmitter: AppEventEmitter; - private readonly onInProgressMethodsChangedEventEmitter: AppEventEmitter; - private readonly onProcessedByAutoModelMethodsChangedEventEmitter: AppEventEmitter; private readonly onRevealInModelEditorEventEmitter: AppEventEmitter; private readonly onFocusModelEditorEventEmitter: AppEventEmitter; @@ -110,10 +83,10 @@ export class ModelingEvents extends DisposableObject { this.onDbClosedEventEmitter = this.push(app.createEventEmitter()); this.onDbClosed = this.onDbClosedEventEmitter.event; - this.onMethodsChangedEventEmitter = this.push( - app.createEventEmitter(), + this.onModelingStateChangedEventEmitter = this.push( + app.createEventEmitter(), ); - this.onMethodsChanged = this.onMethodsChangedEventEmitter.event; + this.onModelingStateChanged = this.onModelingStateChangedEventEmitter.event; this.onHideModeledMethodsChangedEventEmitter = this.push( app.createEventEmitter(), @@ -126,36 +99,12 @@ export class ModelingEvents extends DisposableObject { ); this.onModeChanged = this.onModeChangedEventEmitter.event; - this.onModeledMethodsChangedEventEmitter = this.push( - app.createEventEmitter(), - ); - this.onModeledMethodsChanged = - this.onModeledMethodsChangedEventEmitter.event; - - this.onModifiedMethodsChangedEventEmitter = this.push( - app.createEventEmitter(), - ); - this.onModifiedMethodsChanged = - this.onModifiedMethodsChangedEventEmitter.event; - this.onSelectedMethodChangedEventEmitter = this.push( app.createEventEmitter(), ); this.onSelectedMethodChanged = this.onSelectedMethodChangedEventEmitter.event; - this.onInProgressMethodsChangedEventEmitter = this.push( - app.createEventEmitter(), - ); - this.onInProgressMethodsChanged = - this.onInProgressMethodsChangedEventEmitter.event; - - this.onProcessedByAutoModelMethodsChangedEventEmitter = this.push( - app.createEventEmitter(), - ); - this.onProcessedByAutoModelMethodsChanged = - this.onProcessedByAutoModelMethodsChangedEventEmitter.event; - this.onRevealInModelEditorEventEmitter = this.push( app.createEventEmitter(), ); @@ -179,18 +128,8 @@ export class ModelingEvents extends DisposableObject { this.onDbClosedEventEmitter.fire(dbUri); } - public fireMethodsChangedEvent( - methods: Method[], - dbUri: string, - databaseItem: DatabaseItem, - isActiveDb: boolean, - ) { - this.onMethodsChangedEventEmitter.fire({ - methods, - databaseItem, - dbUri, - isActiveDb, - }); + public fireModelingStateChangedEvent(event: ModelingStateChangedEvent) { + this.onModelingStateChangedEventEmitter.fire(event); } public fireHideModeledMethodsChangedEvent( @@ -210,32 +149,6 @@ export class ModelingEvents extends DisposableObject { }); } - public fireModeledMethodsChangedEvent( - modeledMethods: Record, - modifiedMethodSignatures: ReadonlySet, - dbUri: string, - isActiveDb: boolean, - ) { - this.onModeledMethodsChangedEventEmitter.fire({ - modeledMethods, - modifiedMethodSignatures, - dbUri, - isActiveDb, - }); - } - - public fireModifiedMethodsChangedEvent( - modifiedMethods: ReadonlySet, - dbUri: string, - isActiveDb: boolean, - ) { - this.onModifiedMethodsChangedEventEmitter.fire({ - modifiedMethods, - dbUri, - isActiveDb, - }); - } - public fireSelectedMethodChangedEvent( databaseItem: DatabaseItem, method: Method, @@ -256,26 +169,6 @@ export class ModelingEvents extends DisposableObject { }); } - public fireInProgressMethodsChangedEvent( - dbUri: string, - methods: ReadonlySet, - ) { - this.onInProgressMethodsChangedEventEmitter.fire({ - dbUri, - methods, - }); - } - - public fireProcessedByAutoModelMethodsChangedEvent( - dbUri: string, - methods: ReadonlySet, - ) { - this.onProcessedByAutoModelMethodsChangedEventEmitter.fire({ - dbUri, - methods, - }); - } - public fireRevealInModelEditorEvent(dbUri: string, method: Method) { this.onRevealInModelEditorEventEmitter.fire({ dbUri, diff --git a/extensions/ql-vscode/src/model-editor/modeling-store.ts b/extensions/ql-vscode/src/model-editor/modeling-store.ts index c6eb96b79..50a3aafa0 100644 --- a/extensions/ql-vscode/src/model-editor/modeling-store.ts +++ b/extensions/ql-vscode/src/model-editor/modeling-store.ts @@ -156,12 +156,12 @@ export class ModelingStore extends DisposableObject { dbState.methods = [...methods]; - this.modelingEvents.fireMethodsChangedEvent( - methods, + this.modelingEvents.fireModelingStateChangedEvent({ dbUri, - dbItem, - dbUri === this.activeDb, - ); + databaseItem: dbItem, + isActiveDb: dbUri === this.activeDb, + methods, + }); } public setHideModeledMethods( @@ -408,11 +408,12 @@ export class ModelingStore extends DisposableObject { updateState(state); - this.modelingEvents.fireModifiedMethodsChangedEvent( - state.modifiedMethodSignatures, - dbItem.databaseUri.toString(), - dbItem.databaseUri.toString() === this.activeDb, - ); + this.modelingEvents.fireModelingStateChangedEvent({ + dbUri: dbItem.databaseUri.toString(), + databaseItem: dbItem, + isActiveDb: dbItem.databaseUri.toString() === this.activeDb, + modifiedMethodSignatures: state.modifiedMethodSignatures, + }); } private changeModeledMethods( @@ -423,12 +424,13 @@ export class ModelingStore extends DisposableObject { updateState(state); - this.modelingEvents.fireModeledMethodsChangedEvent( - state.modeledMethods, - state.modifiedMethodSignatures, - dbItem.databaseUri.toString(), - dbItem.databaseUri.toString() === this.activeDb, - ); + this.modelingEvents.fireModelingStateChangedEvent({ + dbUri: dbItem.databaseUri.toString(), + databaseItem: dbItem, + isActiveDb: dbItem.databaseUri.toString() === this.activeDb, + modeledMethods: state.modeledMethods, + modifiedMethodSignatures: state.modifiedMethodSignatures, + }); } private changeInProgressMethods( @@ -439,10 +441,12 @@ export class ModelingStore extends DisposableObject { updateState(state); - this.modelingEvents.fireInProgressMethodsChangedEvent( - dbItem.databaseUri.toString(), - state.inProgressMethods, - ); + this.modelingEvents.fireModelingStateChangedEvent({ + dbUri: dbItem.databaseUri.toString(), + databaseItem: dbItem, + isActiveDb: dbItem.databaseUri.toString() === this.activeDb, + inProgressMethodSignatures: state.inProgressMethods, + }); } private changeProcessedByAutoModelMethods( @@ -453,9 +457,11 @@ export class ModelingStore extends DisposableObject { updateState(state); - this.modelingEvents.fireProcessedByAutoModelMethodsChangedEvent( - dbItem.databaseUri.toString(), - state.processedByAutoModelMethods, - ); + this.modelingEvents.fireModelingStateChangedEvent({ + dbUri: dbItem.databaseUri.toString(), + databaseItem: dbItem, + isActiveDb: dbItem.databaseUri.toString() === this.activeDb, + processedByAutoModelMethodSignatures: state.processedByAutoModelMethods, + }); } } diff --git a/extensions/ql-vscode/test/__mocks__/model-editor/modelingEventsMock.ts b/extensions/ql-vscode/test/__mocks__/model-editor/modelingEventsMock.ts index 3444f946c..14f8088cf 100644 --- a/extensions/ql-vscode/test/__mocks__/model-editor/modelingEventsMock.ts +++ b/extensions/ql-vscode/test/__mocks__/model-editor/modelingEventsMock.ts @@ -4,38 +4,26 @@ import type { ModelingEvents } from "../../../src/model-editor/modeling-events"; export function createMockModelingEvents({ onActiveDbChanged = jest.fn(), onDbClosed = jest.fn(), - onMethodsChanged = jest.fn(), + onModelingStateChanged = jest.fn(), onHideModeledMethodsChanged = jest.fn(), onModeChanged = jest.fn(), - onModeledMethodsChanged = jest.fn(), - onModifiedMethodsChanged = jest.fn(), - onInProgressMethodsChanged = jest.fn(), - onProcessedByAutoModelMethodsChanged = jest.fn(), onRevealInModelEditor = jest.fn(), onFocusModelEditor = jest.fn(), }: { onActiveDbChanged?: ModelingEvents["onActiveDbChanged"]; onDbClosed?: ModelingEvents["onDbClosed"]; - onMethodsChanged?: ModelingEvents["onMethodsChanged"]; + onModelingStateChanged?: ModelingEvents["onModelingStateChanged"]; onHideModeledMethodsChanged?: ModelingEvents["onHideModeledMethodsChanged"]; onModeChanged?: ModelingEvents["onModeChanged"]; - onModeledMethodsChanged?: ModelingEvents["onModeledMethodsChanged"]; - onModifiedMethodsChanged?: ModelingEvents["onModifiedMethodsChanged"]; - onInProgressMethodsChanged?: ModelingEvents["onInProgressMethodsChanged"]; - onProcessedByAutoModelMethodsChanged?: ModelingEvents["onProcessedByAutoModelMethodsChanged"]; onRevealInModelEditor?: ModelingEvents["onRevealInModelEditor"]; onFocusModelEditor?: ModelingEvents["onFocusModelEditor"]; } = {}): ModelingEvents { return mockedObject({ onActiveDbChanged, onDbClosed, - onMethodsChanged, + onModelingStateChanged, onHideModeledMethodsChanged, onModeChanged, - onModeledMethodsChanged, - onModifiedMethodsChanged, - onInProgressMethodsChanged, - onProcessedByAutoModelMethodsChanged, onRevealInModelEditor, onFocusModelEditor, });