Skip to content

Commit c9d86f0

Browse files
authored
Add IteDerivationNode (#68)
1 parent 0fc63fd commit c9d86f0

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

client/src/types/derivation-nodes.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// Type definitions used in refinement errors for expanding node simplifications
22

3-
export type DerivationNode = ValDerivationNode | VarDerivationNode | BinaryDerivationNode | UnaryDerivationNode;
3+
export type DerivationNode =
4+
| ValDerivationNode
5+
| VarDerivationNode
6+
| BinaryDerivationNode
7+
| UnaryDerivationNode
8+
| IteDerivationNode;
49

510
export type ValDerivationNode = {
611
value: any;
@@ -22,3 +27,9 @@ export type UnaryDerivationNode = {
2227
op: string;
2328
operand: ValDerivationNode;
2429
}
30+
31+
export type IteDerivationNode = {
32+
condition: ValDerivationNode;
33+
thenBranch: ValDerivationNode;
34+
elseBranch: ValDerivationNode;
35+
}

client/src/webview/views/diagnostics/derivation-nodes.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ function renderJsonTree(
6565
return node.op === "-" ? `${node.op}(${operandHtml})` : `${node.op}${operandHtml}`;
6666
}
6767

68+
// IteDerivationNode
69+
if ("condition" in node && "thenBranch" in node && "elseBranch" in node) {
70+
const conditionHtml = renderJsonTree(error, node.condition, errorId, `${path}.condition`, expandedPaths);
71+
const thenBranchHtml = renderJsonTree(error, node.thenBranch, errorId, `${path}.thenBranch`, expandedPaths);
72+
const elseBranchHtml = renderJsonTree(error, node.elseBranch, errorId, `${path}.elseBranch`, expandedPaths);
73+
return `${conditionHtml} ? ${thenBranchHtml} : ${elseBranchHtml}`;
74+
}
75+
6876
// fallback
6977
return `<span class="node-value">${JSON.stringify(node)}</span>`;
7078
}
@@ -114,7 +122,7 @@ export function renderDerivationNode(error: RefinementError, node: ValDerivation
114122
return /*html*/ `
115123
<div class="container derivation-container" data-error-id="${errorId}">
116124
<div style="flex: 1;">
117-
${renderJsonTree(error, node.origin || node, errorId, "root", expansions)}
125+
${renderJsonTree(error, node, errorId, "root", expansions)}
118126
${expansions.size === 0 ? '<span class="node-expand-indicator">&nbsp;(click to expand)</span>' : ''}
119127
</div>
120128
<button class="reset-btn derivation-reset-btn" data-error-id="${errorId}" ${expansions.size === 0 ? "disabled" : ""}>

client/src/webview/views/diagnostics/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function renderErrors(errors: LJError[], expandedErrors: Set<number>): st
3131
const errorContentRenderers: Partial<Record<LJError['type'], (error: LJError) => string>> = {
3232
'refinement-error': (e: RefinementError) => /*html*/`
3333
${e.customMessage ? renderSection('Message', e.customMessage) : ''}
34-
${renderSection('Expected', e.expected.value)}
34+
${renderCustomSection('Expected', renderDerivationNode(e, e.expected))}
3535
${renderCustomSection('Found', renderDerivationNode(e, e.found))}
3636
${e.counterexample ? renderSection('Counterexample', e.counterexample) : ''}
3737
`,

0 commit comments

Comments
 (0)