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
13 changes: 12 additions & 1 deletion client/src/types/derivation-nodes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// Type definitions used in refinement errors for expanding node simplifications

export type DerivationNode = ValDerivationNode | VarDerivationNode | BinaryDerivationNode | UnaryDerivationNode;
export type DerivationNode =
| ValDerivationNode
| VarDerivationNode
| BinaryDerivationNode
| UnaryDerivationNode
| IteDerivationNode;

export type ValDerivationNode = {
value: any;
Expand All @@ -22,3 +27,9 @@ export type UnaryDerivationNode = {
op: string;
operand: ValDerivationNode;
}

export type IteDerivationNode = {
condition: ValDerivationNode;
thenBranch: ValDerivationNode;
elseBranch: ValDerivationNode;
}
10 changes: 9 additions & 1 deletion client/src/webview/views/diagnostics/derivation-nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ function renderJsonTree(
return node.op === "-" ? `${node.op}(${operandHtml})` : `${node.op}${operandHtml}`;
}

// IteDerivationNode
if ("condition" in node && "thenBranch" in node && "elseBranch" in node) {
const conditionHtml = renderJsonTree(error, node.condition, errorId, `${path}.condition`, expandedPaths);
const thenBranchHtml = renderJsonTree(error, node.thenBranch, errorId, `${path}.thenBranch`, expandedPaths);
const elseBranchHtml = renderJsonTree(error, node.elseBranch, errorId, `${path}.elseBranch`, expandedPaths);
return `${conditionHtml} ? ${thenBranchHtml} : ${elseBranchHtml}`;
}

// fallback
return `<span class="node-value">${JSON.stringify(node)}</span>`;
}
Expand Down Expand Up @@ -114,7 +122,7 @@ export function renderDerivationNode(error: RefinementError, node: ValDerivation
return /*html*/ `
<div class="container derivation-container" data-error-id="${errorId}">
<div style="flex: 1;">
${renderJsonTree(error, node.origin || node, errorId, "root", expansions)}
${renderJsonTree(error, node, errorId, "root", expansions)}
${expansions.size === 0 ? '<span class="node-expand-indicator">&nbsp;(click to expand)</span>' : ''}
</div>
<button class="reset-btn derivation-reset-btn" data-error-id="${errorId}" ${expansions.size === 0 ? "disabled" : ""}>
Expand Down
2 changes: 1 addition & 1 deletion client/src/webview/views/diagnostics/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function renderErrors(errors: LJError[], expandedErrors: Set<number>): st
const errorContentRenderers: Partial<Record<LJError['type'], (error: LJError) => string>> = {
'refinement-error': (e: RefinementError) => /*html*/`
${e.customMessage ? renderSection('Message', e.customMessage) : ''}
${renderSection('Expected', e.expected.value)}
${renderCustomSection('Expected', renderDerivationNode(e, e.expected))}
${renderCustomSection('Found', renderDerivationNode(e, e.found))}
${e.counterexample ? renderSection('Counterexample', e.counterexample) : ''}
`,
Expand Down