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
9 changes: 8 additions & 1 deletion extensions/ql-vscode/src/common/interface-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import type {
UrlValueResolvable,
} from "./raw-result-types";
import type { AccessPathSuggestionOptions } from "../model-editor/suggestions";
import type { ModelEvaluationRunState } from "../model-editor/shared/model-evaluation-run-state";

/**
* This module contains types and code that are shared between
Expand Down Expand Up @@ -633,6 +634,11 @@ interface SetAccessPathSuggestionsMessage {
accessPathSuggestions: AccessPathSuggestionOptions;
}

interface SetModelEvaluationRunMessage {
t: "setModelEvaluationRun";
run: ModelEvaluationRunState | undefined;
}

export type ToModelEditorMessage =
| SetExtensionPackStateMessage
| SetMethodsMessage
Expand All @@ -641,7 +647,8 @@ export type ToModelEditorMessage =
| SetInProgressMethodsMessage
| SetProcessedByAutoModelMethodsMessage
| RevealMethodMessage
| SetAccessPathSuggestionsMessage;
| SetAccessPathSuggestionsMessage
| SetModelEvaluationRunMessage;

export type FromModelEditorMessage =
| CommonFromViewMessages
Expand Down
26 changes: 18 additions & 8 deletions extensions/ql-vscode/src/model-editor/model-editor-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,15 @@ import { LSPErrorCodes } from "vscode-languageclient";
import type { AccessPathSuggestionOptions } from "./suggestions";
import { runSuggestionsQuery } from "./suggestion-queries";
import { parseAccessPathSuggestionRowsToOptions } from "./suggestions-bqrs";
import { ModelEvaluator } from "./model-evaluator";
import type { ModelEvaluationRunState } from "./shared/model-evaluation-run-state";

export class ModelEditorView extends AbstractWebview<
ToModelEditorMessage,
FromModelEditorMessage
> {
private readonly autoModeler: AutoModeler;
private readonly modelEvaluator: ModelEvaluator;
private readonly languageDefinition: ModelsAsDataLanguage;

public constructor(
Expand Down Expand Up @@ -101,6 +104,14 @@ export class ModelEditorView extends AbstractWebview<
},
);
this.languageDefinition = getModelsAsDataLanguage(language);

this.modelEvaluator = new ModelEvaluator(
modelingStore,
modelingEvents,
databaseItem,
this.updateModelEvaluationRun.bind(this),
);
this.push(this.modelEvaluator);
}

public async openView() {
Expand Down Expand Up @@ -338,10 +349,10 @@ export class ModelEditorView extends AbstractWebview<
break;
}
case "startModelEvaluation":
this.startModelEvaluation();
await this.modelEvaluator.startEvaluation();
break;
case "stopModelEvaluation":
this.stopModelEvaluation();
await this.modelEvaluator.stopEvaluation();
break;
case "telemetry":
telemetryListener?.sendUIInteraction(msg.action);
Expand Down Expand Up @@ -920,11 +931,10 @@ export class ModelEditorView extends AbstractWebview<
this.modelingStore.addModifiedMethod(this.databaseItem, signature);
}

private startModelEvaluation() {
// Do nothing for now. This will be fleshed out in the near future.
}

private stopModelEvaluation() {
// Do nothing for now. This will be fleshed out in the near future.
private async updateModelEvaluationRun(run: ModelEvaluationRunState) {
await this.postMessage({
t: "setModelEvaluationRun",
run,
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface ModelEvaluationRun {
isPreparing: boolean;
variantAnalysisId: number | undefined;
}
73 changes: 73 additions & 0 deletions extensions/ql-vscode/src/model-editor/model-evaluator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import type { ModelingStore } from "./modeling-store";
import type { ModelingEvents } from "./modeling-events";
import type { DatabaseItem } from "../databases/local-databases";
import type { ModelEvaluationRun } from "./model-evaluation-run";
import { DisposableObject } from "../common/disposable-object";
import { sleep } from "../common/time";
import type { ModelEvaluationRunState } from "./shared/model-evaluation-run-state";

export class ModelEvaluator extends DisposableObject {
public constructor(
private readonly modelingStore: ModelingStore,
private readonly modelingEvents: ModelingEvents,
private readonly dbItem: DatabaseItem,
private readonly updateView: (
run: ModelEvaluationRunState,
) => Promise<void>,
) {
super();

this.registerToModelingEvents();
}

public async startEvaluation() {
// Update store with evaluation run status
const evaluationRun: ModelEvaluationRun = {
isPreparing: true,
variantAnalysisId: undefined,
};
this.modelingStore.updateModelEvaluationRun(this.dbItem, evaluationRun);

// For now, just wait 5 seconds and then update the store.
// In the future, this will be replaced with the actual evaluation process.
Comment thread
charisk marked this conversation as resolved.
void sleep(5000).then(() => {
const completedEvaluationRun: ModelEvaluationRun = {
isPreparing: false,
variantAnalysisId: undefined,
};
this.modelingStore.updateModelEvaluationRun(
this.dbItem,
completedEvaluationRun,
);
});
}

public async stopEvaluation() {
// For now just update the store.
// This will be fleshed out in the near future.
const evaluationRun: ModelEvaluationRun = {
isPreparing: false,
variantAnalysisId: undefined,
};
this.modelingStore.updateModelEvaluationRun(this.dbItem, evaluationRun);
}

private registerToModelingEvents() {
this.push(
this.modelingEvents.onModelEvaluationRunChanged(async (event) => {
if (
event.evaluationRun &&
event.dbUri === this.dbItem.databaseUri.toString()
) {
const run: ModelEvaluationRunState = {
isPreparing: event.evaluationRun.isPreparing,

// TODO: Get variant analysis from id.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do this in the next PR. It needs the VariantAnalysisManager wired in and it would make the PR bigger than it is so I left it out for now.

variantAnalysis: undefined,
};
await this.updateView(run);
}
}),
);
}
}
24 changes: 24 additions & 0 deletions extensions/ql-vscode/src/model-editor/modeling-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DisposableObject } from "../common/disposable-object";
import type { AppEvent, AppEventEmitter } from "../common/events";
import type { DatabaseItem } from "../databases/local-databases";
import type { Method, Usage } from "./method";
import type { ModelEvaluationRun } from "./model-evaluation-run";
import type { ModeledMethod } from "./modeled-method";
import type { Mode } from "./shared/mode";

Expand Down Expand Up @@ -55,6 +56,11 @@ interface ProcessedByAutoModelMethodsChangedEvent {
readonly methods: ReadonlySet<string>;
}

interface ModelEvaluationRunChangedEvent {
readonly dbUri: string;
readonly evaluationRun: ModelEvaluationRun | undefined;
}

interface RevealInModelEditorEvent {
dbUri: string;
method: Method;
Expand All @@ -76,6 +82,7 @@ export class ModelingEvents extends DisposableObject {
public readonly onSelectedMethodChanged: AppEvent<SelectedMethodChangedEvent>;
public readonly onInProgressMethodsChanged: AppEvent<InProgressMethodsChangedEvent>;
public readonly onProcessedByAutoModelMethodsChanged: AppEvent<ProcessedByAutoModelMethodsChangedEvent>;
public readonly onModelEvaluationRunChanged: AppEvent<ModelEvaluationRunChangedEvent>;
public readonly onRevealInModelEditor: AppEvent<RevealInModelEditorEvent>;
public readonly onFocusModelEditor: AppEvent<FocusModelEditorEvent>;

Expand All @@ -90,6 +97,7 @@ export class ModelingEvents extends DisposableObject {
private readonly onSelectedMethodChangedEventEmitter: AppEventEmitter<SelectedMethodChangedEvent>;
private readonly onInProgressMethodsChangedEventEmitter: AppEventEmitter<InProgressMethodsChangedEvent>;
private readonly onProcessedByAutoModelMethodsChangedEventEmitter: AppEventEmitter<ProcessedByAutoModelMethodsChangedEvent>;
private readonly onModelEvaluationRunChangedEventEmitter: AppEventEmitter<ModelEvaluationRunChangedEvent>;
private readonly onRevealInModelEditorEventEmitter: AppEventEmitter<RevealInModelEditorEvent>;
private readonly onFocusModelEditorEventEmitter: AppEventEmitter<FocusModelEditorEvent>;

Expand Down Expand Up @@ -155,6 +163,12 @@ export class ModelingEvents extends DisposableObject {
this.onProcessedByAutoModelMethodsChanged =
this.onProcessedByAutoModelMethodsChangedEventEmitter.event;

this.onModelEvaluationRunChangedEventEmitter = this.push(
app.createEventEmitter<ModelEvaluationRunChangedEvent>(),
);
this.onModelEvaluationRunChanged =
this.onModelEvaluationRunChangedEventEmitter.event;

this.onRevealInModelEditorEventEmitter = this.push(
app.createEventEmitter<RevealInModelEditorEvent>(),
);
Expand Down Expand Up @@ -273,6 +287,16 @@ export class ModelingEvents extends DisposableObject {
});
}

public fireModelEvaluationRunChangedEvent(
dbUri: string,
evaluationRun: ModelEvaluationRun | undefined,
) {
this.onModelEvaluationRunChangedEventEmitter.fire({
dbUri,
evaluationRun,
});
}

public fireRevealInModelEditorEvent(dbUri: string, method: Method) {
this.onRevealInModelEditorEventEmitter.fire({
dbUri,
Expand Down
27 changes: 27 additions & 0 deletions extensions/ql-vscode/src/model-editor/modeling-store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DisposableObject } from "../common/disposable-object";
import type { DatabaseItem } from "../databases/local-databases";
import type { Method, Usage } from "./method";
import type { ModelEvaluationRun } from "./model-evaluation-run";
import type { ModeledMethod } from "./modeled-method";
import type { ModelingEvents } from "./modeling-events";
import { INITIAL_HIDE_MODELED_METHODS_VALUE } from "./shared/hide-modeled-methods";
Expand All @@ -17,6 +18,7 @@ interface InternalDbModelingState {
processedByAutoModelMethods: Set<string>;
selectedMethod: Method | undefined;
selectedUsage: Usage | undefined;
modelEvaluationRun: ModelEvaluationRun | undefined;
}

interface DbModelingState {
Expand All @@ -30,6 +32,7 @@ interface DbModelingState {
readonly processedByAutoModelMethods: ReadonlySet<string>;
readonly selectedMethod: Method | undefined;
readonly selectedUsage: Usage | undefined;
readonly modelEvaluationRun: ModelEvaluationRun | undefined;
}

interface SelectedMethodDetails {
Expand Down Expand Up @@ -66,6 +69,7 @@ export class ModelingStore extends DisposableObject {
selectedMethod: undefined,
selectedUsage: undefined,
inProgressMethods: new Set(),
modelEvaluationRun: undefined,
});

this.modelingEvents.fireDbOpenedEvent(databaseItem);
Expand Down Expand Up @@ -372,6 +376,15 @@ export class ModelingStore extends DisposableObject {
});
}

public updateModelEvaluationRun(
dbItem: DatabaseItem,
evaluationRun: ModelEvaluationRun,
) {
this.changeModelEvaluationRun(dbItem, (state) => {
state.modelEvaluationRun = evaluationRun;
});
}

public getSelectedMethodDetails(): SelectedMethodDetails | undefined {
const dbState = this.getInternalStateForActiveDb();
if (!dbState) {
Expand Down Expand Up @@ -465,4 +478,18 @@ export class ModelingStore extends DisposableObject {
state.processedByAutoModelMethods,
);
}

private changeModelEvaluationRun(
dbItem: DatabaseItem,
updateState: (state: InternalDbModelingState) => void,
) {
const state = this.getState(dbItem);

updateState(state);

this.modelingEvents.fireModelEvaluationRunChangedEvent(
dbItem.databaseUri.toString(),
state.modelEvaluationRun,
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { VariantAnalysisStatus } from "../../variant-analysis/shared/variant-analysis";
import type { VariantAnalysis } from "../../variant-analysis/shared/variant-analysis";

export interface ModelEvaluationRunState {
isPreparing: boolean;
variantAnalysis: VariantAnalysis | undefined;
}

export function modelEvaluationRunIsRunning(
run: ModelEvaluationRunState,
): boolean {
return (
run.isPreparing ||
!!(
run.variantAnalysis &&
run.variantAnalysis.status === VariantAnalysisStatus.InProgress
)
);
}
Loading