Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion extensions/ql-vscode/src/common/interface-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,11 @@ interface OpenModelAlertsViewMessage {
t: "openModelAlertsView";
}

interface RevealInModelAlertsViewMessage {
t: "revealInModelAlertsView";
modeledMethod: ModeledMethod;
}

interface ModelDependencyMessage {
t: "modelDependency";
}
Expand Down Expand Up @@ -677,7 +682,8 @@ export type FromModelEditorMessage =
| SetMultipleModeledMethodsMessage
| StartModelEvaluationMessage
| StopModelEvaluationMessage
| OpenModelAlertsViewMessage;
| OpenModelAlertsViewMessage
| RevealInModelAlertsViewMessage;

interface RevealInEditorMessage {
t: "revealInModelEditor";
Expand Down
3 changes: 3 additions & 0 deletions extensions/ql-vscode/src/model-editor/model-editor-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,9 @@ export class ModelEditorView extends AbstractWebview<
case "openModelAlertsView":
await this.modelEvaluator.openModelAlertsView();
break;
case "revealInModelAlertsView":
await this.modelEvaluator.revealInModelAlertsView(msg.modeledMethod);
break;
case "telemetry":
telemetryListener?.sendUIInteraction(msg.action);
break;
Expand Down
11 changes: 11 additions & 0 deletions extensions/ql-vscode/src/model-editor/model-evaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type { QlPackDetails } from "../variant-analysis/ql-pack-details";
import type { App } from "../common/app";
import { ModelAlertsView } from "./model-alerts/model-alerts-view";
import type { ExtensionPack } from "./shared/extension-pack";
import type { ModeledMethod } from "./modeled-method";

export class ModelEvaluator extends DisposableObject {
// Cancellation token source to allow cancelling of the current run
Expand Down Expand Up @@ -158,6 +159,16 @@ export class ModelEvaluator extends DisposableObject {
}
}

public async revealInModelAlertsView(modeledMethod: ModeledMethod) {
if (!this.modelingStore.isModelAlertsViewOpen(this.dbItem)) {
await this.openModelAlertsView();
}
this.modelingEvents.fireRevealInModelAlertsViewEvent(
this.dbItem.databaseUri.toString(),
modeledMethod,
);
}

private registerToModelingEvents() {
this.push(
this.modelingEvents.onModelEvaluationRunChanged(async (event) => {
Expand Down
20 changes: 20 additions & 0 deletions extensions/ql-vscode/src/model-editor/modeling-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ interface FocusModelAlertsViewEvent {
dbUri: string;
}

interface RevealInModelAlertsViewEvent {
dbUri: string;
modeledMethod: ModeledMethod;
}

export class ModelingEvents extends DisposableObject {
public readonly onActiveDbChanged: AppEvent<void>;
public readonly onDbOpened: AppEvent<DatabaseItem>;
Expand All @@ -84,6 +89,7 @@ export class ModelingEvents extends DisposableObject {
public readonly onRevealInModelEditor: AppEvent<RevealInModelEditorEvent>;
public readonly onFocusModelEditor: AppEvent<FocusModelEditorEvent>;
public readonly onFocusModelAlertsView: AppEvent<FocusModelAlertsViewEvent>;
public readonly onRevealInModelAlertsView: AppEvent<RevealInModelAlertsViewEvent>;

private readonly onActiveDbChangedEventEmitter: AppEventEmitter<void>;
private readonly onDbOpenedEventEmitter: AppEventEmitter<DatabaseItem>;
Expand All @@ -99,6 +105,7 @@ export class ModelingEvents extends DisposableObject {
private readonly onRevealInModelEditorEventEmitter: AppEventEmitter<RevealInModelEditorEvent>;
private readonly onFocusModelEditorEventEmitter: AppEventEmitter<FocusModelEditorEvent>;
private readonly onFocusModelAlertsViewEventEmitter: AppEventEmitter<FocusModelAlertsViewEvent>;
private readonly onRevealInModelAlertsViewEventEmitter: AppEventEmitter<RevealInModelAlertsViewEvent>;

constructor(app: App) {
super();
Expand Down Expand Up @@ -176,6 +183,12 @@ export class ModelingEvents extends DisposableObject {
app.createEventEmitter<FocusModelAlertsViewEvent>(),
);
this.onFocusModelAlertsView = this.onFocusModelAlertsViewEventEmitter.event;

this.onRevealInModelAlertsViewEventEmitter = this.push(
app.createEventEmitter<RevealInModelAlertsViewEvent>(),
);
this.onRevealInModelAlertsView =
this.onRevealInModelAlertsViewEventEmitter.event;
}

public fireActiveDbChangedEvent() {
Expand Down Expand Up @@ -301,4 +314,11 @@ export class ModelingEvents extends DisposableObject {
public fireFocusModelAlertsViewEvent(dbUri: string) {
this.onFocusModelAlertsViewEventEmitter.fire({ dbUri });
}

public fireRevealInModelAlertsViewEvent(
dbUri: string,
modeledMethod: ModeledMethod,
) {
this.onRevealInModelAlertsViewEventEmitter.fire({ dbUri, modeledMethod });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { ModeledMethod } from "../../model-editor/modeled-method";
import type { ModelEvaluationRunState } from "../../model-editor/shared/model-evaluation-run-state";
import type { ModelEditorViewState } from "../../model-editor/shared/view-state";
import { VSCodeBadge } from "@vscode/webview-ui-toolkit/react";
import { vscode } from "../vscode-api";

const ModelAlertsButton = styled(VSCodeBadge)`
cursor: pointer;
Expand All @@ -27,6 +28,13 @@ export const ModelAlertsIndicator = ({
return null;
}

const revealInModelAlertsView = () => {
vscode.postMessage({
t: "revealInModelAlertsView",
modeledMethod,
});
};

// TODO: Once we have alert provenance, we can show actual alert counts here.
// For now, we show a random number.
const number = Math.floor(Math.random() * 10);
Expand All @@ -37,6 +45,7 @@ export const ModelAlertsIndicator = ({
aria-label="Model alerts"
onClick={(event: React.MouseEvent) => {
event.stopPropagation();
revealInModelAlertsView();
}}
>
{number}
Expand Down