Skip to content

Commit 3f0c267

Browse files
committed
[gh-1330] Potential fix for legacy execution flow format
1 parent 19cb47a commit 3f0c267

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

source/WebApp/app/shared/resultTypes.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ export type FlowStep = {
9292
readonly jump?: true;
9393
};
9494

95+
export type LegacyFlowStep = number | FlowStep;
96+
9597
export type FlowAreaType = 'method' | 'loop' | `unknown: ${string}`;
9698

9799
export type FlowArea = {
@@ -134,7 +136,7 @@ export interface AstResult extends ResultBase {
134136

135137
export type RunResultLegacyValue = {
136138
readonly output: ReadonlyArray<OutputItem>;
137-
readonly flow: ReadonlyArray<FlowStep>;
139+
readonly flow: ReadonlyArray<LegacyFlowStep>;
138140
};
139141

140142
export interface RunResult extends ResultBase {
@@ -161,11 +163,12 @@ export interface ErrorResult extends ResultBase {
161163
export type NonErrorResult = CodeResult|AstResult|ExplainResult|VerifyResult|RunResult;
162164
export type Result = NonErrorResult|ErrorResult;
163165

166+
export type ParsedRunResultValue = {
167+
readonly output: ReadonlyArray<OutputItem>;
168+
readonly flow: Flow | null;
169+
};
164170
export type ParsedRunResult = Omit<RunResult, 'value'> & {
165-
readonly value: {
166-
readonly output: ReadonlyArray<OutputItem>;
167-
readonly flow: Flow | null;
168-
} | null;
171+
readonly value: ParsedRunResultValue | null;
169172
};
170173
export type ParsedNonErrorResult = Exclude<Result, RunResult|ErrorResult>|ParsedRunResult;
171174
export type ParsedResult = ParsedNonErrorResult|ErrorResult;

source/WebApp/app/shared/state/results/convertFromUpdateResult.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { MaybeCached } from '../../../features/result-cache/types';
2-
import type { UpdateResult, DiagnosticError, DiagnosticWarning, ParsedNonErrorResult, AstItem, Explanation, RunResultLegacyValue, Flow } from '../../resultTypes';
2+
import type { UpdateResult, DiagnosticError, DiagnosticWarning, ParsedNonErrorResult, AstItem, Explanation, RunResultLegacyValue, ParsedRunResultValue } from '../../resultTypes';
33
import { type TargetName, TARGET_AST, TARGET_EXPLAIN, TARGET_VERIFY, TARGET_RUN, TARGET_IL } from '../../targets';
44
import { extractRangesFromIL } from './extractRangesFromIL';
55
import { parseOutput } from './parseOutput';
@@ -19,14 +19,19 @@ const collectErrorsAndWarnings = (target: TargetName, diagnostics: UpdateResult[
1919
return { success, errors, warnings } as const;
2020
};
2121

22-
const convertFromLegacyRunValue = (value: RunResultLegacyValue | null) => {
22+
const convertFromLegacyRunValue = (value: RunResultLegacyValue | null): ParsedRunResultValue | null => {
2323
if (!value)
2424
return null;
2525

26-
const { output, flow: steps } = value;
26+
const { output, flow } = value;
27+
const steps = flow.map(
28+
s => typeof s === 'number'
29+
? { type: 'step', line: s }
30+
: s
31+
);
2732
return {
2833
output,
29-
flow: { steps, areas: [] } as Flow
34+
flow: { steps, areas: [] }
3035
};
3136
};
3237

source/WebApp/app/shared/state/results/parseOutput.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { tryParseOutputJsonAsFlow } from '../../../features/execution-flow/tryParseOutputJsonAsFlow';
2-
import type { Flow, OutputItem } from '../../resultTypes';
2+
import type { Flow, OutputItem, ParsedRunResultValue } from '../../resultTypes';
33

44
type OutputJsonLineData = Exclude<OutputItem, string> | object;
55

6-
export const parseOutput = (outputString: string) => {
6+
export const parseOutput = (outputString: string): ParsedRunResultValue => {
77
const output = [] as Array<OutputItem>;
88
let flow: Flow | null = null;
99

@@ -22,20 +22,16 @@ export const parseOutput = (outputString: string) => {
2222
const json = match[1];
2323
const candidate = JSON.parse(json) as OutputJsonLineData;
2424
if ('type' in candidate && candidate.type.startsWith('inspection:')) {
25-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
26-
commitFragmentUpTo(match.index!);
27-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
28-
lastIndex += match[0]!.length;
25+
commitFragmentUpTo(match.index);
26+
lastIndex += match[0].length;
2927
output.push(candidate);
3028
continue;
3129
}
3230

3331
const flowCandidate = tryParseOutputJsonAsFlow(candidate);
3432
if (flowCandidate) {
35-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
36-
commitFragmentUpTo(match.index!);
37-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
38-
lastIndex += match[0]!.length;
33+
commitFragmentUpTo(match.index);
34+
lastIndex += match[0].length;
3935
flow = flowCandidate;
4036
continue;
4137
}

0 commit comments

Comments
 (0)